Module: check_mk
Branch: master
Commit: 8e285cb99766b0412fd2905419054d7a4f8993a5
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=8e285cb99766b0…
Author: Moritz Kiemer <mo(a)mathias-kettner.de>
Date: Mon Apr 15 10:50:44 2019 +0200
agent_azure: tiny refactoring to prepare for 'client.list_groups
Change-Id: Iabf765b7bacb438b95de35a59f6428082e9f4917
---
agents/special/agent_azure | 17 ++++++++---------
1 file changed, 8 insertions(+), 9 deletions(-)
diff --git a/agents/special/agent_azure b/agents/special/agent_azure
index a75cbfb..c503791 100755
--- a/agents/special/agent_azure
+++ b/agents/special/agent_azure
@@ -506,9 +506,8 @@ class AzureClient(object): # pylint:
disable=too-many-instance-attributes
self._resource_client = ResourceManagementClient(self._creds,
self.args.subscription)
self.specific_clients = {}
-
self.timespans = self._get_timespans()
- self.resources_cache = None
+ self._cache = {}
@staticmethod
def _get_timespans():
@@ -539,12 +538,12 @@ class AzureClient(object): # pylint:
disable=too-many-instance-attributes
return
client.process(resource, self.args)
- def discover_resources(self):
- if self.resources_cache is None:
+ def list_resources(self):
+ if "resources" not in self._cache:
# azure-api-call
raw_resources = self._resource_client.resources.list()
- self.resources_cache = map(AzureResource, raw_resources)
- return self.resources_cache
+ self._cache["resources"] = map(AzureResource, raw_resources)
+ return self._cache["resources"]
def _metric_api_call(self, rid, timespan, interval, metric, aggregation, filter_):
LOG.debug(
@@ -628,7 +627,7 @@ def process_resource(args):
return sections
-def write_groups(resources):
+def write_group_info(resources):
groups = sorted(set(r.info['group'] for r in resources))
section = Section('agent_info')
section.add(('monitored-groups', json.dumps(groups)))
@@ -664,10 +663,10 @@ def main(argv=None):
try:
client = AzureClient(args)
- resources = [r for r in client.discover_resources() if selector.do_monitor(r)]
+ resources = [r for r in client.list_resources() if selector.do_monitor(r)]
client.init_specific(resources)
- write_groups(resources)
+ write_group_info(resources)
func_args = ((resource, client) for resource in resources)
map_ = map if args.sequential else AsyncMapper(args.timeout, args.debug)