From 29cfc26c5ffa73096349e7f1353b57a4010a4f1f Mon Sep 17 00:00:00 2001 From: Kenneth Okoh Date: Mon, 11 Nov 2024 10:35:46 +0100 Subject: [PATCH] Azure agent: format file Change-Id: Ied669d7185d3d3ccfc56a8d3f0b5cd5d19841b01 --- cmk/special_agents/agent_azure.py | 59 ++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 12 deletions(-) diff --git a/cmk/special_agents/agent_azure.py b/cmk/special_agents/agent_azure.py index 224cf54fcd0..b6c9974b246 100644 --- a/cmk/special_agents/agent_azure.py +++ b/cmk/special_agents/agent_azure.py @@ -254,7 +254,9 @@ def parse_arguments(argv: Sequence[str]) -> Args: action=vcrtrace(filter_post_data_parameters=[("client_secret", "****")]), ) parser.add_argument( - "--dump-config", action="store_true", help="""Dump parsed configuration and exit""" + "--dump-config", + action="store_true", + help="""Dump parsed configuration and exit""", ) parser.add_argument( "--timeout", @@ -734,7 +736,8 @@ def nic_ip_conf_view(self, group, nic_name, ip_conf_name): "resourceGroups/{}/providers/Microsoft.Network/networkInterfaces/{}/ipConfigurations/{}" ) return self._get( - url.format(group, nic_name, ip_conf_name), params={"api-version": "2022-01-01"} + url.format(group, nic_name, ip_conf_name), + params={"api-version": "2022-01-01"}, ) def nic_vmss_ip_conf_view(self, group, vmss, virtual_machine_index, nic_name, ip_conf_name): @@ -956,7 +959,11 @@ class Section: LOCK = Lock() def __init__( - self, name: str, piggytargets: Iterable[str], separator: int, options: Sequence[str] + self, + name: str, + piggytargets: Iterable[str], + separator: int, + options: Sequence[str], ) -> None: super().__init__() self._sep = chr(separator) @@ -1137,7 +1144,8 @@ def get_frontend_ip_configs( ip_config_data = { **filter_keys(ip_config, ("id", "name")), **filter_keys( - ip_config["properties"], ("privateIPAllocationMethod", "privateIPAddress") + ip_config["properties"], + ("privateIPAllocationMethod", "privateIPAddress"), ), } if "publicIPAddress" in ip_config.get("properties"): @@ -1173,7 +1181,13 @@ def get_routing_rules(app_gateway: Mapping) -> list[Mapping]: def get_http_listeners(app_gateway: Mapping) -> Mapping[str, Mapping]: - listener_keys = ("port", "protocol", "hostNames", "frontendIPConfiguration", "frontendPort") + listener_keys = ( + "port", + "protocol", + "hostNames", + "frontendIPConfiguration", + "frontendPort", + ) return { l["id"]: { "id": l["id"], @@ -1206,7 +1220,10 @@ def process_app_gateway(mgmt_client: MgmtApiClient, resource: AzureResource) -> resource.info["properties"]["frontend_ports"] = frontend_ports backend_settings = { - c["id"]: {"name": c["name"], **filter_keys(c["properties"], ("port", "protocol"))} + c["id"]: { + "name": c["name"], + **filter_keys(c["properties"], ("port", "protocol")), + } for c in app_gateway["properties"]["backendHttpSettingsCollection"] } resource.info["properties"]["backend_settings"] = backend_settings @@ -1297,7 +1314,11 @@ def get_backend_address_pools( backend_addresses.append(backend_address_data) backend_pools.append( - {"id": backend_pool["id"], "name": backend_pool["name"], "addresses": backend_addresses} + { + "id": backend_pool["id"], + "name": backend_pool["name"], + "addresses": backend_addresses, + } ) return backend_pools @@ -1332,7 +1353,11 @@ def get_remote_peerings( vnet_peering_id = vnet_peering["id"] subscription, group, providers, vnet_id, vnet_peering_id = get_params_from_azure_id( vnet_peering_id, - resource_types=["providers", "virtualNetworks", "virtualNetworkPeerings"], + resource_types=[ + "providers", + "virtualNetworks", + "virtualNetworkPeerings", + ], ) # skip vNet peerings that belong to another Azure subscription if subscription != mgmt_client.subscription: @@ -1553,7 +1578,8 @@ def gather_metrics( metric_resource.metrics += resource_metrics else: LOGGER.info( - "Resource %s found in metrics cache no longer monitored", resource_id + "Resource %s found in metrics cache no longer monitored", + resource_id, ) except ApiError as exc: @@ -1580,7 +1606,10 @@ def get_vm_labels_section(vm: AzureResource, group_labels: GroupLabels) -> Label def process_resource( - mgmt_client: MgmtApiClient, resource: AzureResource, group_labels: GroupLabels, args: Args + mgmt_client: MgmtApiClient, + resource: AzureResource, + group_labels: GroupLabels, + args: Args, ) -> Sequence[Section]: sections: list[Section] = [] enabled_services = set(args.services) @@ -1665,7 +1694,12 @@ def write_group_info( section = AzureSection("agent_info") section.add(("monitored-groups", json.dumps(monitored_groups))) - section.add(("monitored-resources", json.dumps([r.info["name"] for r in monitored_resources]))) + section.add( + ( + "monitored-resources", + json.dumps([r.info["name"] for r in monitored_resources]), + ) + ) section.write() # write empty agent_info section for all groups, otherwise # the service will only be discovered if something goes wrong @@ -1826,7 +1860,8 @@ def process_resource_health( "id": health_id, "name": "/".join(health_id.split("/")[-6:-4]), **filter_keys( - health["properties"], ("availabilityState", "summary", "reasonType", "occuredTime") + health["properties"], + ("availabilityState", "summary", "reasonType", "occuredTime"), ), "tags": resource.tags, }