Module: check_mk
Branch: master
Commit: 13b41da4dcbf9b356f4a2ae15462e2dc3ec12300
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=13b41da4dcbf9b…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Tue Feb 19 13:26:50 2019 +0100
agent_aws: Unified ID in get_metric_data API call
Change-Id: I6024c44880f34194fd47ccf54bf4026451d6da2a
---
agents/special/agent_aws | 20 +++++++++++++++-----
checks/aws.include | 6 ++++--
2 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/agents/special/agent_aws b/agents/special/agent_aws
index ab8b456..54eeb90 100755
--- a/agents/special/agent_aws
+++ b/agents/special/agent_aws
@@ -345,6 +345,15 @@ class AWSSectionCloudwatch(AWSSection):
def _get_metrics(self, colleague_contents):
pass
+ def _create_id_for_metric_data_query(self, index, metric_name, *args):
+ """
+ ID field must be unique in a single call.
+ The valid characters are letters, numbers, and underscore.
+ The first character must be a lowercase letter.
+ Regex: ^[a-z][a-zA-Z0-9_]*$
+ """
+ return "_".join(["id", str(index)] + list(args) +
[metric_name])
+
#.
# .--costs/usage---------------------------------------------------------.
@@ -546,7 +555,7 @@ class EC2(AWSSectionCloudwatch):
("StatusCheckFailed_System", "Count"),
]:
metrics.append({
- 'Id': "%s_%s" % (metric_name.lower(), idx),
+ 'Id': self._create_id_for_metric_data_query(idx,
metric_name),
'Label': instance_name,
'MetricStat': {
'Metric': {
@@ -709,7 +718,8 @@ class S3(AWSSectionCloudwatch):
]:
for storage_class in storage_classes:
metrics.append({
- 'Id': "%s_%s_%s" % (metric_name.lower(),
storage_class.lower(), idx),
+ 'Id': self._create_id_for_metric_data_query(idx,
metric_name,
+ storage_class),
'Label': bucket_name,
'MetricStat': {
'Metric': {
@@ -905,7 +915,7 @@ class ELB(AWSSectionCloudwatch):
("BackendConnectionErrors", "Sum"),
]:
metrics.append({
- 'Id': "%s_%s" % (metric_name.lower(), idx),
+ 'Id': self._create_id_for_metric_data_query(idx,
metric_name),
'Label': load_balancer_dns_name,
'MetricStat': {
'Metric': {
@@ -1063,7 +1073,7 @@ class EBS(AWSSectionCloudwatch):
if volume_types and volume_type not in volume_types:
continue
metric = {
- 'Id': "%s_%s" % (metric_name.lower(), idx),
+ 'Id': self._create_id_for_metric_data_query(idx,
metric_name),
'Label': instance_name,
'MetricStat': {
'Metric': {
@@ -1197,7 +1207,7 @@ class RDS(AWSSectionCloudwatch):
#("MaximumUsedTransactionIDs", "Count"),
]:
metric = {
- 'Id': "%s_%s" % (metric_name.lower(), idx),
+ 'Id': self._create_id_for_metric_data_query(idx,
metric_name),
'Label': instance_id,
'MetricStat': {
'Metric': {
diff --git a/checks/aws.include b/checks/aws.include
index b20ea65..55af9da 100644
--- a/checks/aws.include
+++ b/checks/aws.include
@@ -80,11 +80,13 @@ def _extract_aws_metrics_by_labels(expected_metric_names, parsed,
extra_keys=Non
extra_keys = []
values_by_labels = {}
for row in parsed:
- row_id = row['Id']
+ row_id = row['Id'].lower()
row_label = row['Label']
row_values = row['Values']
for expected_metric_name in expected_metric_names:
- if not row_id.startswith(expected_metric_name.lower()):
+ expected_metric_name_lower = expected_metric_name.lower()
+ if not row_id.startswith(expected_metric_name_lower)\
+ and not row_id.startswith(expected_metric_name_lower):
continue
try: