Add heartbeat pings for the alert check and the nightly backup

heartbeat_url is pinged after every alert check that sent its notifications
without failures, and backup_heartbeat_url after every successful nightly
backup, so an external monitor (healthchecks.io, Uptime Kuma) notices when the
alert timer or the backup stops running. A failing heartbeat is logged without
the URL and never fails the work it reports on. kernelwatch test-heartbeat
pings each configured URL once.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
patrickandClaude Sonnet 5.5 committed 2026-10-30 11:31:32 -04:00
1 parent e3013921d1
commit 60b8c6bff7
4 files changed
+257 -1

No files matched your search

+18
View File
@@ -49,6 +49,12 @@ class Config:
ntfy_url: str = ""
ntfy_token: str = ""
ntfy_timeout_seconds: float = 10.0
# Dead-man's-switch URLs (e.g. healthchecks.io): pinged after every successful
# alert check (every five minutes) and every successful nightly backup, so a
# monitor outside this host notices when either stops. Empty disables.
heartbeat_url: str = ""
backup_heartbeat_url: str = ""
# Notify when a host has needed a reboot or updates for this long; 0 disables.
status_alert_after_hours: float = 24.0
@@ -90,6 +96,18 @@ def load(path: str | None = None) -> Config:
raise SystemExit(f"{path}: backup_dir must be an absolute path")
if not math.isfinite(cfg.status_alert_after_hours) or cfg.status_alert_after_hours < 0:
raise SystemExit(f"{path}: status_alert_after_hours must be zero or positive and finite")
for key in ("heartbeat_url", "backup_heartbeat_url"):
value = getattr(cfg, key)
if value:
try:
url = urlsplit(value)
valid = (url.scheme in ("http", "https") and url.hostname and url.port != 0
and not url.fragment
and not any(c.isspace() or ord(c) < 32 or ord(c) == 127 for c in value))
except ValueError:
valid = False
if not valid:
raise SystemExit(f"{path}: {key} must be an HTTP(S) URL without spaces or a fragment")
if any(ord(c) < 32 or ord(c) == 127 for c in cfg.ntfy_url + cfg.ntfy_token):
raise SystemExit(f"{path}: ntfy settings must not contain control characters")
if cfg.ntfy_url: