Flag hosts where unattended-upgrades has stopped succeeding

On a host with unattended-upgrades enabled, no successful run in
unattended_upgrades_stale_after_days (default 3, 0 disables) puts it in
update. The reason says which way it broke: still running but failing
("last succeeded 5d ago and is failing (last ran 6h ago); check
/var/log/unattended-upgrades/"), not running at all ("is
apt-daily-upgrade.timer enabled?"), or never succeeded. A host where it
hasn't completed its first run yet gets a note, and packages it keeps back
are noted. Hosts with it disabled or not installed, and agents before
0.8.0, are judged as before. The host page shows the state, both stamp
ages and the kept-back packages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
patrickandClaude Opus 5.5 committed 2026-10-31 20:18:41 -04:00
1 parent df097c9da3
commit bfac723850
7 files changed
+143

No files matched your search

+13
View File
@@ -84,6 +84,17 @@ def utc(ts: float | None) -> str:
return time.strftime("%Y-%m-%d %H:%M:%S UTC", time.gmtime(ts)) if ts else ""
def unattended_upgrades_summary(report: dict[str, Any]) -> str | None:
state = report.get("unattended_upgrades")
if state != "enabled":
return state # "disabled", "not-installed", or None from agents before 0.8.0
last = {"success": report.get("unattended_upgrades_success_age_seconds"),
"run": report.get("unattended_upgrades_run_age_seconds")}
return "enabled, " + ", ".join(
f"last {what} " + ("never" if age is None else f"{duration(age)} before the report")
for what, age in last.items())
def phased_summary(report: dict[str, Any]) -> tuple[str, str]:
"""(short cell text, full description) for updates deferred by Ubuntu's phasing."""
if report.get("os_id") not in (None, "ubuntu"):
@@ -512,6 +523,8 @@ class Handler(BaseHTTPRequestHandler):
field("/boot free", None if r.get("boot_free_kb") is None else
f"{r['boot_free_kb'] // 1024} MB of {(r.get('boot_size_kb') or 0) // 1024} MB"),
field("Unfinished dpkg packages", r.get("dpkg_unfinished_packages"), code=True),
field("unattended-upgrades", unattended_upgrades_summary(r)),
field("Kept back by unattended-upgrades", r.get("unattended_upgrades_kept_back"), code=True),
field("Package lists age", duration(r.get("apt_lists_age_seconds"))
if r.get("apt_lists_age_seconds") is not None else None),
field("Uptime", duration(r.get("uptime_seconds")) if r.get("uptime_seconds") is not None else None),