Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions app/monitor.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import requests
import time
from app.config import APPLICATIONS, DEFAULT_WEBHOOK_URL, CHECK_INTERVAL
Expand All @@ -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)}")

Expand Down