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..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 @@ -2368,6 +2368,22 @@ 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 +2401,10 @@ async def _collect_virtual_machines_resources( except KeyError: raise ApiErrorMissingData("Virtual machine instance's statuses must be present") + 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 resource.labels["vm_instance"] = True