Module: check_mk
Branch: master
Commit: 631ed3174c7085b19e383e4c23d7bc74f620c047
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=631ed3174c7085…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Fri May 3 08:47:53 2019 +0200
agent_azure: refactoring I
* rename _monitor_client attribute
* adjust exception handline
* move _get_timespans for readable diff comming up
Change-Id: I8eda3bf199bafa9e87d26ae47ef2cf8ec9a25e26
---
agents/special/agent_azure | 38 ++++++++++++++++++--------------------
1 file changed, 18 insertions(+), 20 deletions(-)
diff --git a/agents/special/agent_azure b/agents/special/agent_azure
index b7e9325..6701bfd 100755
--- a/agents/special/agent_azure
+++ b/agents/special/agent_azure
@@ -509,7 +509,7 @@ class AzureClient(object): # pylint:
disable=too-many-instance-attributes
self._creds = ServicePrincipalCredentials(
client_id=args.client, secret=args.secret, tenant=args.tenant)
# azure-api-call
- self._monitor_client = MonitorManagementClient(self._creds,
self.args.subscription)
+ self.monitor_client = MonitorManagementClient(self._creds,
self.args.subscription)
# azure-api-call
self._resource_client = ResourceManagementClient(self._creds,
self.args.subscription)
@@ -517,21 +517,6 @@ class AzureClient(object): # pylint:
disable=too-many-instance-attributes
self.timespans = self._get_timespans()
self._cache = {}
- @staticmethod
- def _get_timespans(time_end=datetime.datetime.utcnow()):
- """compute timespans dict"""
-
- def interval(**kwargs):
- start = time_end - datetime.timedelta(**kwargs)
- return "%s/%s" % (start.strftime("%Y-%m-%dT%H:%M:%SZ"),
- time_end.strftime("%Y-%m-%dT%H:%M:%SZ"))
-
- return {
- "PT1M": interval(minutes=3),
- "PT5M": interval(minutes=15),
- "PT1H": interval(hours=3),
- }
-
def init_specific(self, resources):
r_types = set(r.info["type"] for r in resources)
for rtp in r_types:
@@ -558,11 +543,26 @@ class AzureClient(object): # pylint:
disable=too-many-instance-attributes
self._cache["resources"] = map(AzureResource, raw_resources)
return self._cache["resources"]
+ @staticmethod
+ def _get_timespans(time_end=datetime.datetime.utcnow()):
+ """compute timespans dict"""
+
+ def interval(**kwargs):
+ start = time_end - datetime.timedelta(**kwargs)
+ return "%s/%s" % (start.strftime("%Y-%m-%dT%H:%M:%SZ"),
+ time_end.strftime("%Y-%m-%dT%H:%M:%SZ"))
+
+ return {
+ "PT1M": interval(minutes=3),
+ "PT5M": interval(minutes=15),
+ "PT1H": interval(hours=3),
+ }
+
def _metric_api_call(self, rid, timespan, interval, metric, aggregation, filter_):
LOG.debug(
"metrics.list(%r, timespan=%r, interval=%r, metric=%r,
aggregation=%r,"
" filter=%r, raw=True)", rid, timespan, interval, metric,
aggregation, filter_)
- raw = self._monitor_client.metrics.list(
+ raw = self.monitor_client.metrics.list(
rid,
timespan=timespan,
interval=interval,
@@ -587,9 +587,7 @@ class AzureClient(object): # pylint:
disable=too-many-instance-attributes
try:
response, raw_metrics = self._metric_api_call(rid, timespan, interval,
metricnames,
aggregation, filter_)
- except ErrorResponseException as exc:
- if self.args.debug:
- raise exc
+ except () if self.args.debug else ErrorResponseException as exc:
err.add("exception", rid, exc.message)
LOG.exception(exc)
return []