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:
1 parent
df097c9da3
commit
bfac723850
7 files changed
+143
No files matched your search
@@ -157,6 +157,40 @@ def boot_space_low(report: dict[str, Any], cfg: Config) -> str | None:
|
||||
return f"/boot has {free_kb // 1024} MB free{used}; the next kernel may not fit"
|
||||
|
||||
|
||||
UU_LOG = "/var/log/unattended-upgrades/"
|
||||
|
||||
|
||||
def _age(seconds: int) -> str:
|
||||
return f"{seconds // 86400}d" if seconds >= 86400 else f"{seconds // 3600}h"
|
||||
|
||||
|
||||
def unattended_upgrades_problem(report: dict[str, Any], cfg: Config) -> tuple[bool, str] | None:
|
||||
"""(is it a problem, why) about unattended-upgrades on a host that has it enabled,
|
||||
or None. Hosts without it, and agents before 0.8.0, get nothing.
|
||||
|
||||
The success stamp is apt.systemd.daily's (touched only when unattended-upgrade
|
||||
exits 0); the run stamp is unattended-upgrade's own (written even when the run
|
||||
then fails). Ages are as of the report."""
|
||||
if report.get("unattended_upgrades") != "enabled" or not cfg.unattended_upgrades_stale_after_days:
|
||||
return None
|
||||
success = report.get("unattended_upgrades_success_age_seconds")
|
||||
run = report.get("unattended_upgrades_run_age_seconds")
|
||||
if success is None:
|
||||
if run is None:
|
||||
# Freshly installed: the first daily run hasn't happened yet.
|
||||
return False, "unattended-upgrades is enabled but hasn't completed a run yet"
|
||||
return True, (f"unattended-upgrades has never succeeded (last ran {_age(run)} ago); "
|
||||
f"check {UU_LOG}")
|
||||
if success <= cfg.unattended_upgrades_stale_after_days * 86400:
|
||||
return None
|
||||
# A successful run writes both stamps within moments of each other.
|
||||
if run is not None and run < success - 3600:
|
||||
return True, (f"unattended-upgrades last succeeded {_age(success)} ago and is failing "
|
||||
f"(last ran {_age(run)} ago); check {UU_LOG}")
|
||||
return True, (f"unattended-upgrades hasn't run in {_age(success)}; "
|
||||
"is apt-daily-upgrade.timer enabled?")
|
||||
|
||||
|
||||
def _kernel_only_reboot_file(report: dict[str, Any]) -> bool:
|
||||
"""/run/reboot-required exists only because of kernel packages."""
|
||||
pkgs = report.get("reboot_required_pkgs") or []
|
||||
@@ -229,6 +263,18 @@ def evaluate(received_at: int | None, report: dict[str, Any] | None, now: float,
|
||||
if low := boot_space_low(report, cfg):
|
||||
status.raise_to("update", low)
|
||||
|
||||
if found := unattended_upgrades_problem(report, cfg):
|
||||
problem, why = found
|
||||
if problem:
|
||||
status.raise_to("update", why)
|
||||
else:
|
||||
status.note(why)
|
||||
# Packages from its allowed origins (by default security) it won't install: held,
|
||||
# blacklisted or stuck on a conffile prompt. They stay pending until someone acts.
|
||||
if report.get("unattended_upgrades") == "enabled" and (kept := report.get("unattended_upgrades_kept_back")):
|
||||
more = f", +{len(kept) - 5} more" if len(kept) > 5 else ""
|
||||
status.note(f"unattended-upgrades is keeping back {', '.join(kept[:5])}{more}")
|
||||
|
||||
today = datetime.fromtimestamp(now, timezone.utc).date()
|
||||
if found := support.check(report, today, cfg.os_eol_warn_days):
|
||||
problem, why = found
|
||||
|
||||
Reference in new issue
Block a user