Add ntfy alerts for stale hosts and reporting recovery
CI / tests (Python 3.10) (pull_request) Successful in 19s
CI / tests (Python 3.11) (pull_request) Successful in 17s
CI / tests (Python 3.12) (pull_request) Successful in 17s
CI / tests (Python 3.13) (pull_request) Successful in 18s
CI / lint (pull_request) Successful in 3s

This commit is contained in:
patrick committed 2026-10-24 15:15:48 -04:00
1 parent bd0db302b0
commit 47f93968e9
11 files changed
+631 -4

No files matched your search

+52 -1
View File
@@ -369,6 +369,55 @@ Host zeus
ProxyJump eurus
```
## Stale-host and recovery alerts (ntfy)
The server can notify an [ntfy](https://ntfy.sh/) topic when a host stops
reporting and when its reports resume. Agents report hourly with up to 15 minutes
of jitter. Alerts use the same `stale_after_hours` as the dashboard (3 hours by
default), leaving room for ordinary delays. Newly registered hosts get that same
grace period to send their first report.
Re-run `sudo ./server/install.sh` to install the alert timer when upgrading.
The installer preserves your existing config, so add these settings to
`/etc/kernelwatch/server.toml`:
```toml
ntfy_url = "https://ntfy.example.com/kernelwatch"
ntfy_token = "" # optional access token with publish permission for this topic
ntfy_timeout_seconds = 10.0
```
Subscribe to that topic in your ntfy app, then check delivery:
```sh
sudo kernelwatch test-alert
systemctl list-timers kernelwatch-alerts.timer
```
`kernelwatch-alerts.timer` runs a separate, unprivileged check every five minutes,
even when no hosts report and nobody opens the dashboard. Notifications normally
arrive within about five minutes of crossing the stale threshold or receiving a
fresh report. Run `sudo kernelwatch check-alerts` to check immediately, or inspect
`journalctl -u kernelwatch-alerts.service` for delivery failures.
- Each host gets one stale notification and one reporting-recovery notification
per detected outage. Successful sends are saved in SQLite, so routine checks
and server restarts don't repeat them. Recovery confirms reporting has resumed;
the host may still need updates or a reboot.
- Failed sends are retried on the next check, and a failure for one host doesn't
stop checks for the others. A recovery is sent only after a stale notification
was successfully delivered. A timeout or crash after ntfy accepted a message
can cause a duplicate on retry.
- An empty `ntfy_url` disables notifications. The timer reads its configuration
on every run; changing ntfy settings needs no restart. If you change
`stale_after_hours`, restart `kernelwatch.service` too so the dashboard uses the
new threshold.
Use the topic's direct publish URL, with token authentication if needed; it must
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.
## Server admin commands
```
@@ -379,6 +428,8 @@ sudo kernelwatch list-hosts hosts and when they last reported
sudo kernelwatch set-password USER create a user / change password (logs out their sessions)
sudo kernelwatch remove-user USER
sudo kernelwatch list-users
sudo kernelwatch check-alerts check for stale hosts and reporting recovery now
sudo kernelwatch test-alert send a test notification to the configured ntfy topic
```
## Security notes
@@ -432,7 +483,7 @@ export KERNELWATCH_CONFIG=/tmp/kw.toml
## Ideas for later
- Alerts on status changes (email/ntfy/webhook)
- Notifications for pending updates/reboots, and additional delivery channels
- Ubuntu Livepatch / Pro status, so live-patched hosts aren't flagged for reboot
- A JSON endpoint for scripting
- Grouping or tagging hosts (prod/staging, location)