feat(power): complete Phase 7 Power Resilience & UPS Automation deployment and verification

This commit is contained in:
2026-11-02 21:58:49 -05:00
parent 7ca3d5acb8
commit d3e2e1f291
8 changed files with 216 additions and 40 deletions

View File

@@ -4,7 +4,7 @@
set -euo pipefail
EVENT_TYPE="${1:-$NOTIFYTYPE}"
UPS_NAME="${UPSNAME:-snarf-ups}"
UPS_NAME="${UPSNAME:-server-closet}"
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
# Internal Gotify VIP endpoint (bypasses Authentik Forward Auth and NPM)
@@ -20,11 +20,11 @@ send_gotify() {
local priority="$3"
local color="${4:-16711680}"
# Primary: Send to Gotify (which pushes to mobile devices + forwards to Discord ups-power webhook)
# Primary: Send to Gotify (which pushes to mobile devices + forwards to Discord #ups-power)
if ! curl -sf -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; then
# Fallback: If Gotify/Shipyard is already powered down (Tier 4+), send directly to Discord via UDM Pro (Tier 6)
# Fallback: If Gotify/Shipyard is already powered down (Tier 4+), send directly to Discord via UDM Pro
curl -sf -m 5 -X POST "${DISCORD_UPS_WEBHOOK}" \
-H "Content-Type: application/json" \
-d "{\"username\": \"SnarfNet NUT Master (Direct Fallback)\", \"embeds\": [{\"title\": \"${title}\", \"description\": \"${message}\", \"color\": ${color}}]}" >/dev/null 2>&1 || true
@@ -41,15 +41,26 @@ case "$EVENT_TYPE" in
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 15158332
send_gotify "🚨 UPS Battery Critical" "[$TIMESTAMP] Battery level critical on ${UPS_NAME}! Final Tier 3-6 shutdown initiated." 10 15158332
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 10038562
logger -t nut-notify "FSD signal received. Halting systems."
;;
COMMOK)
send_gotify "🔌 UPS Communication Restored" "[$TIMESTAMP] Communication with ${UPS_NAME} established." 4 3066993
logger -t nut-notify "UPS communication restored."
;;
COMMBAD)
send_gotify "⚠️ UPS Communication Lost" "[$TIMESTAMP] Lost communication with ${UPS_NAME}." 8 16753920
logger -t nut-notify "UPS communication lost."
;;
SHUTDOWN)
send_gotify "🛑 Homelab Emergency Powerdown" "[$TIMESTAMP] System shutdown initiated by NUT." 10 10038562
logger -t nut-notify "System shutdown initiated."
;;
*)
logger -t nut-notify "Unhandled UPS event: ${EVENT_TYPE}"
;;
esac