Report unattended-upgrades state from the agent
The agent now sends whether unattended-upgrades is enabled (package installed, not just its leftover config, and APT::Periodic::Unattended- Upgrade set and non-zero), the age of apt.systemd.daily's upgrade-stamp (touched only when unattended-upgrade exits 0), the age of unattended-upgrade's own stamp (written whenever a run gets far enough, even if it then fails) and the packages it keeps back. Nothing reads them yet. Agent 0.8.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6cbc9665d8
commit
df097c9da3
4 files changed
+104
-3
No files matched your search
+39
-1
@@ -6,7 +6,7 @@
|
||||
# rules can change without redeploying agents.
|
||||
set -euo pipefail
|
||||
|
||||
AGENT_VERSION=0.7.0
|
||||
AGENT_VERSION=0.8.0
|
||||
|
||||
# Prefix for every file the agent reads. Only the test suite sets this.
|
||||
ROOT=${KERNELWATCH_ROOT:-}
|
||||
@@ -261,6 +261,39 @@ unfinished_packages() {
|
||||
sort -u || true
|
||||
}
|
||||
|
||||
# unattended-upgrades: "enabled", "disabled" or "not-installed". Enabled means the
|
||||
# package is installed (not just its leftover config, dpkg state rc) and
|
||||
# APT::Periodic::Unattended-Upgrade is set and not 0, which is what makes
|
||||
# apt-daily-upgrade.service (apt.systemd.daily) run it.
|
||||
unattended_upgrades_state() {
|
||||
local abbrev value
|
||||
abbrev=$(dpkg-query -W -f='${db:Status-Abbrev}' unattended-upgrades 2>/dev/null || true)
|
||||
if [[ $abbrev != ii* ]]; then
|
||||
printf 'not-installed'
|
||||
return 0
|
||||
fi
|
||||
value=$(apt-config dump APT::Periodic::Unattended-Upgrade 2>/dev/null |
|
||||
sed -n 's/^APT::Periodic::Unattended-Upgrade "\(.*\)";$/\1/p' | tail -n1 || true)
|
||||
if [[ -n $value && $value != 0 ]]; then printf 'enabled'; else printf 'disabled'; fi
|
||||
}
|
||||
|
||||
# Seconds since the file at $1 was modified, or empty if it doesn't exist.
|
||||
file_age() {
|
||||
local m
|
||||
m=$(stat -c %Y "$1" 2>/dev/null) || return 0
|
||||
printf '%s' $(($(date +%s) - m))
|
||||
}
|
||||
|
||||
# apt.systemd.daily touches upgrade-stamp only when unattended-upgrade exits 0.
|
||||
# unattended-upgrade writes its own stamp whenever a run gets far enough to know
|
||||
# what it would do, even if it then fails (e.g. on a conffile prompt). So a newer
|
||||
# run stamp than success stamp means it's running but failing.
|
||||
UU_SUCCESS_STAMP=$ROOT/var/lib/apt/periodic/upgrade-stamp
|
||||
UU_RUN_STAMP=$ROOT/var/lib/apt/periodic/unattended-upgrades-stamp
|
||||
# Packages from its allowed origins it didn't upgrade (held, blacklisted, conffile
|
||||
# prompt), space-separated; removed when there are none.
|
||||
UU_KEPT_FILE=$ROOT/var/lib/unattended-upgrades/kept-back
|
||||
|
||||
# Ubuntu Pro state from the pro client's status cache, which it keeps
|
||||
# world-readable (the token lives in private/ next to it). Prints "ATTACHED ESM"
|
||||
# (e.g. "true enabled", "false -"); nothing if there's no file or it can't be
|
||||
@@ -361,6 +394,11 @@ build_report() {
|
||||
*) printf '"ubuntu_pro_attached":null,' ;;
|
||||
esac
|
||||
printf '"ubuntu_esm_infra":%s,' "$(json_str_or_null "$pro_esm")"
|
||||
printf '"unattended_upgrades":%s,' "$(json_str "$(unattended_upgrades_state)")"
|
||||
printf '"unattended_upgrades_success_age_seconds":%s,' "$(json_int "$(file_age "$UU_SUCCESS_STAMP")")"
|
||||
printf '"unattended_upgrades_run_age_seconds":%s,' "$(json_int "$(file_age "$UU_RUN_STAMP")")"
|
||||
printf '"unattended_upgrades_kept_back":%s,' \
|
||||
"$( { [[ -r $UU_KEPT_FILE ]] && tr -s ' \t' '\n' <"$UU_KEPT_FILE"; } | sort -u | json_str_array)"
|
||||
printf '"apt_lists_age_seconds":%s,' "$(json_int "$(apt_lists_age)")"
|
||||
printf '"uptime_seconds":%s' "$(json_int "$(uptime_seconds)")"
|
||||
printf '}\n'
|
||||
|
||||
Reference in new issue
Block a user