Module: check_mk
Branch: master
Commit: 6ac25d857a834eb14c7efa42219948f4873777a0
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6ac25d857a834e…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Wed Dec 19 15:01:57 2018 +0100
aws_s3_summary: Add location information of each bucket
Change-Id: Idf7db4f3639c2919249bf51616547558f9cb52f7
---
agents/special/agent_aws | 14 ++++++++++----
checks/aws_s3_summary | 12 ++++++++++--
2 files changed, 20 insertions(+), 6 deletions(-)
diff --git a/agents/special/agent_aws b/agents/special/agent_aws
index a93be4a..d3fdb18 100755
--- a/agents/special/agent_aws
+++ b/agents/special/agent_aws
@@ -318,15 +318,21 @@ class S3Summary(AWSSection):
return 86400
def _get_raw_result(self):
- return self._client.list_buckets()
-
- def _extract_content_from(self, raw_result):
+ raw_result = self._client.list_buckets()
try:
- return raw_result['Buckets']
+ buckets = raw_result['Buckets']
except KeyError, e:
logging.info("%s: KeyError %s; Available are %s", self.name, e,
raw_result.keys())
return []
+ for entry in buckets:
+ response = self._client.get_bucket_location(Bucket=entry['Name'])
+ entry['LocationConstraint'] = response['LocationConstraint']
+ return buckets
+
+ def _extract_content_from(self, raw_result):
+ return raw_result
+
def _format_content(self, content):
return [AWSSectionResult("", content)]
diff --git a/checks/aws_s3_summary b/checks/aws_s3_summary
index 88e68fb..da00ea0 100644
--- a/checks/aws_s3_summary
+++ b/checks/aws_s3_summary
@@ -31,10 +31,18 @@ def inventory_aws_s3_summary(parsed):
def check_aws_s3_summary(item, params, parsed):
- yield 0, 'Buckets: %s' % len(parsed)
+ yield 0, '%s buckets' % len(parsed)
+ buckets_by_region = {}
+ for row in parsed:
+ buckets_by_region.setdefault(row['LocationConstraint'], []).append(row)
+
+ for region, buckets in buckets_by_region.iteritems():
+ yield 0, "%s buckets in region %s" % (len(buckets), region)
+
long_output = []
for row in parsed:
- long_output.append("Bucket: %s, Creation date: %s" %
(row['Name'], row['CreationDate']))
+ long_output.append("Bucket: %s, Region: %s, Creation date: %s"\
+ % (row['Name'], row['LocationConstraint'],
row['CreationDate']))
if long_output:
yield 0, '\n%s' % '\n'.join(long_output)