Module: check_mk
Branch: master
Commit: 5853c36bac312a065c51b4b9e195e7d816501ba1
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5853c36bac312a…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Fri Dec 21 13:02:37 2018 +0100
agent_aws, aws.include, aws_ec2: Minor cleanup
Change-Id: I810781f8ef85f89152252121b9c3c14cb29f51ce
---
agents/special/agent_aws | 24 ++++++++++--------------
checks/aws.include | 19 +++++++++++++------
checks/aws_ec2 | 35 ++++++++++++++++++-----------------
3 files changed, 41 insertions(+), 37 deletions(-)
diff --git a/agents/special/agent_aws b/agents/special/agent_aws
index f9fd920..0ba90ec 100755
--- a/agents/special/agent_aws
+++ b/agents/special/agent_aws
@@ -216,7 +216,7 @@ class EC2Summary(AWSSection):
reservations = raw_result['Reservations']
except KeyError, e:
logging.info("%s: KeyError %s; Available are %s", self.name, e,
raw_result.keys())
- return []
+ return {}
return {
"Reservations": reservations,
"mapping": self._map_instance_id_to_name(reservations),
@@ -255,7 +255,7 @@ class EC2(AWSSection):
start_time = end_time - self.period
metrics = self._get_metrics()
if not metrics:
- return {}
+ return []
# A single GetMetricData call can include up to 100 MetricDataQuery structures
# There's no pagination for this operation:
@@ -278,11 +278,11 @@ class EC2(AWSSection):
return raw_result
def _get_metrics(self):
- instance_ids = self._received_results.get('ec2_summary', {})\
- .get('mapping', {}).values()
metrics = []
idx = 0
- for instance_id in instance_ids:
+ for instance_id, instance_name in\
+ self._received_results.get('ec2_summary', {})\
+ .get('mapping', {}).iteritems():
for metric_name, unit in [
("CPUCreditUsage", "Count"),
("CPUCreditBalance", "Count"),
@@ -298,7 +298,7 @@ class EC2(AWSSection):
]:
metrics.append({
'Id': "%s_%s" % (metric_name.lower(), idx),
- 'Label': instance_id,
+ 'Label': instance_name,
'MetricStat': {
'Metric': {
'Namespace': 'AWS/EC2',
@@ -473,7 +473,7 @@ class ELB(AWSSection):
start_time = end_time - self.period
metrics = self._get_metrics()
if not metrics:
- return {}
+ return []
# A single GetMetricData call can include up to 100 MetricDataQuery structures
# There's no pagination for this operation:
@@ -539,11 +539,7 @@ class ELB(AWSSection):
return metrics
def _extract_content_from(self, raw_result):
- try:
- return raw_result['MetricDataResults']
- except KeyError, e:
- logging.info("%s: KeyError %s; Available are %s", self.name, e,
raw_result.keys())
- return []
+ return raw_result
def _format_content(self, content):
content_by_piggyback_hosts = {}
@@ -633,7 +629,7 @@ class EBS(AWSSection):
start_time = end_time - self.period
metrics = self._get_metrics()
if not metrics:
- return {}
+ return []
# A single GetMetricData call can include up to 100 MetricDataQuery structures
# There's no pagination for this operation:
@@ -822,8 +818,8 @@ class AWSSections(object):
#---sections--------------------------------------------------------
s3 = S3(s3_client)
- ec2 = EC2(cloudwatch_client)
elb_health = ELBHealth(elb_client)
+ ec2 = EC2(cloudwatch_client)
elb = ELB(cloudwatch_client)
ebs = EBS(cloudwatch_client)
diff --git a/checks/aws.include b/checks/aws.include
index 980d411..1e495ff 100644
--- a/checks/aws.include
+++ b/checks/aws.include
@@ -52,11 +52,18 @@ def _extract_aws_metrics(expected_metric_names, parsed):
def _extract_aws_metrics_by_labels(expected_metric_names, parsed):
values_by_labels = {}
for row in parsed:
+ row_id = row['Id']
+ row_label = row['Label']
+ row_values = row['Values']
for expected_metric_name in expected_metric_names:
- if row['Id'].startswith(expected_metric_name.lower()):
- try:
- values_by_labels.setdefault(row['Label'], {})\
- .setdefault(expected_metric_name,
row['Values'][0])
- except IndexError:
- pass
+ if not row_id.startswith(expected_metric_name.lower()):
+ continue
+
+ try:
+ value = row_values[0]
+ except IndexError:
+ continue
+ else:
+ values_by_labels.setdefault(row_label, {})\
+ .setdefault(expected_metric_name, value)
return values_by_labels
diff --git a/checks/aws_ec2 b/checks/aws_ec2
index 79d66df..14105c5 100644
--- a/checks/aws_ec2
+++ b/checks/aws_ec2
@@ -24,26 +24,27 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
+EC2DefaultItemName = "DEFAULT"
-def parse_aws_ec2(info):
- return {
- EC2DefaultItemName: _extract_aws_metrics([
- 'StatusCheckFailed_Instance',
- 'StatusCheckFailed_System',
- 'CPUCreditUsage',
- 'CPUCreditBalance',
- 'CPUUtilization',
- 'DiskReadOps',
- 'DiskWriteOps',
- 'DiskReadBytes',
- 'DiskWriteBytes',
- 'NetworkIn',
- 'NetworkOut',
- ], parse_aws(info)),
- }
+def parse_aws_ec2(info):
+ metrics = _extract_aws_metrics([
+ 'StatusCheckFailed_Instance',
+ 'StatusCheckFailed_System',
+ 'CPUCreditUsage',
+ 'CPUCreditBalance',
+ 'CPUUtilization',
+ 'DiskReadOps',
+ 'DiskWriteOps',
+ 'DiskReadBytes',
+ 'DiskWriteBytes',
+ 'NetworkIn',
+ 'NetworkOut',
+ ], parse_aws(info))
+ if metrics:
+ return {EC2DefaultItemName: metrics}
+ return
-EC2DefaultItemName = "DEFAULT"
# .--status check--------------------------------------------------------.
# | _ _ _ _ |