Module: check_mk
Branch: master
Commit: 4e8666bed3f810c1e04b4950b2491e488a4a1481
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4e8666bed3f810…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Mon Jan 28 13:08:21 2019 +0100
aws_s3_summary: Add tagging information to long output
Change-Id: I95d6c6bec9c80ddd7fedfb4f42c0f69a8427b20f
---
checks/aws.include | 22 ++++++++++++++++++++++
checks/aws_ec2_summary | 23 ++++++++++++++++++++++-
checks/aws_s3_summary | 16 ++++++++++++++--
3 files changed, 58 insertions(+), 3 deletions(-)
diff --git a/checks/aws.include b/checks/aws.include
index 1e495ff..117375d 100644
--- a/checks/aws.include
+++ b/checks/aws.include
@@ -24,6 +24,28 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
+AWSRegions = {
+ "ap-south-1": "Asia Pacific Mumbai",
+ "ap-northeast-3": "Asia Pacific Osaka-Local",
+ "ap-northeast-2": "Asia Pacific Seoul",
+ "ap-southeast-1": "Asia Pacific Singapore",
+ "ap-southeast-2": "Asia Pacific Sydney",
+ "ap-northeast-1": "Asia Pacific Tokyo",
+ "ca-central-1": "Canada Central",
+ "cn-north-1": "China Beijing",
+ "cn-northwest-1": "China Ningxia",
+ "eu-central-1": "EU Frankfurt",
+ "eu-west-1": "EU Ireland",
+ "eu-west-2": "EU London",
+ "eu-west-3": "EU Paris",
+ "eu-north-1": "EU Stockholm",
+ "sa-east-1": "South America Sao Paulo",
+ "us-east-2": "US East Ohio",
+ "us-east-1": "US East N. Virginia",
+ "us-west-1": "US West N. California",
+ "us-west-2": "US West Oregon",
+}
+
def parse_aws(info):
import json
diff --git a/checks/aws_ec2_summary b/checks/aws_ec2_summary
index b97ea7b..62c0b0c 100644
--- a/checks/aws_ec2_summary
+++ b/checks/aws_ec2_summary
@@ -30,6 +30,19 @@ def inventory_aws_ec2_summary(parsed):
return [(None, {})]
+def _extract_aws_ec2_security_groups(metrics):
+ # metrics is dict with key 'SecurityGroups'
+ return ", ".join([
+ "%s: %s" % (pair['GroupId'], pair['GroupName'])
+ for pair in metrics.get('SecurityGroups', [])
+ ])
+
+
+def _extract_aws_ec2_tags(metrics):
+ # metrics is dict with key 'Tags'
+ return ", ".join(["%s: %s" % (pair['Key'],
pair['Value']) for pair in metrics.get('Tags', [])])
+
+
def check_aws_ec2_summary(item, params, parsed):
instances_by_state = {}
long_output = []
@@ -38,7 +51,15 @@ def check_aws_ec2_summary(item, params, parsed):
instance_id = instance['InstanceId']
instance_state = instance['State']['Name']
instances_by_state.setdefault(instance_state, []).append(instance_id)
- long_output.append("Instance: %s, Status: %s" % (instance_id,
instance_state))
+
+ long_output_info = ["Instance: %s, Status: %s" % (instance_id,
instance_state)]
+ security_groups = _extract_aws_ec2_security_groups(instance)
+ if security_groups:
+ long_output_info.append("[Security groups] %s" %
security_groups)
+ tags = _extract_aws_ec2_tags(instance)
+ if tags:
+ long_output_info.append("[Tags] %s" % tags)
+ long_output.append(", ".join(long_output_info))
yield 0, "Instances: %s" % sum([len(v) for v in
instances_by_state.itervalues()])
for instance_state, instances in instances_by_state.iteritems():
diff --git a/checks/aws_s3_summary b/checks/aws_s3_summary
index 48ddc66..93c5d8a 100644
--- a/checks/aws_s3_summary
+++ b/checks/aws_s3_summary
@@ -32,6 +32,12 @@ def parse_aws_s3(info):
return parsed
+def _extract_aws_s3_tags(metrics):
+ # metrics is dict with key 'Tagging'
+ return ", ".join(
+ ["%s: %s" % (pair['Key'], pair['Value']) for pair in
metrics.get('Tagging', [])])
+
+
# .--summary-------------------------------------------------------------.
# | |
# | ___ _ _ _ __ ___ _ __ ___ __ _ _ __ _ _ |
@@ -50,11 +56,17 @@ def check_aws_s3_summary(item, params, parsed):
region = row['LocationConstraint']
if not region:
region = "unknown"
+
buckets_by_region.setdefault(region, []).append(row)
- long_output.append("Bucket: %s, Region: %s" % (bucket_name, region))
+ long_output_info = ["Bucket: %s, Region: %s" % (bucket_name, region)]
+ tags = _extract_aws_s3_tags(row)
+ if tags:
+ long_output_info.append("[Tags] %s" % tags)
+ long_output.append(", ".join(long_output_info))
for region, buckets in buckets_by_region.iteritems():
- yield 0, "%s: %s" % (region, len(buckets))
+ region_readable = AWSRegions.get(region, 'unknown[%s]' % region)
+ yield 0, "%s: %s" % (region_readable, len(buckets))
if long_output:
yield 0, '\n%s' % '\n'.join(long_output)