diff --git a/cmk/plugins/checkmk/agent_based/check_mk.py b/cmk/plugins/checkmk/agent_based/check_mk.py index 76adb46e78c..8bb30afc282 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,13 @@ 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", 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", ),