Module: check_mk
Branch: master
Commit: 6e2607d95ed68b0810c747ccbb5359fb7652dc96
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6e2607d95ed68b…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Fri Dec 21 11:57:39 2018 +0100
agent_aws: Refactored EBS; merged summary and health sections
Change-Id: I6386775a94f42bacefe973709f0cc4df5073e94a
---
agents/special/agent_aws | 68 ++++++----------------
.../{aws_ebs_health => aws_ebs_summary.health} | 0
checks/aws_ebs_health | 46 ---------------
checks/aws_ebs_summary | 39 +++++++++++--
4 files changed, 54 insertions(+), 99 deletions(-)
diff --git a/agents/special/agent_aws b/agents/special/agent_aws
index e8a1a9b..f9fd920 100755
--- a/agents/special/agent_aws
+++ b/agents/special/agent_aws
@@ -579,66 +579,40 @@ class EBSSummary(AWSSection):
return 300
def _get_raw_result(self):
- return self._client.describe_volumes()
-
- def _extract_content_from(self, raw_result):
+ response = self._client.describe_volumes()
try:
- return raw_result['Volumes']
+ volumes = {r['VolumeId']: r for r in response['Volumes']}
except KeyError, e:
- logging.info("%s: KeyError %s; Available are %s", self.name, e,
raw_result.keys())
- return []
-
- def _format_content(self, content):
- instance_ids = self._received_results.get('ec2_summary', {})\
- .get('mapping', {})
- content_by_piggyback_hosts = {}
- for row in content:
- for attachment in row['Attachments']:
- attachment_id = attachment['InstanceId']
- instance_name = instance_ids.get(attachment_id, attachment_id)
- content_by_piggyback_hosts.setdefault(instance_name, [])\
- .append(row)
- return [
- AWSSectionResult(piggyback_hostname, rows)
- for piggyback_hostname, rows in content_by_piggyback_hosts.iteritems()
- ]
-
-
-class EBSHealth(AWSSection):
- @property
- def name(self):
- return "ebs_health"
+ logging.info("%s: KeyError %s; Available are %s", self.name, e,
response.keys())
+ volumes = []
- @property
- def interval(self):
- return 300
+ response = self._client.describe_volume_status()
+ try:
+ volume_states = {r['VolumeId']: r for r in
response['VolumeStatuses']}
+ except KeyError, e:
+ logging.info("%s: KeyError %s; Available are %s", self.name, e,
response.keys())
+ volume_states = []
- def _get_raw_result(self):
- volumes = []
- for entry in self._received_results.get('ebs_summary', []):
- volumes.append(entry['VolumeId'])
- return self._client.describe_volume_status(VolumeIds=volumes)
+ raw_result = []
+ for volume_id in set(volumes.keys()).union(set(volume_states.keys())):
+ volume = volumes.get(volume_id, {})
+ volume.update(volume_states.get(volume_id, {}))
+ raw_result.append(volume)
+ return raw_result
def _extract_content_from(self, raw_result):
- content = {}
- for row in raw_result.get('VolumeStatuses', []):
- try:
- content.setdefault(row['VolumeId'], row['VolumeStatus'])
- except KeyError, e:
- logging.info("%s: KeyError %s; Available are %s", self.name, e,
row.keys())
- return content
+ return raw_result
def _format_content(self, content):
instance_ids = self._received_results.get('ec2_summary', {})\
.get('mapping', {})
content_by_piggyback_hosts = {}
- for row in self._received_results.get('ebs_summary', []):
- vol_id = row['VolumeId']
+ for row in content:
for attachment in row['Attachments']:
attachment_id = attachment['InstanceId']
instance_name = instance_ids.get(attachment_id, attachment_id)
content_by_piggyback_hosts.setdefault(instance_name, [])\
- .append({vol_id: content[vol_id]})
+ .append(row)
return [
AWSSectionResult(piggyback_hostname, rows)
for piggyback_hostname, rows in content_by_piggyback_hosts.iteritems()
@@ -851,17 +825,14 @@ class AWSSections(object):
ec2 = EC2(cloudwatch_client)
elb_health = ELBHealth(elb_client)
elb = ELB(cloudwatch_client)
- ebs_health = EBSHealth(ec2_client)
ebs = EBS(cloudwatch_client)
#---register sections to distributors-------------------------------
ec2_summary_distributor.add(ec2)
ec2_summary_distributor.add(ebs_summary)
- ec2_summary_distributor.add(ebs_health)
ec2_summary_distributor.add(ebs)
elb_summary_distributor.add(elb_health)
elb_summary_distributor.add(elb)
- ebs_summary_distributor.add(ebs_health)
ebs_summary_distributor.add(ebs)
#---register sections with distributors for execution---------------
@@ -874,7 +845,6 @@ class AWSSections(object):
self._sections.append(s3)
self._sections.append(elb_health)
self._sections.append(elb)
- self._sections.append(ebs_health)
self._sections.append(ebs)
def _init_client(self, client_key):
diff --git a/checkman/aws_ebs_health b/checkman/aws_ebs_summary.health
similarity index 100%
rename from checkman/aws_ebs_health
rename to checkman/aws_ebs_summary.health
diff --git a/checks/aws_ebs_health b/checks/aws_ebs_health
deleted file mode 100644
index 37d2a0d..0000000
--- a/checks/aws_ebs_health
+++ /dev/null
@@ -1,46 +0,0 @@
-#!/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_health(info):
- return {k: v for row in parse_aws(info) for k, v in row.iteritems()}
-
-
-@get_parsed_item_data
-def check_aws_ebs_health(item, params, metrics):
- ebs_status = metrics["Status"]
- yield 0 if ebs_status.lower() == 'ok' else 2, "Status: %s" %
ebs_status
- for row in metrics['Details']:
- yield 0, "%s: %s" % (row['Name'], row['Status'])
-
-
-check_info['aws_ebs_health'] = {
- 'parse_function': parse_aws_health,
- 'inventory_function': discover(),
- 'check_function': check_aws_ebs_health,
- 'service_description': 'AWS/EBS Health %s',
- 'includes': ['aws.include'],
-}
diff --git a/checks/aws_ebs_summary b/checks/aws_ebs_summary
index ea818e4..09de4f6 100644
--- a/checks/aws_ebs_summary
+++ b/checks/aws_ebs_summary
@@ -41,9 +41,14 @@ def parse_aws_summary(info):
return parsed
-def inventory_aws_ebs_summary(parsed):
- if parsed:
- return [(None, {})]
+# .--summary-------------------------------------------------------------.
+# | |
+# | ___ _ _ _ __ ___ _ __ ___ __ _ _ __ _ _ |
+# | / __| | | | '_ ` _ \| '_ ` _ \ / _` | '__| | | | |
+# | \__ \ |_| | | | | | | | | | | | (_| | | | |_| | |
+# | |___/\__,_|_| |_| |_|_| |_| |_|\__,_|_| \__, | |
+# | |___/ |
+# '----------------------------------------------------------------------'
def check_aws_ebs_summary(item, params, parsed):
@@ -69,8 +74,34 @@ def check_aws_ebs_summary(item, params, parsed):
check_info['aws_ebs_summary'] = {
'parse_function': parse_aws_summary,
- 'inventory_function': inventory_aws_ebs_summary,
+ 'inventory_function': discover_single,
'check_function': check_aws_ebs_summary,
'service_description': 'AWS/EBS Summary',
'includes': ['aws.include'],
}
+
+#.
+# .--health--------------------------------------------------------------.
+# | _ _ _ _ |
+# | | |__ ___ __ _| | |_| |__ |
+# | | '_ \ / _ \/ _` | | __| '_ \ |
+# | | | | | __/ (_| | | |_| | | | |
+# | |_| |_|\___|\__,_|_|\__|_| |_| |
+# | |
+# '----------------------------------------------------------------------'
+
+
+@get_parsed_item_data
+def check_aws_ebs_summary_health(item, params, ebs_data):
+ metrics = ebs_data['VolumeStatus']
+ ebs_status = metrics["Status"]
+ yield 0 if ebs_status.lower() == 'ok' else 2, "Status: %s" %
ebs_status
+ for row in metrics['Details']:
+ yield 0, "%s: %s" % (row['Name'], row['Status'])
+
+
+check_info['aws_ebs_summary.health'] = {
+ 'inventory_function': discover(),
+ 'check_function': check_aws_ebs_summary_health,
+ 'service_description': 'AWS/EBS Health %s',
+}