Module: check_mk
Branch: master
Commit: 320b6c709d68d07a330370f6e9be490623491851
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=320b6c709d68d0…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Tue Apr 16 14:12:16 2019 +0200
7372 FIX agent_aws: Fixed restriction of services by tags
Wow, what a rookie mistake... :(
Change-Id: I0740ab3d80b36fc59e6ba37af14c1cfd5eab3abd
---
.werks/7372 | 13 +++++++++++++
cmk/special_agents/agent_aws.py | 23 +++++++++++++++++------
2 files changed, 30 insertions(+), 6 deletions(-)
diff --git a/.werks/7372 b/.werks/7372
new file mode 100644
index 0000000..89f1bd7
--- /dev/null
+++ b/.werks/7372
@@ -0,0 +1,13 @@
+Title: agent_aws: Fixed restriction of services by tags
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1555416683
+Class: fix
+
+If tags were configured in the special agent {{Amazon Web Services (AWS)}}
+and began or ended with 't', 'a', 'g' or ':' in the
related tag key, the
+special agent stripped these characters away. These tagged AWS resources
+were not discovered.
diff --git a/cmk/special_agents/agent_aws.py b/cmk/special_agents/agent_aws.py
index 6db2ef1..6845a72 100644
--- a/cmk/special_agents/agent_aws.py
+++ b/cmk/special_agents/agent_aws.py
@@ -678,7 +678,15 @@ class AWSSection(object):
"""
if not tags:
return
- return [{'Key': e['Name'].strip("tag:"),
'Value': v} for e in tags for v in e['Values']]
+ prepared_tags = []
+ for tag in tags:
+ tag_name = tag['Name']
+ if tag_name.startswith('tag:'):
+ tag_key = tag_name[4:]
+ else:
+ tag_key = tag_name
+ prepared_tags.extend([{'Key': tag_key, 'Value': v} for v in
tag['Values']])
+ return prepared_tags
class AWSSectionLimits(AWSSection):
@@ -2708,6 +2716,14 @@ class AWSConfig(object):
self.service_config = {}
def add_service_tags(self, tags_key, tags):
+ """Convert commandline input
+ from
+ ([['foo'], ['aaa'], ...], [['bar', 'baz'],
['bbb', 'ccc'], ...])
+ to
+ Filters=[{'Name': 'tag:foo', 'Values':
['bar', 'baz']},
+ {'Name': 'tag:aaa', 'Values':
['bbb', 'ccc']}, ...]
+ as we need in API methods if and only if keys AND values are set.
+ """
self.service_config.setdefault(tags_key, None)
if tags != (None, None):
self.service_config[tags_key] = self._prepare_tags(tags)
@@ -2715,11 +2731,6 @@ class AWSConfig(object):
self.service_config[tags_key] = self._overall_tags
def _prepare_tags(self, tags):
- """
- Prepare tags format as needed in API methods:
- Filters=[{'Name': 'tag:KEY', 'Values': [VAL,...]}, ...]
- Keys AND values must be set for filtering.
- """
keys, values = tags
if keys and values:
return [{