From 8ec6562ded8300ec47e46e006ea9eac2af2141b4 Mon Sep 17 00:00:00 2001 From: Sofia Colakovic Date: Thu, 8 Aug 2024 17:40:07 +0200 Subject: [PATCH] 16867 FIX azure: Remove unnecessary 'metric not found' errors When querying metrics, Azure agent was reporting each missing metric in the details of the 'Azure Agent Info' service. This didn't influence the status of the service but still implied an error. It was misleading because some metrics aren't defined in some types of resources. Now, those metrics are optional and won't cause an error. SUP-19726 Change-Id: If8f370610c32252f0f9499c4bfed4a60a4910203 --- .werks/16867 | 15 +++++++++++++++ cmk/special_agents/agent_azure.py | 30 +++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 .werks/16867 diff --git a/.werks/16867 b/.werks/16867 new file mode 100644 index 00000000000..bcd18bd7321 --- /dev/null +++ b/.werks/16867 @@ -0,0 +1,15 @@ +Title: azure: Remove unnecessary 'metric not found' errors +Class: fix +Compatible: compat +Component: checks +Date: 1723131636 +Edition: cre +Level: 1 +Version: 2.2.0p33 + +When querying metrics, Azure agent was reporting each missing metric in the +details of the 'Azure Agent Info' service. This didn't influence the status +of the service but still implied an error. + +It was misleading because some metrics aren't defined in some types +of resources. Now, those metrics are optional and won't cause an error. diff --git a/cmk/special_agents/agent_azure.py b/cmk/special_agents/agent_azure.py index c234f52ccd6..6aba8d0ee2a 100644 --- a/cmk/special_agents/agent_azure.py +++ b/cmk/special_agents/agent_azure.py @@ -197,6 +197,22 @@ ], } +OPTIONAL_METRICS: Mapping[str, Sequence[str]] = { + "Microsoft.Sql/servers/databases": [ + "storage_percent", + "deadlock", + "dtu_consumption_percent", + ], + "Microsoft.DBforMySQL/servers": ["seconds_behind_master"], + "Microsoft.DBforMySQL/flexibleServers": ["replication_lag"], + "Microsoft.DBforPostgreSQL/servers": ["pg_replica_log_delay_in_seconds"], + "Microsoft.Network/loadBalancers": ["AllocatedSnatPorts", "UsedSnatPorts"], + "Microsoft.Compute/virtualMachines": [ + "CPU Credits Consumed", + "CPU Credits Remaining", + ], +} + def parse_arguments(argv: Sequence[str]) -> Args: parser = argparse.ArgumentParser(description=__doc__) @@ -1279,7 +1295,7 @@ def get_validity_from_args(self, *args: Any) -> bool: return True def get_live_data(self, *args: Any) -> Any: - mgmt_client, resource_id, err = args + mgmt_client, resource_id, resource_type, err = args metricnames, interval, aggregation, filter_ = self.metric_definition raw_metrics = mgmt_client.metrics( @@ -1297,7 +1313,11 @@ def get_live_data(self, *args: Any) -> Any: if parsed_metric is not None: metrics.append(parsed_metric) else: - msg = "metric not found: {} ({})".format(raw_metric["name"]["value"], aggregation) + metric_name = raw_metric["name"]["value"] + if metric_name in OPTIONAL_METRICS.get(resource_type, []): + continue + + msg = "metric not found: {} ({})".format(metric_name, aggregation) err.add("info", resource_id, msg) LOGGER.info(msg) @@ -1347,7 +1367,11 @@ def gather_metrics(mgmt_client, resource, debug=False): cache = MetricCache(resource, metric_def, NOW, debug=debug) try: resource.metrics += cache.get_data( - mgmt_client, resource.info["id"], err, use_cache=cache.cache_interval > 60 + mgmt_client, + resource.info["id"], + resource.info["type"], + err, + use_cache=cache.cache_interval > 60, ) except ApiError as exc: if debug: