Alert when Livepatch is broken or has stopped reporting
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>
This commit is contained in:
1 parent
203c729e14
commit
650806bfce
7 files changed
+346
-6
No files matched your search
@@ -42,6 +42,11 @@ CREATE TABLE IF NOT EXISTS status_alerts (
|
||||
since INTEGER NOT NULL,
|
||||
notified_level TEXT
|
||||
);
|
||||
CREATE TABLE IF NOT EXISTS livepatch_alerts (
|
||||
host TEXT PRIMARY KEY REFERENCES hosts(name) ON DELETE CASCADE,
|
||||
since INTEGER,
|
||||
notified INTEGER NOT NULL DEFAULT 0
|
||||
);
|
||||
"""
|
||||
|
||||
|
||||
@@ -271,6 +276,27 @@ def clear_status_alert(conn: sqlite3.Connection, host: str) -> None:
|
||||
conn.execute("DELETE FROM status_alerts WHERE host = ?", (host,))
|
||||
|
||||
|
||||
# --- livepatch notifications -------------------------------------------------
|
||||
|
||||
def livepatch_alerts(conn: sqlite3.Connection) -> dict[str, tuple[int | None, bool]]:
|
||||
"""host -> (when its current Livepatch problem began or None, whether it was
|
||||
notified). A host appears once it has reported Livepatch at all, which is how
|
||||
"stopped reporting it" is told apart from "never had it"."""
|
||||
return {r["host"]: (r["since"], bool(r["notified"]))
|
||||
for r in conn.execute("SELECT * FROM livepatch_alerts")}
|
||||
|
||||
|
||||
def save_livepatch_alert(conn: sqlite3.Connection, host: str, since: int | None,
|
||||
notified: bool) -> None:
|
||||
# The host may have been removed while a notification was in flight.
|
||||
conn.execute(
|
||||
"INSERT INTO livepatch_alerts (host, since, notified) "
|
||||
"SELECT name, ?, ? FROM hosts WHERE name = ? "
|
||||
"ON CONFLICT(host) DO UPDATE SET since = excluded.since, notified = excluded.notified",
|
||||
(since, int(notified), host),
|
||||
)
|
||||
|
||||
|
||||
# --- users & sessions -------------------------------------------------------
|
||||
|
||||
def set_user(conn: sqlite3.Connection, name: str, pw_hash: str) -> None:
|
||||
|
||||
Reference in new issue
Block a user