#!/bin/bash # Monitor dashboard health and send alerts # Run via cron: */5 * * * * /volume1/repos/nas-tools/scripts/monitor-dashboard-health.sh PROD_URL="http://nas.jimmygan.com:4000" DEV_URL="http://nas.jimmygan.com:4001" ALERT_FILE="/tmp/dashboard-health-alert-sent" LOG_DIR="/volume1/repos/nas-tools/logs" # Create log directory if it doesn't exist mkdir -p "$LOG_DIR" check_endpoint() { local url=$1 local name=$2 response=$(curl -s -o /dev/null -w "%{http_code}" "$url/api/health" --max-time 5) if [ "$response" != "200" ]; then echo "$(date): ❌ $name health check failed (HTTP $response)" return 1 fi echo "$(date): ✅ $name health check passed" return 0 } # Check production if ! check_endpoint "$PROD_URL" "Production"; then if [ ! -f "$ALERT_FILE" ]; then # Send alert only once until issue is resolved /volume1/repos/nas-tools/notify.sh "⚠️ Dashboard Production Health Check Failed - HTTP endpoint not responding" touch "$ALERT_FILE" fi exit 1 fi # Check dev (non-critical, just log) if ! check_endpoint "$DEV_URL" "Dev"; then echo "$(date): ⚠️ Dev dashboard health check failed (non-critical)" fi # Clear alert file if checks pass if [ -f "$ALERT_FILE" ]; then rm -f "$ALERT_FILE" /volume1/repos/nas-tools/notify.sh "✅ Dashboard Production Health Restored" fi echo "$(date): ✅ All health checks passed"