Module: check_mk
Branch: master
Commit: b2ad01a6d21f24206093581c6bd6dd9e549447c2
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b2ad01a6d21f24…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Mon Sep 24 10:31:36 2018 +0200
agent_azure: fix API call, azure.include: fix tag formatting
Change-Id: I86665dd89186a35a7c8e5420c4cc01773f5b8b13
---
agents/special/agent_azure | 26 ++++++++++++++++++--------
checks/azure.include | 11 ++++++-----
2 files changed, 24 insertions(+), 13 deletions(-)
diff --git a/agents/special/agent_azure b/agents/special/agent_azure
index 7cae8eb..6c44d11 100755
--- a/agents/special/agent_azure
+++ b/agents/special/agent_azure
@@ -336,11 +336,14 @@ class AzureClient(object):
self._resource_client = ResourceManagementClient(self._creds,
args.subscription_id)
# compute timespan once, and keep it fixed
- time_end = datetime.datetime.utcnow()
- time_min = datetime.timedelta(minutes=5)
- time_hrs = datetime.timedelta(hours=2)
- self.timespan_min = "%s/%s" % (time_end - time_min, time_end)
- self.timespan_hrs = "%s/%s" % (time_end - time_hrs, time_end)
+ t_end = datetime.datetime.utcnow()
+ t_min = t_end - datetime.timedelta(minutes=5)
+ t_hrs = t_end - datetime.timedelta(hours=2)
+ self.timespan_min =
"/".join((t_min.strftime("%Y-%m-%dT%H:%M:%SZ"),
+ t_end.strftime("%Y-%m-%dT%H:%M:%SZ")))
+ self.timespan_hrs =
"/".join((t_hrs.strftime("%Y-%m-%dT%H:%M:%SZ"),
+ t_end.strftime("%Y-%m-%dT%H:%M:%SZ")))
+
self.resources_cache = None
self.metrics_cache = {}
@@ -353,8 +356,14 @@ class AzureClient(object):
def discover_metrics(self, rid):
if rid not in self.metrics_cache:
- # azure-api-call
- md_list = list(self._monitor_client.metric_definitions.list(rid))
+ try:
+ # azure-api-call
+ md_list = list(self._monitor_client.metric_definitions.list(rid))
+ except ErrorResponseException, exc:
+ if "is not a supported platform metric namespace" in
exc.message:
+ md_list = []
+ else:
+ raise exc
self.metrics_cache[rid] = md_list
log.debug("%d discovered metrics: %r", len(md_list), [md.name.value
for md in md_list])
return self.metrics_cache[rid]
@@ -382,6 +391,7 @@ class AzureClient(object):
for m_def in self.discover_metrics(rid): # sort into categories
cat = self._categorize_metric(m_def)
categorized_metrics.setdefault(cat, []).append(m_def)
+ log.debug("categorized_metrics = %r", categorized_metrics)
for time_grain in ('PT1M', 'PT1H'):
metrics_no_dim = categorized_metrics.get('%s_no_dim' % time_grain)
@@ -427,7 +437,7 @@ class AzureClient(object):
rid,
timespan=timespan,
interval=time_grain,
- metric=metricnames,
+ metricnames=metricnames,
aggregation=aggregations,
filter=filters,
raw=True,
diff --git a/checks/azure.include b/checks/azure.include
index 4cc4059..4a68d3d 100644
--- a/checks/azure.include
+++ b/checks/azure.include
@@ -36,13 +36,14 @@ def get_resource(check_function):
def azure_iter_informative_attrs(resource):
- loc = resource.get('location', None)
- if loc:
+
+ loc = resource.get('location')
+ if loc is not None:
yield 'Location', loc
- tags = resource.get('tags', {})
- for k, v in tags.iteritems():
+
+ for k, v in resource.get('tags', {}).iteritems():
if not k.startswith("hidden-"):
- yield k, v
+ yield k[0].upper() + k[1:], v
def check_azure_metric(resource, metric_key, cmk_key, display_name, levels=None,