From 52d4064195ae46a510c0dc5a55ba232104872f1b Mon Sep 17 00:00:00 2001 From: C0M-M4ND0 Date: Mon, 7 Oct 2024 17:12:00 +0100 Subject: [PATCH 1/2] Refactor send_discord_notification to include more detailed information in the notification message --- app/monitor.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/monitor.py b/app/monitor.py index a31efca..2b865de 100644 --- a/app/monitor.py +++ b/app/monitor.py @@ -19,7 +19,14 @@ def check_health(application): try: response = requests.get(application['url']) if response.status_code != 200: - send_discord_notification(application.get("webhook_url", DEFAULT_WEBHOOK_URL), f"🚨 {application['name']} is unhealthy: Status code {response.status_code}") + send_discord_notification( + application.get("webhook_url", DEFAULT_WEBHOOK_URL), + f"🚨 **{application['name']}** is unhealthy:\n" + f"**Status Code:** {response.status_code}\n" + f"**URL:** {application['url']}\n" + f"**Response Time:** {response.elapsed.total_seconds()} seconds\n" + f"**Response Content:** {response.text[:300]}...\n" + ) except requests.exceptions.RequestException as e: send_discord_notification(application.get("webhook_url", DEFAULT_WEBHOOK_URL), f"🚨 {application['name']} health check failed: {str(e)}") From 41ae4555e24b59ec556760986985dab8ac262011 Mon Sep 17 00:00:00 2001 From: C0M-M4ND0 Date: Mon, 7 Oct 2024 17:16:12 +0100 Subject: [PATCH 2/2] Refactor send_discord_notification to include more detailed error information --- app/monitor.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/monitor.py b/app/monitor.py index 2b865de..9916081 100644 --- a/app/monitor.py +++ b/app/monitor.py @@ -1,3 +1,4 @@ +import logging import requests import time from app.config import APPLICATIONS, DEFAULT_WEBHOOK_URL, CHECK_INTERVAL @@ -9,11 +10,9 @@ def send_discord_notification(webhook_url, message): try: response = requests.post(webhook_url, json=data) if response.status_code != 204: - print(f"Failed to send notification: {response.status_code}") + logging.error(f"Failed to send Discord notification: {response.text}") except Exception as e: - print(f"Error sending Discord notification: {str(e)}") logging.error(f"Failed to send Discord notification: {str(e)}", exc_info=True) - print(f"Error sending notification: {e}") def check_health(application): try: