Harden Pushover error notifications on abort
This commit is contained in:
@@ -18,6 +18,7 @@ set -Eeuo pipefail
|
||||
WG_IF="wg0"
|
||||
VPN_TEST_IP="10.202.101.10"
|
||||
WG_WAS_STARTED_BY_SCRIPT=0
|
||||
PUSHOVER_FAILURE_SENT=0
|
||||
|
||||
LOCK_FILE="/var/lock/agathe_backup.lock"
|
||||
|
||||
@@ -89,16 +90,27 @@ send_pushover() {
|
||||
local priority="${2:-0}"
|
||||
|
||||
if command -v curl >/dev/null 2>&1; then
|
||||
curl -s \
|
||||
local rc
|
||||
set +e
|
||||
curl -fsS --max-time 20 --retry 2 --retry-delay 2 \
|
||||
--form-string "token=${PUSHOVER_API_TOKEN}" \
|
||||
--form-string "user=${PUSHOVER_USER_TOKEN}" \
|
||||
--form-string "title=${PUSHOVER_TITLE}" \
|
||||
--form-string "message=${message}" \
|
||||
--form-string "priority=${priority}" \
|
||||
https://api.pushover.net/1/messages.json >/dev/null || true
|
||||
https://api.pushover.net/1/messages.json >/dev/null
|
||||
rc=$?
|
||||
set -e
|
||||
if [[ "$rc" -ne 0 ]]; then
|
||||
log "WARNUNG: Pushover konnte nicht gesendet werden (curl Exit-Code: $rc)."
|
||||
return 1
|
||||
fi
|
||||
else
|
||||
log "WARNUNG: curl fehlt, Pushover konnte nicht gesendet werden."
|
||||
return 1
|
||||
fi
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
need_root() {
|
||||
@@ -148,13 +160,22 @@ on_error() {
|
||||
local exit_code=$?
|
||||
local line_no="${1:-unknown}"
|
||||
log "FEHLER in Zeile ${line_no}, Exit-Code ${exit_code}"
|
||||
send_pushover "Backup FEHLER auf $(hostname): Zeile ${line_no}, Exit-Code ${exit_code}" 1
|
||||
if send_pushover "Backup FEHLER auf $(hostname): Zeile ${line_no}, Exit-Code ${exit_code}" 1; then
|
||||
PUSHOVER_FAILURE_SENT=1
|
||||
fi
|
||||
trap - EXIT
|
||||
cleanup
|
||||
exit "$exit_code"
|
||||
}
|
||||
|
||||
on_exit() {
|
||||
local exit_code=$?
|
||||
if [[ "$exit_code" -ne 0 && "$PUSHOVER_FAILURE_SENT" -eq 0 ]]; then
|
||||
log "WARNUNG: Abbruch ohne ERR-Notification erkannt (Exit-Code ${exit_code}), sende Fallback-Pushover."
|
||||
if send_pushover "Backup FEHLER auf $(hostname): Exit-Code ${exit_code} (EXIT trap)." 1; then
|
||||
PUSHOVER_FAILURE_SENT=1
|
||||
fi
|
||||
fi
|
||||
cleanup
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user