added notification support, and added to a few scripts . need to update the rest

This commit is contained in:
2026-04-08 21:42:56 -04:00
parent ae0054fd85
commit d12e034ef1
4 changed files with 260 additions and 3 deletions
+52 -1
View File
@@ -2,7 +2,7 @@
# -----------------------------------------------------------------------------------------------
# ----------------- UNRAID OPS COMMON LIBRARY (STABLE FRAMEWORK v1) ----------------------------
# -----------------------------------------------------------------------------------------------
# Version: 2.2
# Version: 2.3
# -----------------------------------------------------------------------------------------------
# Changelog:
# v1.0 — Initial stable framework
@@ -34,6 +34,9 @@
# v2.1 — ICON_ZFS and ICON_MEM added for ZFS and memory diagnostics
# Diagnostics icon group added to icon block
# v2.2 — ICON_WATCHDOG added for Docker watchdog monitoring operations
# v2.3 — ICON_NOTIFY added for notification operations
# notify() added — shared notification function supporting unRAID native and Discord
# NOTIFY_UNRAID and DISCORD_WEBHOOK configured in Master.conf
# -----------------------------------------------------------------------------------------------
# -----------------------------------------------------------------------------------------------
@@ -82,6 +85,9 @@ ICON_ZFS="📊" # ZFS ARC statistics
ICON_MEM="🧠" # memory status
ICON_WATCHDOG="🐾" # docker watchdog monitoring operations
# Notifications
ICON_NOTIFY="🔔" # notification operations
# Output
ICON_INFO="️"
ICON_WARN="⚠️"
@@ -102,6 +108,51 @@ log() {
[[ "${ENABLE_LOGGING:-false}" == true ]] && echo "[LOG] $*"
}
# -----------------------------------------------------------------------------------------------
# NOTIFICATION
# Sends a notification via unRAID native system and/or Discord webhook.
# Both channels are optional and independently controlled via Master.conf.
# unRAID native: requires NOTIFY_UNRAID=true and the dynamix notify script to be present.
# Discord: requires DISCORD_WEBHOOK to be set to a valid webhook URL.
# Severity levels: normal, warning, alert — maps to unRAID notification severity.
# Usage: notify "message" "subject" "severity"
# notify "Rsync failed: Movies" "Rsync Alert" "alert"
# notify "Daily sync complete" "Daily Sync" "normal"
# -----------------------------------------------------------------------------------------------
notify() {
local message="$1"
local subject="${2:-unRAID Notification}"
local severity="${3:-normal}"
log "$ICON_NOTIFY Sending notification: $subject$message"
# unRAID native notification
if [[ "${NOTIFY_UNRAID:-false}" == true ]]; then
local notify_script="/usr/local/emhttp/plugins/dynamix/scripts/notify"
if [[ -x "$notify_script" ]]; then
"$notify_script" -s "$subject" -d "$message" -i "$severity" 2>/dev/null
log "$ICON_NOTIFY unRAID notification sent"
else
log "$ICON_NOTIFY unRAID notify script not found — skipping"
fi
fi
# Discord webhook notification
if [[ -n "${DISCORD_WEBHOOK:-}" ]]; then
local hostname
hostname=$(hostname)
local payload
payload=$(printf '{"content": "%s — **%s**\\n%s"}' \
"$ICON_NOTIFY" "$subject" "$message")
if curl -s -H "Content-Type: application/json" \
-d "$payload" "$DISCORD_WEBHOOK" >/dev/null 2>&1; then
log "$ICON_NOTIFY Discord notification sent"
else
warn "Discord notification failed — check DISCORD_WEBHOOK in Master.conf"
fi
fi
}
# -----------------------------------------------------------------------------------------------
# DURATION FORMATTER
# Converts raw seconds into a human readable string — e.g. 10m53s or 47s