diff --git a/app/monitor.py b/app/monitor.py index a31efca..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,17 +10,22 @@ 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: 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)}")