From 8fe71379c9e6bb77d090f5cb4b9ee3b256e2b25b Mon Sep 17 00:00:00 2001 From: Pierre Ducroquet Date: Wed, 9 Nov 2022 13:32:03 +0100 Subject: [PATCH] add a check for the running kernel version (#63481) --- .../prometheus-system-exporter.py | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/prometheus-entrouvert-exporter/prometheus-system-exporter.py b/prometheus-entrouvert-exporter/prometheus-system-exporter.py index ab187b4..1965aef 100755 --- a/prometheus-entrouvert-exporter/prometheus-system-exporter.py +++ b/prometheus-entrouvert-exporter/prometheus-system-exporter.py @@ -53,7 +53,7 @@ eo_rabbitmq = Gauge("eo_rabbitmq", "rabbitmq", ["ctn"], registry=registry) eo_threads = Gauge("eo_threads", "system threads", ["ctn"], registry=registry) eo_units = Gauge("eo_units", "systemd units", ["ctn", "name", "state"], registry=registry) eo_packages = Gauge("eo_packages", "packages", ["ctn", "state"], registry=registry) - +eo_kernel = Gauge("eo_kernel", "kernel update", ["ctn"], registry=registry) def run(cmd): m = shlex.split(cmd) @@ -280,6 +280,31 @@ def run_in_machines(ctn): metric.labels(**s.labels).set(s.value) +def check_kernel_version(ctn): + # no check if no kernel installed (aka container) + if not os.path.exists("/vmlinuz"): + return + + uname = os.uname() + current_version = uname.version + current_release = uname.release + + # first check, simple : verify that the current release match /vmlinuz + next_boot_release = os.path.basename(os.readlink("/vmlinuz")) + if next_boot_release != "vmlinuz-%s" % current_release: + eo_kernel.labels(ctn).set(2) + return + + # second check, a bit harder : verify that the current version matches the package + current_version_extract = current_version.split(" ")[3] + for line in subprocess.check_output(["dpkg", "--status", "linux-image-" + current_release]).split(b"\n"): + if line.startswith(b"Version: "): + if line != b"Version: " + current_version_extract.encode("ascii"): + eo_kernel.labels(ctn).set(1) + return + break + eo_kernel.labels(ctn).set(0) + if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("--test", action="store_true", help="raise errors") @@ -288,6 +313,7 @@ if __name__ == "__main__": for test in [ certificates, + check_kernel_version, debian, etckeeper, exim,