46 lines
1.8 KiB
Bash
46 lines
1.8 KiB
Bash
#!/bin/bash
|
|
# /usr/local/bin/nut-notify.sh
|
|
# Emergency power notification script for Network UPS Tools on Snarfnet
|
|
set -euo pipefail
|
|
|
|
EVENT_TYPE="${1:-$NOTIFYTYPE}"
|
|
UPS_NAME="${UPSNAME:-snarf-ups}"
|
|
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
|
|
|
|
# Internal Gotify VIP endpoint (bypasses Authentik Forward Auth and NPM)
|
|
GOTIFY_INTERNAL_URL="http://140.44.4.70:8090/message"
|
|
GOTIFY_APP_TOKEN="${GOTIFY_APP_TOKEN:-A4uN4fEmErGeNcYtOkEn}"
|
|
|
|
send_gotify() {
|
|
local title="$1"
|
|
local message="$2"
|
|
local priority="$3"
|
|
|
|
curl -s -m 5 -X POST "${GOTIFY_INTERNAL_URL}?token=${GOTIFY_APP_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"title\": \"${title}\", \"message\": \"${message}\", \"priority\": ${priority}}" >/dev/null 2>&1 || true
|
|
}
|
|
|
|
case "$EVENT_TYPE" in
|
|
ONBATT)
|
|
send_gotify "⚡ Grid Power Lost" "[$TIMESTAMP] Homelab is running on UPS battery (${UPS_NAME}). Staged shutdown countdown started." 8
|
|
logger -t nut-notify "Grid power failure detected - running on UPS battery."
|
|
;;
|
|
ONLINE)
|
|
send_gotify "✅ Grid Power Restored" "[$TIMESTAMP] Utility AC power restored to ${UPS_NAME}. Battery recharging." 5
|
|
logger -t nut-notify "AC utility power restored."
|
|
;;
|
|
LOWBATT)
|
|
send_gotify "🚨 UPS Battery Critical" "[$TIMESTAMP] Battery level critical on ${UPS_NAME}! Final Tier 4-6 shutdown initiated." 10
|
|
logger -t nut-notify "CRITICAL: UPS battery low. Enforcing emergency shutdown."
|
|
;;
|
|
FSD)
|
|
send_gotify "🛑 Forced Shutdown Engaged" "[$TIMESTAMP] NUT Master has commanded immediate power cutoff across all clusters." 10
|
|
logger -t nut-notify "FSD signal received. Halting systems."
|
|
;;
|
|
*)
|
|
logger -t nut-notify "Unhandled UPS event: ${EVENT_TYPE}"
|
|
;;
|
|
esac
|
|
|