add a check for the running kernel version (#63481)
gitea/publik-infra/pipeline/head This commit looks good
Details
gitea/publik-infra/pipeline/head This commit looks good
Details
This commit is contained in:
parent
e797a96dd2
commit
8fe71379c9
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue