Module: check_mk
Branch: master
Commit: 79066a31eb48fc7e127eab4392b3746019c9d04e
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=79066a31eb48fc…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Wed Jan 30 16:59:19 2019 +0100
aws_s3: Monitor S3 objects in an own check plugin
Change-Id: Ic66ad30ef79a08b5d12ae862f1514f843ab8b259
---
agents/special/agent_aws | 4 +--
checkman/{aws_s3_summary.objects => aws_s3} | 0
checks/aws_s3 | 56 +++++++++++++++++++++++++++++
checks/aws_s3_summary | 51 ++------------------------
4 files changed, 60 insertions(+), 51 deletions(-)
diff --git a/agents/special/agent_aws b/agents/special/agent_aws
index d93fb7a..495d7f1 100755
--- a/agents/special/agent_aws
+++ b/agents/special/agent_aws
@@ -1292,7 +1292,7 @@ def main(args=None):
try:
session = create_session(access_key_id, secret_access_key,
"us-east-1")
aws_sections_us_east = AWSSectionsUSEast(hostname, session, services)
- aws_sections_us_east.init_sections(buckets=args.buckets)
+ aws_sections_us_east.init_sections()
aws_sections_us_east.run(use_cache=use_cache)
except Exception as e:
if args.debug:
@@ -1303,7 +1303,7 @@ def main(args=None):
try:
session = create_session(access_key_id, secret_access_key, region)
aws_sections = AWSSectionsGeneric(hostname, session, services)
- aws_sections.init_sections(region=region)
+ aws_sections.init_sections(buckets=args.buckets, region=region)
aws_sections.run(use_cache=use_cache)
except Exception as e:
if args.debug:
diff --git a/checkman/aws_s3_summary.objects b/checkman/aws_s3
similarity index 100%
rename from checkman/aws_s3_summary.objects
rename to checkman/aws_s3
diff --git a/checks/aws_s3 b/checks/aws_s3
new file mode 100644
index 0000000..3c66361
--- /dev/null
+++ b/checks/aws_s3
@@ -0,0 +1,56 @@
+#!/usr/bin/python
+# -*- encoding: utf-8; py-indent-offset: 4 -*-
+# +------------------------------------------------------------------+
+# | ____ _ _ __ __ _ __ |
+# | / ___| |__ ___ ___| | __ | \/ | |/ / |
+# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
+# | | |___| | | | __/ (__| < | | | | . \ |
+# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
+# | |
+# | Copyright Mathias Kettner 2018 mk(a)mathias-kettner.de |
+# +------------------------------------------------------------------+
+#
+# This file is part of Check_MK.
+# The official homepage is at
http://mathias-kettner.de/check_mk.
+#
+# check_mk is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation in version 2. check_mk is distributed
+# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
+# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE. See the GNU General Public License for more de-
+# tails. You should have received a copy of the GNU General Public
+# License along with GNU Make; see the file COPYING. If not, write
+# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+# Boston, MA 02110-1301 USA.
+
+
+def parse_aws_s3(info):
+ parsed = {}
+ for row in parse_aws(info):
+ splitted_row = row['Id'].split("_")
+ inst = parsed.setdefault(row['Label'], {}).setdefault(splitted_row[0],
{})
+ try:
+ inst.setdefault(splitted_row[1], row['Values'][0])
+ except (IndexError, ValueError):
+ pass
+ return parsed
+
+
+@get_parsed_item_data
+def check_aws_s3(item, params, metrics):
+ sum_size = sum(metrics['bucketsizebytes'].values())
+ yield 0, 'Bucket size: %s' % get_bytes_human_readable(sum_size),
[('bucket_size', sum_size)]
+
+ num_objects = sum(metrics['numberofobjects'].values())
+ yield 0, 'Number of objects: %s' % int(num_objects), [('num_objects',
num_objects)]
+
+
+check_info['aws_s3'] = {
+ 'parse_function': parse_aws_s3,
+ 'inventory_function': discover(),
+ 'check_function': check_aws_s3,
+ 'service_description': 'AWS/S3 Objects %s',
+ 'has_perfdata': True,
+ 'includes': ['aws.include'],
+}
diff --git a/checks/aws_s3_summary b/checks/aws_s3_summary
index 330f1b9..91c7d48 100644
--- a/checks/aws_s3_summary
+++ b/checks/aws_s3_summary
@@ -25,7 +25,7 @@
# Boston, MA 02110-1301 USA.
-def parse_aws_s3(info):
+def parse_aws_s3_summary(info):
parsed = {}
for row in parse_aws(info):
parsed.setdefault(row['Name'], row)
@@ -38,16 +38,6 @@ def _extract_aws_s3_tags(metrics):
["%s: %s" % (pair['Key'], pair['Value']) for pair in
metrics.get('Tagging', [])])
-# .--summary-------------------------------------------------------------.
-# | |
-# | ___ _ _ _ __ ___ _ __ ___ __ _ _ __ _ _ |
-# | / __| | | | '_ ` _ \| '_ ` _ \ / _` | '__| | | | |
-# | \__ \ |_| | | | | | | | | | | | (_| | | | |_| | |
-# | |___/\__,_|_| |_| |_|_| |_| |_|\__,_|_| \__, | |
-# | |___/ |
-# '----------------------------------------------------------------------'
-
-
def check_aws_s3_summary(item, params, parsed):
yield 0, '%s buckets' % len(parsed)
buckets_by_region = {}
@@ -73,46 +63,9 @@ def check_aws_s3_summary(item, params, parsed):
check_info['aws_s3_summary'] = {
- 'parse_function': parse_aws_s3,
+ 'parse_function': parse_aws_s3_summary,
'inventory_function': discover_single,
'check_function': check_aws_s3_summary,
'service_description': 'AWS/S3 Summary',
'includes': ['aws.include'],
}
-
-#.
-# .--objects-------------------------------------------------------------.
-# | _ _ _ |
-# | ___ | |__ (_) ___ ___| |_ ___ |
-# | / _ \| '_ \| |/ _ \/ __| __/ __| |
-# | | (_) | |_) | | __/ (__| |_\__ \ |
-# | \___/|_.__// |\___|\___|\__|___/ |
-# | |__/ |
-# '----------------------------------------------------------------------'
-
-
-@get_parsed_item_data
-def check_aws_s3_summary_objects(item, params, metrics):
- sum_size = 0
- num_objects = 0
- largest = None
- largest_size = 0
- for row in metrics.get('Contents', []):
- size = row['Size']
- sum_size += row['Size']
- num_objects += 1
- if size >= largest_size:
- largest = row['Key']
- largest_size = size
- yield 0, 'Bucket size: %s' % get_bytes_human_readable(sum_size),
[('bucket_size', sum_size)]
- yield 0, 'Number of objects: %s' % num_objects, [('num_objects',
num_objects)]
- if largest:
- yield 0, 'Largest object: %s, %s' % (largest,
get_bytes_human_readable(largest_size))
-
-
-check_info['aws_s3_summary.objects'] = {
- 'inventory_function': discover(),
- 'check_function': check_aws_s3_summary_objects,
- 'service_description': 'AWS/S3 Objects %s',
- 'has_perfdata': True,
-}