Module: check_mk
Branch: master
Commit: 133534b2a478798261b3e68c71ad76a0d7efd744
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=133534b2a47879…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Wed Feb 13 10:27:23 2019 +0100
agent_aws: Reordered configuration of services, use DNSName for load balancers and fixed
some blemishes
Change-Id: Ibb23fb8a560a98b20d60867c90f3ad0fd7b55b85
---
agents/special/agent_aws | 27 ++++++++++++++++-----------
checks/agent_aws | 6 ++++--
checks/aws_ec2 | 2 +-
checks/aws_s3 | 7 +++++--
cmk/gui/plugins/wato/check_parameters/aws.py | 4 ++--
cmk/gui/plugins/wato/datasource_programs.py | 22 ++++++++++++----------
6 files changed, 40 insertions(+), 28 deletions(-)
diff --git a/agents/special/agent_aws b/agents/special/agent_aws
index d68c489..e4cdfca 100755
--- a/agents/special/agent_aws
+++ b/agents/special/agent_aws
@@ -450,8 +450,10 @@ class EC2Summary(AWSSectionGeneric):
return self._client.describe_instances()
def _compute_content(self, raw_content, colleague_contents):
+ # PrivateIpAddress and InstanceId is available although the instance is stopped
return AWSComputedContent({
- instance["PrivateDnsName"]: instance for reservation in
raw_content.content
+ "%s-%s-%s" % (instance['PrivateIpAddress'], self._region,
instance['InstanceId']):
+ instance for reservation in raw_content.content
for instance in reservation.get('Instances', [])
}, raw_content.cache_timestamp)
@@ -784,18 +786,20 @@ class ELBSummary(AWSSectionGeneric):
found_load_balancers = []
for load_balancer in self._describe_load_balancers():
load_balancer_name = load_balancer['LoadBalancerName']
- tag_descrs = []
+ tagging = []
try:
response =
self._client.describe_tags(LoadBalancerNames=[load_balancer_name])
- tag_descrs = response['TagDescriptions']
+ tagging = [
+ tag for tag_descr in response['TagDescriptions'] for tag in
tag_descr['Tags']
+ ]
except botocore.exceptions.ClientError as e:
# If there are no tags attached to a bucket we receive a
'ClientError'
logging.info("%s/%s: No tags set, %s", self.name,
load_balancer_name, e)
except KeyError as e:
logging.info("%s/%s: KeyError %s; Available are %s", self.name,
load_balancer_name,
e, response.keys())
- if self._matches_conditions(tag_descrs):
- load_balancer['TagDescriptions'] = tag_descrs
+ if self._matches_conditions(tagging):
+ load_balancer['TagDescriptions'] = tagging
found_load_balancers.append(load_balancer)
return found_load_balancers
@@ -823,7 +827,7 @@ class ELBSummary(AWSSectionGeneric):
def _compute_content(self, raw_content, colleague_contents):
content_by_piggyback_hosts = {}
for load_balancer in raw_content.content:
-
content_by_piggyback_hosts.setdefault(load_balancer['LoadBalancerName'],
load_balancer)
+ content_by_piggyback_hosts.setdefault(load_balancer['DNSName'],
load_balancer)
return AWSComputedContent(content_by_piggyback_hosts,
raw_content.cache_timestamp)
def _create_results(self, computed_content):
@@ -847,7 +851,8 @@ class ELBHealth(AWSSectionGeneric):
def _fetch_raw_content(self, colleague_contents):
load_balancers = {}
- for load_balancer_name in colleague_contents.content.iterkeys():
+ for load_balancer_dns_name, load_balancer in
colleague_contents.content.iteritems():
+ load_balancer_name = load_balancer['LoadBalancerName']
response =
self._client.describe_instance_health(LoadBalancerName=load_balancer_name)
try:
states = response['InstanceStates']
@@ -855,7 +860,7 @@ class ELBHealth(AWSSectionGeneric):
logging.info("%s/%s: KeyError %s; Available are %s", self.name,
load_balancer_name,
e, response.keys())
else:
- load_balancers.setdefault(load_balancer_name, states)
+ load_balancers.setdefault(load_balancer_dns_name, states)
return load_balancers
def _compute_content(self, raw_content, colleague_contents):
@@ -886,7 +891,8 @@ class ELB(AWSSectionCloudwatch):
def _get_metrics(self, colleague_contents):
metrics = []
idx = 0
- for load_balancer_name in colleague_contents.content.iterkeys():
+ for load_balancer_dns_name, load_balancer in
colleague_contents.content.iteritems():
+ load_balancer_name = load_balancer['LoadBalancerName']
for metric_name, stat in [
("RequestCount", "Sum"),
("SurgeQueueLength", "Maximum"),
@@ -904,7 +910,7 @@ class ELB(AWSSectionCloudwatch):
]:
metrics.append({
'Id': "%s_%s" % (metric_name.lower(), idx),
- 'Label': load_balancer_name,
+ 'Label': load_balancer_dns_name,
'MetricStat': {
'Metric': {
'Namespace': 'AWS/ELB',
@@ -1368,7 +1374,6 @@ def parse_arguments(argv):
parser.add_argument(
"--regions",
nargs='+',
- required=True,
help="Regions to use:\n%s" % "\n".join(["%-15s %s"
% e for e in AWSRegions]))
parser.add_argument(
diff --git a/checks/agent_aws b/checks/agent_aws
index 0ee1b79..e641e42 100644
--- a/checks/agent_aws
+++ b/checks/agent_aws
@@ -71,8 +71,10 @@ def agent_aws_arguments(params, hostname, ipaddress):
"--secret-access-key",
passwordstore_get_cmdline("%s",
params["secret_access_key"]),
]
- args.append("--regions")
- args += params["regions"]
+ regions = params.get("regions")
+ if regions:
+ args.append("--regions")
+ args += regions
global_services = params.get("global_services", {})
if global_services:
diff --git a/checks/aws_ec2 b/checks/aws_ec2
index f9e8e92..6c405ee 100644
--- a/checks/aws_ec2
+++ b/checks/aws_ec2
@@ -24,7 +24,7 @@
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
-EC2DefaultItemName = "DEFAULT"
+EC2DefaultItemName = "Summary"
def parse_aws_ec2(info):
diff --git a/checks/aws_s3 b/checks/aws_s3
index 9e84e2f..fc032a1 100644
--- a/checks/aws_s3
+++ b/checks/aws_s3
@@ -70,8 +70,11 @@ def check_aws_s3_objects(item, params, metrics):
storage_infos.append(
"%s: %s" % (aws_s3_storage_mapping[storage_type],
get_bytes_human_readable(value)))
sum_size = sum(bucket_sizes.values())
- yield (0,
- 'Bucket size: %s (%s)' % (get_bytes_human_readable(sum_size), ",
".join(storage_infos)),
+ if storage_infos:
+ storage_infos_str = " (%s)" % ", ".join(storage_infos)
+ else:
+ storage_infos_str = ""
+ yield (0, 'Bucket size: %s%s' % (get_bytes_human_readable(sum_size),
storage_infos_str),
[('aws_bucket_size', sum_size)])
num_objects = sum(metrics['numberofobjects'].values())
diff --git a/cmk/gui/plugins/wato/check_parameters/aws.py
b/cmk/gui/plugins/wato/check_parameters/aws.py
index 0d4a238..8564d92 100644
--- a/cmk/gui/plugins/wato/check_parameters/aws.py
+++ b/cmk/gui/plugins/wato/check_parameters/aws.py
@@ -111,8 +111,8 @@ class
RulespecCheckgroupParametersAwsCostsAndUsage(CheckParameterRulespecWithout
Tuple(
title=_("Upper levels for unblended costs"),
elements=[
- Integer(title=_("Warning at")),
- Integer(title=_("Critical at")),
+ Integer(title=_("Warning at"), unit=_("USD per
day")),
+ Integer(title=_("Critical at"), unit=_("USD per
day")),
],
),
)],)
diff --git a/cmk/gui/plugins/wato/datasource_programs.py
b/cmk/gui/plugins/wato/datasource_programs.py
index e5c9bae..ddd5d44 100644
--- a/cmk/gui/plugins/wato/datasource_programs.py
+++ b/cmk/gui/plugins/wato/datasource_programs.py
@@ -1890,12 +1890,24 @@ class RulespecSpecialAgentsAws(HostRulespec):
TextAscii(
title=_("The access key for your AWS account"),
allow_empty=False,
+ size=50,
)),
("secret_access_key",
IndividualOrStoredPassword(
title=_("The secret key for your AWS account"),
allow_empty=False,
)),
+ ("global_services",
+ Dictionary(
+ title=_("Global services to monitor"),
+ elements=[
+ ("ce",
+ FixedValue(
+ None,
+ totext=_("Monitor costs and usage"),
+ title=_("Costs and usage (CE)"))),
+ ],
+ )),
("regions",
ListChoice(
title=_("Regions to use"),
@@ -1922,16 +1934,6 @@ class RulespecSpecialAgentsAws(HostRulespec):
],
key=lambda x: x[1]),
)),
- ("global_services",
- Dictionary(
- title=_("Global services to monitor"),
- elements=[
- ("ce",
- FixedValue(
- None, totext=_("Monitor costs and usage"),
- title=_("Costs and usage"))),
- ],
- )),
("services",
Dictionary(
title=_("Services per region to monitor"),