Alert when Livepatch is broken or has stopped reporting #22

Merged
patrick merged 2 commits from feat/livepatch-alert into main 2026-10-30 16:22:06 +00:00
Owner

Summary

An unhealthy Livepatch state was only a note on the dashboard. This adds an ntfy
alert for it.

The alert check notifies once per problem, high priority, when:

  • Livepatch has been unhealthy for livepatch_alert_after_hours (default 6, 0
    disables): a state other than applied/nothing-to-apply, a check that didn't
    complete, or an unsupported kernel; or
  • a host that used to report Livepatch no longer does. A dead Livepatch daemon
    makes canonical-livepatch status fail, the agent has nothing to send, and
    that looks like a host that never had it. A new livepatch_alerts table records
    which hosts have reported Livepatch (plus when the current problem began and
    whether it was notified), so hosts without Livepatch never alert.

Behavior matches the other alerts: one message per episode, healthy again
re-arms it, a problem that clears within the period sends nothing, stale hosts
are skipped, failed deliveries retry, restarts don't repeat, and state is only
written when it changes.

livepatch_problem() is now the single definition of "unhealthy", shared with the
rule that decides whether a pending reboot is covered by Livepatch. It also names
the check state when that is the problem (it used to say "applied, supported" for
a failed check).

The table is CREATE TABLE IF NOT EXISTS, so no migration.

Testing

make test: 235 tests pass (16 new): grace boundary, one alert per episode, every
kind of unhealthy, healthy states never alert, blips forgiven, re-arming, a host
that stops reporting, hosts that never had Livepatch, stale skipped, retry after
a failed send, 0 disables, cascade on host removal, no needless writes, config
validation. Seven deliberate breakages (alert never-enrolled hosts, repeat,
ignore grace, never mark notified, don't skip stale, write every run, reset the
clock) each broke a test.

Not run: against a live host. To try it, set livepatch_alert_after_hours = 0.1
temporarily and stop the Livepatch daemon on a test host.

🤖 Generated with Claude Code

## Summary An unhealthy Livepatch state was only a note on the dashboard. This adds an ntfy alert for it. The alert check notifies once per problem, high priority, when: - Livepatch has been unhealthy for `livepatch_alert_after_hours` (default 6, `0` disables): a state other than applied/nothing-to-apply, a check that didn't complete, or an unsupported kernel; or - a host that **used to report Livepatch no longer does**. A dead Livepatch daemon makes `canonical-livepatch status` fail, the agent has nothing to send, and that looks like a host that never had it. A new `livepatch_alerts` table records which hosts have reported Livepatch (plus when the current problem began and whether it was notified), so hosts without Livepatch never alert. Behavior matches the other alerts: one message per episode, healthy again re-arms it, a problem that clears within the period sends nothing, stale hosts are skipped, failed deliveries retry, restarts don't repeat, and state is only written when it changes. `livepatch_problem()` is now the single definition of "unhealthy", shared with the rule that decides whether a pending reboot is covered by Livepatch. It also names the check state when that is the problem (it used to say "applied, supported" for a failed check). The table is `CREATE TABLE IF NOT EXISTS`, so no migration. ## Testing `make test`: 235 tests pass (16 new): grace boundary, one alert per episode, every kind of unhealthy, healthy states never alert, blips forgiven, re-arming, a host that stops reporting, hosts that never had Livepatch, stale skipped, retry after a failed send, `0` disables, cascade on host removal, no needless writes, config validation. Seven deliberate breakages (alert never-enrolled hosts, repeat, ignore grace, never mark notified, don't skip stale, write every run, reset the clock) each broke a test. Not run: against a live host. To try it, set `livepatch_alert_after_hours = 0.1` temporarily and stop the Livepatch daemon on a test host. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
patrick added 2 commits 2026-10-30 16:19:53 +00:00
The alert check now also notifies, once per problem, when a host's Livepatch has
been unhealthy for livepatch_alert_after_hours (default 6), or when a host that
used to report Livepatch no longer does (a dead daemon leaves the agent with
nothing to send). A livepatch_alerts table records which hosts have reported
Livepatch, when the current problem began and whether it was notified, so hosts
without Livepatch never alert and restarts do not repeat messages. Stale hosts
are skipped.

livepatch_problem() is now the single test for unhealthy, shared with the cover
rule for pending reboots, and names the check state when that is the problem.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Document Livepatch alerts
CI / tests (Python 3.10) (pull_request) Successful in 27s
CI / tests (Python 3.11) (pull_request) Successful in 26s
CI / tests (Python 3.12) (pull_request) Successful in 26s
CI / tests (Python 3.13) (pull_request) Successful in 27s
CI / lint (pull_request) Successful in 5s
83d5e58ea5
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
patrick merged commit 1350c78676 into main 2026-10-30 16:22:06 +00:00
Sign in to join this conversation.
No Reviewers
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: patrick/kernel-automation#22