Skip to content

Commit

Permalink
Azure agent: format file
Browse files Browse the repository at this point in the history
Change-Id: Ied669d7185d3d3ccfc56a8d3f0b5cd5d19841b01
  • Loading branch information
oKenneth committed Nov 11, 2024
1 parent 3cfa194 commit 29cfc26
Showing 1 changed file with 47 additions and 12 deletions.
59 changes: 47 additions & 12 deletions cmk/special_agents/agent_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"):
Expand Down Expand Up @@ -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"],
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
}
Expand Down

0 comments on commit 29cfc26

Please sign in to comment.