Module: check_mk
Branch: master
Commit: ef28290c2d3deec193cf1da87d0e8f4a35f13e22
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ef28290c2d3deeā¦
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Wed Nov 28 15:41:25 2018 +0100
6820 aws_ec2_instances_summary: New check which gives an overview of AWS/EC2 instances
Change-Id: If248c2d6a89d5e820a95cdaab9a8d20893877172
---
.werks/6820 | 10 +++++++
agents/special/agent_aws | 10 +++++--
checkman/aws_ec2_instances_summary | 14 +++++++++
checks/aws.include | 33 +++++++++++++++++++++
checks/aws_ec2_instances_summary | 61 ++++++++++++++++++++++++++++++++++++++
5 files changed, 125 insertions(+), 3 deletions(-)
diff --git a/.werks/6820 b/.werks/6820
new file mode 100644
index 0000000..5b63f91
--- /dev/null
+++ b/.werks/6820
@@ -0,0 +1,10 @@
+Title: aws_ec2_instances_summary: New check which gives an overview of AWS/EC2 instances
+Level: 1
+Component: checks
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1543416042
+Class: feature
+
+
diff --git a/agents/special/agent_aws b/agents/special/agent_aws
index 29892e1..af9a8de 100755
--- a/agents/special/agent_aws
+++ b/agents/special/agent_aws
@@ -172,13 +172,17 @@ class EC2InstancesSummary(AWSSection):
return "ec2_instances_summary"
def _get_raw_result(self):
- pass
+ return self._client.describe_instances()
def _extract_content_from(self, raw_result):
- pass
+ try:
+ return raw_result['Reservations']
+ except KeyError, e:
+ logging.info(e)
+ return
def _format_content(self, content):
- pass
+ return [AWSSectionResult("", content)]
class EC2Instance(AWSSection):
diff --git a/checkman/aws_ec2_instances_summary b/checkman/aws_ec2_instances_summary
new file mode 100644
index 0000000..d935fce
--- /dev/null
+++ b/checkman/aws_ec2_instances_summary
@@ -0,0 +1,14 @@
+title: AWS EC2 Instances Summary
+agents: aws
+catalog: applications
+license: GPL
+distribution: check_mk
+description:
+ This check monitors all AWS EC2 instances and reports
+ a summary of their states.
+
+ If at least one instance is not running the state is WARN
+ otherwise it is OK.
+
+inventory:
+ One summary service is created.
diff --git a/checks/aws.include b/checks/aws.include
new file mode 100644
index 0000000..6792aec
--- /dev/null
+++ b/checks/aws.include
@@ -0,0 +1,33 @@
+#!/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(info):
+ import json
+ try:
+ return json.loads("".join(info[0]))
+ except (TypeError, IndexError):
+ return
diff --git a/checks/aws_ec2_instances_summary b/checks/aws_ec2_instances_summary
new file mode 100644
index 0000000..50637fe
--- /dev/null
+++ b/checks/aws_ec2_instances_summary
@@ -0,0 +1,61 @@
+#!/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 inventory_aws_ec2_instances_summary(parsed):
+ if parsed:
+ return [(None, {})]
+
+
+def check_aws_ec2_instances_summary(item, params, parsed):
+ instances_by_state = {}
+ for reservation in parsed:
+ for instance in reservation['Instances']:
+ instances_by_state.setdefault(instance['State']['Name'],
[])\
+ .append(instance['InstanceId'])
+
+ yield 0, "Instances: %s" % sum([len(v) for v in
instances_by_state.itervalues()])
+
+ long_output = []
+ for instance_state, instances in instances_by_state.iteritems():
+ if instance_state == 'running':
+ state = 0
+ else:
+ state = 1
+ long_output.append("%s: %s" % (instance_state, ",
".join(instances)))
+ yield state, "%s: %s" % (instance_state, len(instances))
+
+ if long_output:
+ yield 0, "\n%s" % "\n".join(long_output)
+
+
+check_info['aws_ec2_instances_summary'] = {
+ 'parse_function': parse_aws,
+ 'inventory_function': inventory_aws_ec2_instances_summary,
+ 'check_function': check_aws_ec2_instances_summary,
+ 'service_description': 'AWS EC2 Instances',
+ 'includes': ['aws.include'],
+}