Viewing File: /home/ubuntu/scripts/site-monitor.sh
#!/bin/bash
# Sites to monitor
SITES=("https://herald.exchange/" "https://eficyent.com/", "https://theridgecorp.com/", "https://efimarkets.com/", "https://app.aexpressremit.com/")
# Mailgun settings
MAILGUN_API_KEY="c21c401a04c86f159d6382e7821bff06-2b77fbb2-fb1ab683"
MAILGUN_DOMAIN="staging.socialdraco.com"
MAILGUN_FROM="Site Monitor <monitor@$MAILGUN_DOMAIN>"
MAILGUN_TO="vithya@codegama.com"
# Telegram settings
TELEGRAM_BOT_TOKEN="your-telegram-bot-token"
TELEGRAM_CHAT_ID="your-chat-id"
# Slack settings
SLACK_WEBHOOK_URL="https://hooks.slack.com/services/your/slack/webhook"
# Status log folder
STATUS_DIR="/tmp/site_monitor_status"
mkdir -p "$STATUS_DIR"
send_email() {
local subject="$1"
local body="$2"
curl -s --user "api:$MAILGUN_API_KEY" \
https://api.mailgun.net/v3/$MAILGUN_DOMAIN/messages \
-F from="$MAILGUN_FROM" \
-F to="$MAILGUN_TO" \
-F subject="$subject" \
-F text="$body"
}
# send_telegram() {
# local message="$1"
# curl -s -X POST "https://api.telegram.org/bot$TELEGRAM_BOT_TOKEN/sendMessage" \
# -d chat_id="$TELEGRAM_CHAT_ID" \
# -d text="$message"
# }
# send_slack() {
# local message="$1"
# curl -s -X POST -H 'Content-type: application/json' \
# --data "{\"text\":\"$message\"}" \
# "$SLACK_WEBHOOK_URL"
# }
# Loop through sites
for URL in "${SITES[@]}"; do
DOMAIN=$(echo "$URL" | awk -F[/:] '{print $4}')
STATUS_FILE="$STATUS_DIR/${DOMAIN}.status"
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" "$URL")
PREVIOUS_STATUS=$(cat "$STATUS_FILE" 2>/dev/null)
echo "$RESPONSE" > "$STATUS_FILE"
if [ "$RESPONSE" -ne 200 ]; then
if [ "$PREVIOUS_STATUS" != "$RESPONSE" ]; then
ALERT_MSG="❌ $DOMAIN is DOWN! ($RESPONSE)"
echo "[`date`] $ALERT_MSG"
send_email "$DOMAIN is DOWN" "$ALERT_MSG"
#send_telegram "$ALERT_MSG"
#send_slack "$ALERT_MSG"
fi
else
if [ "$PREVIOUS_STATUS" != "$RESPONSE" ]; then
ALERT_MSG="✅ $DOMAIN is back UP. ($RESPONSE)"
echo "[`date`] $ALERT_MSG"
send_email "$DOMAIN is UP" "$ALERT_MSG"
#send_telegram "$ALERT_MSG"
#send_slack "$ALERT_MSG"
fi
fi
done
Back to Directory
File Manager