40 lines
1.1 KiB
Bash
40 lines
1.1 KiB
Bash
#!/usr/bin/env bash
|
|
# UPTIME-PROBE-SENTINEL-9c2f — phase 56 fixture marker: this token exists
|
|
# nowhere else, so the extension_kb rows are unambiguous in the shared DB.
|
|
#
|
|
# uptime.sh — homelab service probe: polls the core services and posts a
|
|
# ntfy alert on the first failure. A novel (.sh) file on purpose — it
|
|
# only imports when BOR_IMPORT_EXTENSIONS names the sh extension.
|
|
|
|
set -euo pipefail
|
|
|
|
ALERT_TOPIC="homelab-alerts"
|
|
NTFY_URL="https://ntfy.reeseapps.com"
|
|
CHECKS=(
|
|
"k3s|https://10.0.1.10:6443/healthz"
|
|
"gitlab|https://gitlab.reeseapps.com/-/health_check"
|
|
"ntfy|https://ntfy.reeseapps.com/health"
|
|
)
|
|
|
|
probe() {
|
|
local name="$1" url="$2"
|
|
curl -s -o /dev/null -w "%{http_code}" --max-time 10 "$url"
|
|
}
|
|
|
|
main() {
|
|
local line name code
|
|
for line in "${CHECKS[@]}"; do
|
|
name="${line%%|*}"
|
|
code="$(probe "$name" "${line#*|}")"
|
|
if [[ "$code" != "200" ]]; then
|
|
echo "uptime: $name answered $code (expected 200)" >&2
|
|
curl -s -X POST "$NTFY_URL/$ALERT_TOPIC" \
|
|
-H "Title: homelab check failed" \
|
|
-d "$name is down (HTTP $code)"
|
|
fi
|
|
done
|
|
echo "uptime: round complete"
|
|
}
|
|
|
|
main "$@"
|