Show Ubuntu phased updates separately from available updates

apt lists updates deferred by phasing in an indented block rather than
as Inst lines, so they were already excluded from the counts but
invisible. The agent now parses that block into phased_packages; the
dashboard shows "+N phased" in the Updates column (with a tooltip) and
the list on the host page. Phasing never affects status: Ubuntu doesn't
phase security updates, and there's nothing to act on until apt offers
the update.

Run the apt simulation with LC_ALL=C since we parse its messages (the
systemd unit already runs in the C locale; manual --print may not).
Agent and server 0.3.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
patrickandClaude Opus 5.5 committed 2026-10-17 12:03:02 -04:00
1 parent ac17a98e91
commit 271af3b071
8 files changed
+76 -7

No files matched your search

+12 -3
View File
@@ -6,7 +6,7 @@
# rules can change without redeploying agents.
set -euo pipefail
AGENT_VERSION=0.2.0
AGENT_VERSION=0.3.0
# Prefix for every file the agent reads. Only the test suite sets this.
ROOT=${KERNELWATCH_ROOT:-}
@@ -153,15 +153,23 @@ read_needrestart() {
# Simulated dist-upgrade. Reads only: no locks, no cache files written.
# dist-upgrade (not upgrade) so new-ABI kernel packages pulled in by the
# meta-package show up.
# meta-package show up. C locale because we parse apt's messages.
apt_simulation() {
apt-get -s -q \
LC_ALL=C apt-get -s -q \
-o Debug::NoLocking=true \
-o Dir::Cache::pkgcache= \
-o Dir::Cache::srcpkgcache= \
dist-upgrade 2>/dev/null || true
}
# Packages Ubuntu is holding back from this host for now (phased updates). apt
# lists them in an indented block instead of as Inst lines, so they're not in
# the upgradable counts. Debian doesn't phase updates.
phased_packages() {
sed -n '/deferred due to phasing:$/,/^[^ ]/{/^ /p}' |
tr -s ' ' '\n' | sed '/^$/d' | sort -u
}
# Seconds since apt last refreshed its package lists, or empty if unknown.
apt_lists_age() {
local newest=0 f m
@@ -223,6 +231,7 @@ build_report() {
printf '"reboot_required_pkgs":%s,' "$(json_str_array <<<"$reboot_pkgs")"
printf '"upgradable_count":%s,' "$(json_int "$(grep -c . <<<"$inst" || true)")"
printf '"security_count":%s,' "$(json_int "$(grep -ci 'security' <<<"$inst" || true)")"
printf '"phased_packages":%s,' "$(phased_packages <<<"$sim" | json_str_array)"
printf '"kernel_upgradable":%s,' "$(awk '$2 ~ /^linux-image-/ { print $2 }' <<<"$inst" | json_str_array)"
printf '"apt_lists_age_seconds":%s,' "$(json_int "$(apt_lists_age)")"
printf '"uptime_seconds":%s' "$(json_int "$(uptime_seconds)")"