From 6af7ee3e76f11f7bf2c6677503aa764eb0db48c7 Mon Sep 17 00:00:00 2001 From: "Buhleier, Leon" Date: Fri, 21 Aug 2026 14:31:37 +0200 Subject: [PATCH 1/3] Added host labels for the checkmk agents version --- cmk/plugins/checkmk/agent_based/check_mk.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmk/plugins/checkmk/agent_based/check_mk.py b/cmk/plugins/checkmk/agent_based/check_mk.py index 76adb46e78c..294b36657ce 100644 --- a/cmk/plugins/checkmk/agent_based/check_mk.py +++ b/cmk/plugins/checkmk/agent_based/check_mk.py @@ -4,6 +4,8 @@ # conditions defined in the file COPYING, which is part of this source code package. +import re + from cmk.agent_based.v2 import ( AgentSection, Attributes, @@ -84,6 +86,11 @@ def host_label_function_labels(section: CheckmkSection) -> HostLabelGenerator: if (osversion := section.get("osversion")) is not None: yield HostLabel("cmk/os_version", osversion) + if (agent_version := section.get("version")) is not None: + yield HostLabel("cmk/agent_version", agent_version) + agent_major = re.match(r'[0-9.]+', agent_version) + yield HostLabel("cmk/agent_version_major", agent_major.group(0) if agent_major else agent_version) + agent_section_check_mk = AgentSection( name="check_mk", From d2eb4108ec032e53299e17c161b23c1c974f15da Mon Sep 17 00:00:00 2001 From: "Buhleier, Leon" Date: Fri, 21 Aug 2026 14:32:04 +0200 Subject: [PATCH 2/3] Formatting --- cmk/plugins/checkmk/agent_based/check_mk.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmk/plugins/checkmk/agent_based/check_mk.py b/cmk/plugins/checkmk/agent_based/check_mk.py index 294b36657ce..8bb30afc282 100644 --- a/cmk/plugins/checkmk/agent_based/check_mk.py +++ b/cmk/plugins/checkmk/agent_based/check_mk.py @@ -88,8 +88,10 @@ def host_label_function_labels(section: CheckmkSection) -> HostLabelGenerator: if (agent_version := section.get("version")) is not None: yield HostLabel("cmk/agent_version", agent_version) - agent_major = re.match(r'[0-9.]+', agent_version) - yield HostLabel("cmk/agent_version_major", agent_major.group(0) if agent_major else agent_version) + agent_major = re.match(r"[0-9.]+", agent_version) + yield HostLabel( + "cmk/agent_version_major", agent_major.group(0) if agent_major else agent_version + ) agent_section_check_mk = AgentSection( From 04265e91e4da530b58603e855636a2fa8bd3433d Mon Sep 17 00:00:00 2001 From: "Buhleier, Leon" Date: Fri, 18 Sep 2026 15:30:03 +0200 Subject: [PATCH 3/3] Added new host labels to checkmk unit test --- tests/unit/cmk/plugins/checkmk/agent_based/test_checkmk.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/unit/cmk/plugins/checkmk/agent_based/test_checkmk.py b/tests/unit/cmk/plugins/checkmk/agent_based/test_checkmk.py index 6af2f9ef40a..047ba77bf48 100644 --- a/tests/unit/cmk/plugins/checkmk/agent_based/test_checkmk.py +++ b/tests/unit/cmk/plugins/checkmk/agent_based/test_checkmk.py @@ -39,6 +39,8 @@ HostLabel("cmk/os_platform", "ubuntu"), HostLabel("cmk/os_name", "Ubuntu"), HostLabel("cmk/os_version", "20.04"), + HostLabel("cmk/agent_version", "1.7.0i1"), + HostLabel("cmk/agent_version_major", "1.7.0"), ], id="linux current agent", ), @@ -53,6 +55,8 @@ [ HostLabel("cmk/os_family", "linux"), HostLabel("cmk/os_platform", "linux"), + HostLabel("cmk/agent_version", "1.7.0i1"), + HostLabel("cmk/agent_version_major", "1.7.0"), ], id="old agent", ), @@ -66,6 +70,8 @@ [ HostLabel("cmk/os_family", "windows"), HostLabel("cmk/os_platform", "windows"), + HostLabel("cmk/agent_version", "1.7.0i1"), + HostLabel("cmk/agent_version_major", "1.7.0"), ], id="windows agent", ),