summaryrefslogtreecommitdiff
path: root/arecordalertfailzero.sh
diff options
context:
space:
mode:
authordoc <doc@filenotfound.org>2025-06-30 20:11:52 +0000
committerdoc <doc@filenotfound.org>2025-06-30 20:11:52 +0000
commit41e897f4945aaf8fbcdf0b12ac2f08c5e6ae0458 (patch)
treedb7c3520fd91abc3cf56b1a52095d23f3a80d059 /arecordalertfailzero.sh
commit of legacy codeHEADmaster
Diffstat (limited to 'arecordalertfailzero.sh')
-rwxr-xr-xarecordalertfailzero.sh88
1 files changed, 88 insertions, 0 deletions
diff --git a/arecordalertfailzero.sh b/arecordalertfailzero.sh
new file mode 100755
index 0000000..fadeba8
--- /dev/null
+++ b/arecordalertfailzero.sh
@@ -0,0 +1,88 @@
+#!/bin/bash
+
+# FailZero Early Warning System (FZ EWS)
+# Monitor critical hosts and alert on Telegram on failure
+
+# === INSERT YOUR TELEGRAM CREDENTIALS BELOW ===
+BOT_TOKEN="8031184325:AAEGj3gzwYF8HaLjWHVe0gOG5bzo63tcRbU"
+CHAT_ID="1559582356"
+
+# === INSERT YOUR CRITICAL HOSTNAMES BELOW ===
+CRITICAL_HOSTS=(
+ "da.genesishostingtechnologies.com"
+ "zcluster.technodrome1.sshjunkie.com"
+ "zcluster.technodrome2.sshjunkie.com"
+ "krang.core.sshjunkie.com"
+ "tt.themediahub.org"
+ "toot.themediahub.org"
+ "chatwithus.live"
+ "genesishostingtechnologies.com"
+ "portal.genesishostingtechnologies.com"
+ "brandoncharles.us"
+ # Add more hostnames here, one per line inside quotes
+)
+
+LOG_FILE="/home/doc/fz_ews.log"
+COOLDOWN_FILE="/home/doc/fz_ews_cooldown"
+
+# Cooldown period in seconds to prevent alert spam (e.g., 3600 = 1 hour)
+ALERT_COOLDOWN=3600
+
+send_telegram_alert() {
+ local message="$1"
+ curl -s -X POST "https://api.telegram.org/bot$BOT_TOKEN/sendMessage" \
+ -d chat_id="$CHAT_ID" \
+ -d text="🚨 FailZero EWS Alert: $message" > /dev/null
+}
+
+log() {
+ echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >> "$LOG_FILE"
+}
+
+check_cooldown() {
+ local host="$1"
+ local now=$(date +%s)
+ local last_alert=$(grep "^$host " "$COOLDOWN_FILE" 2>/dev/null | awk '{print $2}')
+ if [[ -z "$last_alert" ]]; then
+ return 0
+ fi
+ local elapsed=$((now - last_alert))
+ if (( elapsed > ALERT_COOLDOWN )); then
+ return 0
+ else
+ return 1
+ fi
+}
+
+update_cooldown() {
+ local host="$1"
+ local now=$(date +%s)
+ # Remove existing entry for host if any
+ grep -v "^$host " "$COOLDOWN_FILE" 2>/dev/null > "${COOLDOWN_FILE}.tmp"
+ mv "${COOLDOWN_FILE}.tmp" "$COOLDOWN_FILE"
+ # Append new timestamp
+ echo "$host $now" >> "$COOLDOWN_FILE"
+}
+
+check_host() {
+ local host="$1"
+ if ping -c 2 -W 3 "$host" > /dev/null 2>&1; then
+ log "$host is UP"
+ else
+ log "$host is DOWN"
+ if check_cooldown "$host"; then
+ send_telegram_alert "$host is DOWN or unreachable!"
+ update_cooldown "$host"
+ else
+ log "Cooldown active for $host; alert suppressed"
+ fi
+ fi
+}
+
+main() {
+ for host in "${CRITICAL_HOSTS[@]}"; do
+ check_host "$host"
+ done
+}
+
+main