94 lines
4.3 KiB
Bash
Executable File
94 lines
4.3 KiB
Bash
Executable File
#!/bin/bash
|
|
# ==============================================================================================
|
|
# ================================== Uptime Report =============================================
|
|
# ==============================================================================================
|
|
#
|
|
# PURPOSE
|
|
# ─────────────────────────────────────────────────────────────────────────────
|
|
# The weekly read of what Tools/uptime_probe.sh has been recording every minute: anything down
|
|
# right now, and anything that was not perfect over the last seven days. Runs in the Sunday
|
|
# Morning Coffee Report.
|
|
#
|
|
# Silent on a clean week. A report that always says something is a report nobody reads, so this
|
|
# prints nothing and notifies nothing when every domain was 100%.
|
|
#
|
|
# ==============================================================================================
|
|
# OPERATIONAL MODEL
|
|
# ==============================================================================================
|
|
#
|
|
# uptime_probe.php --report exits 1 when it has something to say and 0 when it does not, so the
|
|
# decision to notify is the exit code rather than this script parsing the text it just printed.
|
|
#
|
|
# ==============================================================================================
|
|
# DESIGN PRINCIPLES
|
|
# ==============================================================================================
|
|
#
|
|
# Silence is the normal output.
|
|
# A report that always says something is a report nobody reads. A perfect week prints nothing
|
|
# and notifies nothing, so anything that does appear in the Sunday report is worth the glance.
|
|
#
|
|
# The exit code is the decision, not the text.
|
|
# uptime_probe.php --report exits 1 when it has something to say and 0 when it does not. This
|
|
# script never parses the output it just printed to work out whether to notify — a report whose
|
|
# wording changed would otherwise silently stop notifying.
|
|
#
|
|
# It reads; it never probes.
|
|
# The measurements are already taken, once a minute, by Tools/uptime_probe.sh. Re-probing at
|
|
# report time would describe Sunday morning rather than the week being reported on.
|
|
#
|
|
# ==============================================================================================
|
|
# OPERATIONAL SAFEGUARDS
|
|
# ==============================================================================================
|
|
#
|
|
# Read-only. Reads the stored history and prints; records nothing, and cannot alter the data it
|
|
# is reporting on.
|
|
#
|
|
# UPTIME_PROBE_ENABLED gates the whole run — with the probe off there is no history worth
|
|
# reporting, and this says nothing rather than reporting an empty week as a perfect one.
|
|
#
|
|
# ==============================================================================================
|
|
# RUNTIME MODES
|
|
# ==============================================================================================
|
|
#
|
|
# uptime_report.sh the weekly read. Silent when every domain was 100%.
|
|
#
|
|
# Called from COFFEE_REPORT_SCRIPTS; takes no arguments and has no other mode. For live figures
|
|
# or a per-domain table, use Tools/uptime_probe.sh --status.
|
|
#
|
|
# ==============================================================================================
|
|
# CONFIGURATION
|
|
# ==============================================================================================
|
|
#
|
|
# UPTIME_PROBE_ENABLED nothing here runs when the probe is switched off
|
|
#
|
|
# ==============================================================================================
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
source "$SCRIPT_DIR/../load_config.sh"
|
|
|
|
acquire_lock
|
|
detect_hosts
|
|
|
|
if [[ "${UPTIME_PROBE_ENABLED:-true}" == "false" ]]; then
|
|
log "$ICON_GEAR Uptime probe disabled — nothing to report"
|
|
exit 0
|
|
fi
|
|
|
|
REPORT="$(php "$SCRIPT_DIR/../Plugin/unraid/Tools/uptime_probe.php" --report 2>/dev/null)"
|
|
RC=$?
|
|
|
|
if [[ $RC -eq 0 || -z "$REPORT" ]]; then
|
|
echo "$ICON_DONE All monitored domains at 100% this week ✅"
|
|
exit 0
|
|
fi
|
|
|
|
echo "$REPORT"
|
|
|
|
DOWN_COUNT=$(grep -c "DOWN" <<< "$REPORT" || true)
|
|
if [[ "$DOWN_COUNT" -gt 0 ]]; then
|
|
notify "$DOWN_COUNT domain(s) currently unreachable on $(hostname)" "Uptime" "warning"
|
|
else
|
|
notify "Some domains had downtime this week on $(hostname)" "Uptime" "normal"
|
|
fi
|
|
exit 0
|