Add heartbeat pings for the alert check and the nightly backup #19

Merged
patrick merged 2 commits from feat/heartbeat into main 2026-10-30 15:35:17 +00:00
2 changed files with 47 additions and 0 deletions
Showing only changes of commit 55a9766418 - Show all commits

No files matched your search

+41
View File
@@ -453,6 +453,46 @@ accept the POST without a browser login or redirect. The topic and token stay
in the server config (root-owned, readable by the `kernelwatch` service group).
Agents need no changes.
## Heartbeat: is kernelwatch itself running?
Every alert above depends on `kernelwatch-alerts.timer` running on the dashboard
host. If that host is down, or the timer breaks, nothing tells you. A heartbeat
fixes this: kernelwatch pings an external monitor, and the monitor alerts when the
pings **stop**. [healthchecks.io](https://healthchecks.io) has a free tier;
Uptime Kuma's push monitors work the same way.
1. In the monitor, create two checks and copy their ping URLs:
- **alerts**: period 5 minutes, grace 20 minutes.
- **backup**: period 1 day, grace a few hours (the timer fires about 03:30 and
can be up to 30 minutes late).
2. Add the URLs to `/etc/kernelwatch/server.toml` (no restart needed for the
alert check or the backup; they read it on every run):
```toml
heartbeat_url = "https://hc-ping.com/<uuid>"
backup_heartbeat_url = "https://hc-ping.com/<other-uuid>"
```
3. Check both: `sudo kernelwatch test-heartbeat` pings each configured URL once.
What counts as a heartbeat:
- `heartbeat_url` is pinged at the end of every alert check (every five minutes)
that sent all its notifications. If ntfy delivery is failing, the ping is
skipped on purpose, so the monitor also notices a broken alert pipeline. It's
pinged even with no `ntfy_url`, since the timer is still alive.
- `backup_heartbeat_url` is pinged after each successful nightly backup, so a
timer that never ran, or a backup that failed, shows up as a missing ping.
A manual `kernelwatch backup` doesn't ping.
- A heartbeat that can't be delivered is logged (status code or error type, never
the URL) and never fails the check or the backup.
The pings leave from the dashboard host, so a dead host is exactly what stops
them. Set the monitor to notify you some way that doesn't depend on that host:
email, the monitor's own app, or ntfy.sh. Not a ntfy server running behind it.
The URLs are secrets (whoever has one can fake a heartbeat), so keep
`server.toml` readable by root and the `kernelwatch` group only.
## Server admin commands
```
@@ -468,6 +508,7 @@ sudo kernelwatch scheduled-backup dated copy in backup_dir, then prune old on
sudo kernelwatch notify-backup-failure send the failed-backup notification now (also runs on failure)
sudo kernelwatch check-alerts check for stale, recovered, reboot and update alerts now
sudo kernelwatch test-alert send a test notification to the configured ntfy topic
sudo kernelwatch test-heartbeat ping the configured heartbeat URLs once and report
```
## Backups
+6
View File
@@ -50,3 +50,9 @@ ntfy_timeout_seconds = 10.0
# Reaching a worse state (updates -> reboot) notifies again after another period.
# 0 disables. Needs ntfy_url.
status_alert_after_hours = 24.0
# Dead-man's switch: an external monitor (e.g. healthchecks.io) that alerts when the
# pings STOP, which is how you learn kernelwatch itself isn't running. Treat these
# URLs like passwords. Empty disables.
heartbeat_url = "" # pinged every five minutes by the alert check
backup_heartbeat_url = "" # pinged after each successful nightly backup