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
@@ -105,6 +105,24 @@ def kernel_reboot_pending(report: dict[str, Any]) -> str | None:
|
||||
return None
|
||||
|
||||
|
||||
def livepatch_problem(report: dict[str, Any]) -> str | None:
|
||||
"""Why Livepatch isn't working on this host, or None if it is (or isn't in use).
|
||||
|
||||
"Working" means a state we recognise as healthy, a completed check and a
|
||||
supported kernel. The same test decides cover for a pending reboot and whether
|
||||
to send a Livepatch alert."""
|
||||
state = report.get("livepatch_state")
|
||||
if state is None:
|
||||
return None
|
||||
if (state not in LIVEPATCH_HEALTHY_STATES or report.get("livepatch_check_state") != "checked"
|
||||
or report.get("livepatch_supported") != "supported"):
|
||||
parts = [state, report.get("livepatch_supported") or "?"]
|
||||
if report.get("livepatch_check_state") != "checked":
|
||||
parts.append(f"check: {report.get('livepatch_check_state') or '?'}")
|
||||
return f"livepatch not healthy ({', '.join(parts)})"
|
||||
return None
|
||||
|
||||
|
||||
def livepatch_cover(report: dict[str, Any], now: float) -> tuple[bool, str | None]:
|
||||
"""(is the running kernel kept patched by Livepatch, a note about it).
|
||||
|
||||
@@ -112,16 +130,14 @@ def livepatch_cover(report: dict[str, Any], now: float) -> tuple[bool, str | Non
|
||||
support ends, so cover lapses LIVEPATCH_MARGIN_DAYS before that date. Hosts
|
||||
without Livepatch data, or with Livepatch in any state we don't recognise as
|
||||
healthy, get no cover and are judged as before."""
|
||||
state = report.get("livepatch_state")
|
||||
if state is None:
|
||||
if report.get("livepatch_state") is None:
|
||||
return False, None
|
||||
if problem := livepatch_problem(report):
|
||||
return False, problem
|
||||
try:
|
||||
deadline = date.fromisoformat(report.get("livepatch_upgrade_required") or "")
|
||||
except ValueError:
|
||||
deadline = None
|
||||
if (state not in LIVEPATCH_HEALTHY_STATES or report.get("livepatch_check_state") != "checked"
|
||||
or report.get("livepatch_supported") != "supported"):
|
||||
return False, f"livepatch not healthy ({state}, {report.get('livepatch_supported') or '?'})"
|
||||
if deadline is None:
|
||||
return False, "livepatch end of support date unknown"
|
||||
left = (deadline - datetime.fromtimestamp(now, timezone.utc).date()).days
|
||||
|
||||
Reference in new issue
Block a user