From 60ee3a606f44a642768dabde440cfeb549053168 Mon Sep 17 00:00:00 2001 From: "Haeger, Sebastian" Date: Fri, 14 Aug 2026 16:33:25 +0200 Subject: [PATCH 1/3] add vm_ip to labels of azure vms --- .../azure_v2/special_agent/agent_azure_v2.py | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/packages/cmk-plugins/cmk/plugins/azure_v2/special_agent/agent_azure_v2.py b/packages/cmk-plugins/cmk/plugins/azure_v2/special_agent/agent_azure_v2.py index 81d3796569a..c21ab9710cc 100644 --- a/packages/cmk-plugins/cmk/plugins/azure_v2/special_agent/agent_azure_v2.py +++ b/packages/cmk-plugins/cmk/plugins/azure_v2/special_agent/agent_azure_v2.py @@ -2368,6 +2368,24 @@ async def _collect_virtual_machines_resources( key="value", ) + nics = await api_client.get_async( + "providers/Microsoft.Network/networkInterfaces", + params={"api-version": "2024-07-01"}, + key="value", + ) + vm_ip_map: dict[str, str] = {} + + for nic in nics: + try: + vm_name = nic["properties"]["virtualMachine"]["id"].lower() + + private_ip = ( + nic["properties"]["ipConfigurations"][0]["properties"]["privateIPAddress"] + ) + vm_ip_map[vm_name] = private_ip + except (KeyError, IndexError): + continue + virtual_machines: list[AzureResource] = [] for vm in response: try: @@ -2385,6 +2403,13 @@ async def _collect_virtual_machines_resources( except KeyError: raise ApiErrorMissingData("Virtual machine instance's statuses must be present") + try: + resource.labels["vm_ip"] = vm_ip_map.get(vm["id"].lower()) + except KeyError: + LOGGER.info( + "Virtual machine not found in ip mapping: %(vm_id)s", {"vm_id": vm["id"]} + ) + resource.info["specific_info"] = {"statuses": statuses} # for backward compatibility resource.labels["vm_instance"] = True From c794df78f83963f24aa609e21c5aef053fceb5a7 Mon Sep 17 00:00:00 2001 From: "Haeger, Sebastian" Date: Mon, 17 Aug 2026 08:54:06 +0200 Subject: [PATCH 2/3] fix linter, typo --- .../azure_v2/special_agent/agent_azure_v2.py | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/packages/cmk-plugins/cmk/plugins/azure_v2/special_agent/agent_azure_v2.py b/packages/cmk-plugins/cmk/plugins/azure_v2/special_agent/agent_azure_v2.py index c21ab9710cc..ffdf3f0e8f2 100644 --- a/packages/cmk-plugins/cmk/plugins/azure_v2/special_agent/agent_azure_v2.py +++ b/packages/cmk-plugins/cmk/plugins/azure_v2/special_agent/agent_azure_v2.py @@ -2369,19 +2369,17 @@ async def _collect_virtual_machines_resources( ) nics = await api_client.get_async( - "providers/Microsoft.Network/networkInterfaces", - params={"api-version": "2024-07-01"}, - key="value", - ) + "providers/Microsoft.Network/networkInterfaces", + params={"api-version": "2024-07-01"}, + key="value", + ) + vm_ip_map: dict[str, str] = {} - for nic in nics: try: vm_name = nic["properties"]["virtualMachine"]["id"].lower() - private_ip = ( - nic["properties"]["ipConfigurations"][0]["properties"]["privateIPAddress"] - ) + private_ip = nic["properties"]["ipConfigurations"][0]["properties"]["privateIPAddress"] vm_ip_map[vm_name] = private_ip except (KeyError, IndexError): continue @@ -2403,12 +2401,9 @@ async def _collect_virtual_machines_resources( except KeyError: raise ApiErrorMissingData("Virtual machine instance's statuses must be present") - try: - resource.labels["vm_ip"] = vm_ip_map.get(vm["id"].lower()) - except KeyError: - LOGGER.info( - "Virtual machine not found in ip mapping: %(vm_id)s", {"vm_id": vm["id"]} - ) + ip = vm_ip_map.get(vm["id"].lower()) + if ip is not None: + resource.labels["vm_ip"] = ip resource.info["specific_info"] = {"statuses": statuses} # for backward compatibility From 674960209c67bd9055428ad1f0052bb416750029 Mon Sep 17 00:00:00 2001 From: "Haeger, Sebastian" Date: Wed, 19 Aug 2026 10:34:04 +0200 Subject: [PATCH 3/3] dummy commit for pipeline --- .../cmk/plugins/azure_v2/special_agent/agent_azure_v2.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/cmk-plugins/cmk/plugins/azure_v2/special_agent/agent_azure_v2.py b/packages/cmk-plugins/cmk/plugins/azure_v2/special_agent/agent_azure_v2.py index ffdf3f0e8f2..63fff090114 100644 --- a/packages/cmk-plugins/cmk/plugins/azure_v2/special_agent/agent_azure_v2.py +++ b/packages/cmk-plugins/cmk/plugins/azure_v2/special_agent/agent_azure_v2.py @@ -2401,9 +2401,9 @@ async def _collect_virtual_machines_resources( except KeyError: raise ApiErrorMissingData("Virtual machine instance's statuses must be present") - ip = vm_ip_map.get(vm["id"].lower()) - if ip is not None: - resource.labels["vm_ip"] = ip + vm_ip = vm_ip_map.get(vm["id"].lower()) + if vm_ip is not None: + resource.labels["vm_ip"] = vm_ip resource.info["specific_info"] = {"statuses": statuses} # for backward compatibility