Module: check_mk
Branch: master
Commit: b091b3b845716c9aaf2c1f3be5f59a32e2dad9dd
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b091b3b845716c…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Thu May 2 13:19:47 2019 +0200
agent_aws: Fixed querying ApplicationELB and NetworkELB
Change-Id: I8e880d4efe9b883bbb721184bfebeae814bc473c
---
cmk/special_agents/agent_aws.py | 17 ++++++--
.../agent_aws/test_agent_aws_elbv2.py | 47 ++++++++++++++++++++--
2 files changed, 57 insertions(+), 7 deletions(-)
diff --git a/cmk/special_agents/agent_aws.py b/cmk/special_agents/agent_aws.py
index eac5bd9..2287596 100644
--- a/cmk/special_agents/agent_aws.py
+++ b/cmk/special_agents/agent_aws.py
@@ -1896,9 +1896,20 @@ class ELBSummaryGeneric(AWSSectionGeneric):
if load_balancer['LoadBalancerName'] in self._names
]
response =
self._client.describe_load_balancers(LoadBalancerNames=self._names)
+
else:
+ if colleague_contents.content:
+ return colleague_contents.content
+
response = self._client.describe_load_balancers()
- return self._get_response_content(response, 'LoadBalancerDescriptions')
+
+ if self._resource == "elb":
+ response_key = "LoadBalancerDescriptions"
+ elif self._resource == "elbv2":
+ response_key = "LoadBalancers"
+ else:
+ response_key = None
+ return self._get_response_content(response, response_key)
def _matches_tag_conditions(self, tagging):
if self._names is not None:
@@ -2256,7 +2267,7 @@ class ELBv2Application(AWSSectionCloudwatch):
return 300
def _get_colleague_contents(self):
- colleague = self._received_results.get('elb_summary')
+ colleague = self._received_results.get('elbv2_summary')
if colleague and colleague.content:
return AWSColleagueContents(colleague.content, colleague.cache_timestamp)
return AWSColleagueContents({}, 0.0)
@@ -2342,7 +2353,7 @@ class ELBv2Network(AWSSectionCloudwatch):
return 300
def _get_colleague_contents(self):
- colleague = self._received_results.get('elb_summary')
+ colleague = self._received_results.get('elbv2_summary')
if colleague and colleague.content:
return AWSColleagueContents(colleague.content, colleague.cache_timestamp)
return AWSColleagueContents({}, 0.0)
diff --git a/tests/unit/cmk/special_agents/agent_aws/test_agent_aws_elbv2.py
b/tests/unit/cmk/special_agents/agent_aws/test_agent_aws_elbv2.py
index a4c39b3..7ad17d0 100644
--- a/tests/unit/cmk/special_agents/agent_aws/test_agent_aws_elbv2.py
+++ b/tests/unit/cmk/special_agents/agent_aws/test_agent_aws_elbv2.py
@@ -2,12 +2,14 @@
import pytest
from agent_aws_fake_clients import (
+ FakeCloudwatchClient,
ELBv2DescribeLoadBalancersIB,
ELBv2DescribeTargetGroupsIB,
ELBv2DescribeListenersIB,
ELBv2DescribeRulesIB,
ELBv2DescribeAccountLimitsIB,
ELBv2DescribeTargetHealthIB,
+ ELBDescribeTagsIB,
)
from cmk.special_agents.agent_aws import (
@@ -16,6 +18,8 @@ from cmk.special_agents.agent_aws import (
ELBv2Limits,
ELBSummaryGeneric,
ELBv2TargetGroups,
+ ELBv2Application,
+ ELBv2Network,
)
@@ -26,6 +30,11 @@ class FakeELBv2Client(object):
'NextMarker': 'string',
}
+ def describe_tags(self, LoadBalancerNames=None):
+ return {
+ 'TagDescriptions': ELBDescribeTagsIB.create_instances(amount=1),
+ }
+
def describe_target_groups(self, LoadBalancerArn=None):
return {
'TargetGroups':
ELBv2DescribeTargetGroupsIB.create_instances(amount=1),
@@ -65,6 +74,7 @@ def get_elbv2_sections():
config.add_service_tags('elbv2_tags', tags)
fake_elbv2_client = FakeELBv2Client()
+ fake_cloudwatch_client = FakeCloudwatchClient()
elbv2_limits_distributor = ResultDistributor()
elbv2_summary_distributor = ResultDistributor()
@@ -73,16 +83,21 @@ def get_elbv2_sections():
elbv2_summary = ELBSummaryGeneric(
fake_elbv2_client, region, config, elbv2_summary_distributor,
resource='elbv2')
elbv2_target_groups = ELBv2TargetGroups(fake_elbv2_client, region, config)
+ elbv2_application = ELBv2Application(fake_cloudwatch_client, region, config)
+ elbv2_network = ELBv2Network(fake_cloudwatch_client, region, config)
elbv2_limits_distributor.add(elbv2_summary)
elbv2_summary_distributor.add(elbv2_target_groups)
- return elbv2_limits, elbv2_summary, elbv2_target_groups
+ elbv2_summary_distributor.add(elbv2_application)
+ elbv2_summary_distributor.add(elbv2_network)
+ return elbv2_limits, elbv2_summary, elbv2_target_groups, elbv2_application,
elbv2_network
return _create_elbv2_sections
def test_agent_aws_elbv2_limits(get_elbv2_sections):
- elbv2_limits, _elbv2_summary, _elbv2_target_groups = get_elbv2_sections(None, (None,
None))
+ elbv2_limits, _elbv2_summary, _elbv2_target_groups, _elbv2_application,
_elbv2_network = get_elbv2_sections(
+ None, (None, None))
_elbv2_limits_results = elbv2_limits.run().results
assert elbv2_limits.cache_interval == 300
@@ -90,7 +105,8 @@ def test_agent_aws_elbv2_limits(get_elbv2_sections):
def test_agent_aws_elbv2_summary(get_elbv2_sections):
- elbv2_limits, elbv2_summary, _elbv2_target_groups = get_elbv2_sections(None, (None,
None))
+ elbv2_limits, elbv2_summary, _elbv2_target_groups, _elbv2_application, _elbv2_network
= get_elbv2_sections(
+ None, (None, None))
_elbv2_limits_results = elbv2_limits.run().results
_elbv2_summary_results = elbv2_summary.run().results
@@ -99,10 +115,33 @@ def test_agent_aws_elbv2_summary(get_elbv2_sections):
def test_agent_aws_elbv2_target_groups(get_elbv2_sections):
- elbv2_limits, elbv2_summary, elbv2_target_groups = get_elbv2_sections(None, (None,
None))
+ elbv2_limits, elbv2_summary, elbv2_target_groups, _elbv2_application, _elbv2_network
= get_elbv2_sections(
+ None, (None, None))
_elbv2_limits_results = elbv2_limits.run().results
_elbv2_summary_results = elbv2_summary.run().results
_elbv2_target_groups_results = elbv2_target_groups.run().results
assert elbv2_target_groups.cache_interval == 300
assert elbv2_target_groups.name == "elbv2_target_groups"
+
+
+def test_agent_aws_elbv2_application(get_elbv2_sections):
+ elbv2_limits, elbv2_summary, _elbv2_target_groups, elbv2_application, _elbv2_network
= get_elbv2_sections(
+ None, (None, None))
+ _elbv2_limits_results = elbv2_limits.run().results
+ _elbv2_summary_results = elbv2_summary.run().results
+ _elbv2_application_results = elbv2_application.run().results
+
+ assert elbv2_application.cache_interval == 300
+ assert elbv2_application.name == "elbv2_application"
+
+
+def test_agent_aws_elbv2_network(get_elbv2_sections):
+ elbv2_limits, elbv2_summary, _elbv2_target_groups, _elbv2_application, elbv2_network
= get_elbv2_sections(
+ None, (None, None))
+ _elbv2_limits_results = elbv2_limits.run().results
+ _elbv2_summary_results = elbv2_summary.run().results
+ _elbv2_network_results = elbv2_network.run().results
+
+ assert elbv2_network.cache_interval == 300
+ assert elbv2_network.name == "elbv2_network"