Module: check_mk
Branch: master
Commit: f67a2d22e67ce33a538897d7930f536127b16f27
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=f67a2d22e67ce3…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Mon Jan 28 08:40:24 2019 +0100
agent_aws: Refactored WATO configuration which is more flexible
Change-Id: Ibed9164c00b3505e8f8b28641e3dafce8ebbf7ca
---
agents/special/agent_aws | 2 +-
checks/agent_aws | 10 ++++++++--
cmk/gui/plugins/wato/datasource_programs.py | 27 +++++++++++++--------------
tests/unit/checks/test_agent_aws.py | 13 ++++++++++---
4 files changed, 32 insertions(+), 20 deletions(-)
diff --git a/agents/special/agent_aws b/agents/special/agent_aws
index 289c32e..6f0913d 100755
--- a/agents/special/agent_aws
+++ b/agents/special/agent_aws
@@ -440,7 +440,7 @@ class EC2(AWSSectionCloudwatch):
# '----------------------------------------------------------------------'
-class S3(AWSSection):
+class S3(AWSSectionGeneric):
@property
def name(self):
return "s3"
diff --git a/checks/agent_aws b/checks/agent_aws
index bbe29f6..6904ada 100644
--- a/checks/agent_aws
+++ b/checks/agent_aws
@@ -34,8 +34,14 @@ def agent_aws_arguments(params, hostname, ipaddress):
]
args.append("--regions")
args += params["--regions"]
- args.append("--services")
- args += params["--services"]
+
+ services = params.get("--services", {})
+ if services:
+ args.append("--services")
+ # We need to sort the inner services-as-a-dict-params
+ # in order to create reliable tests
+ args += sorted(services.keys())
+
args += [
"--hostname",
hostname,
diff --git a/cmk/gui/plugins/wato/datasource_programs.py
b/cmk/gui/plugins/wato/datasource_programs.py
index f6ee56a..7c5eeaf 100644
--- a/cmk/gui/plugins/wato/datasource_programs.py
+++ b/cmk/gui/plugins/wato/datasource_programs.py
@@ -1843,20 +1843,19 @@ class RulespecSpecialAgentsAws(HostRulespec):
],
key=lambda x: x[1]),
)),
- (
- "--services",
- ListChoice(
- title=_("Services to monitor"),
- choices=[
- ("ce", _("Costs and usage")),
- ("ec2", _("Elastic Compute Cloud
(EC2)")),
- ("ebs", _("Elastic Block Storage
(EBS)")),
- ("s3", _("Simple Storage Service
(S3)")),
- #("elb", _("Elastic Load Balancing
(ELB)")),
- #("cloudtrail", _("")),
- #("glacier", _("")),
- ],
- )),
+ ("--services",
+ Dictionary(
+ title=_("Services to monitor"),
+ elements=[
+ ("ce", FixedValue(None, totext="",
title=_("Costs and usage"))),
+ ("ec2", FixedValue(
+ None, totext="", title=_("Elastic Compute
Cloud (EC2)"))),
+ ("ebs", FixedValue(
+ None, totext="", title=_("Elastic Block
Storage (EBS)"))),
+ ("s3", FixedValue(None, totext="",
+ title=_("Simple Storage Service
(S3)"))),
+ ],
+ )),
],
optional_keys=[],
)
diff --git a/tests/unit/checks/test_agent_aws.py b/tests/unit/checks/test_agent_aws.py
index b85c6fe..030b7f2 100644
--- a/tests/unit/checks/test_agent_aws.py
+++ b/tests/unit/checks/test_agent_aws.py
@@ -5,10 +5,17 @@ import pytest
"--aws-access-key-id": "user",
"--aws-secret-access-key": "d1ng",
"--regions": ['region-eu'],
- "--services": ['ec2', 'ebs'],
}, [
- '--aws-access-key-id', 'user', '--aws-secret-access-key',
'd1ng', '--regions', 'region-eu',
- '--services', 'ec2', 'ebs', '--hostname',
'host'
+ '--aws-access-key-id', 'user', '--aws-secret-access-key',
'd1ng',
+ '--regions', 'region-eu', '--hostname', 'host'
+]), ({
+ "--aws-access-key-id": "user",
+ "--aws-secret-access-key": "d1ng",
+ "--regions": ['region-eu'],
+ "--services": {'ec2': None, 's3': None},
+}, [
+ '--aws-access-key-id', 'user', '--aws-secret-access-key',
'd1ng',
+ '--regions', 'region-eu', '--services', 'ec2',
's3', '--hostname', 'host'
])])
def test_aws(check_manager, params, result):
agent = check_manager.get_special_agent("agent_aws")