From 8bdc5dd281d6f8f95fbf2dcaa76663954f332c93 Mon Sep 17 00:00:00 2001 From: Pat Heard Date: Wed, 24 Jan 2024 20:42:45 +0000 Subject: [PATCH] fix: opsgenie integration healthcheck Update to an API entpoint that the bot's Team API key can access. Move the API call into the try block so that a request failure is properly identified as a failed healthcheck. --- app/integrations/opsgenie.py | 10 +++++----- app/jobs/scheduled_tasks.py | 10 +++++++--- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/integrations/opsgenie.py b/app/integrations/opsgenie.py index b11b34ca..2d5aaf66 100644 --- a/app/integrations/opsgenie.py +++ b/app/integrations/opsgenie.py @@ -44,14 +44,14 @@ def create_alert(description): def healthcheck(): """Check if the bot can interact with the Opsgenie API.""" healthy = False - content = api_get_request( - "https://api.opsgenie.com/v2/account", - {"name": "GenieKey", "token": OPSGENIE_KEY}, - ) try: + content = api_get_request( + "https://api.opsgenie.com/v1/services", + {"name": "GenieKey", "token": OPSGENIE_KEY}, + ) result = json.loads(content) - logging.info(f"OpsGenie healthcheck result: {result}") healthy = "data" in result + logging.info(f"OpsGenie healthcheck result: {result}") except Exception as error: logging.error(f"OpsGenie healthcheck failed: {error}") return healthy diff --git a/app/jobs/scheduled_tasks.py b/app/jobs/scheduled_tasks.py index 94891e65..433f4fe0 100644 --- a/app/jobs/scheduled_tasks.py +++ b/app/jobs/scheduled_tasks.py @@ -28,10 +28,14 @@ def scheduler_heartbeat(): def integration_healthchecks(): logging.info("Running integration healthchecks ...") - healthchecks = [opsgenie.healthcheck] - for healthcheck in healthchecks: + healthchecks = { + "opsgenie": opsgenie.healthcheck, + } + for key, healthcheck in healthchecks.items(): if not healthcheck(): - logging.error(f"Integration {healthcheck.__name__} is unhealthy 💀") + logging.error(f"Integration {key} is unhealthy 💀") + else: + logging.info(f"Integration {key} is healthy 🌈") def run_continuously(interval=1):