Module: check_mk
Branch: master
Commit: 248c3e907a605b8e5978c98d71150ec93fcb4e81
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=248c3e907a605b…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Apr 24 08:48:28 2019 +0200
Move config.ping_levels processing to HostConfig
CMK-2030
Change-Id: Ib881070a2fb62c11243318b83bec3d9e363a1663
---
cmk_base/config.py | 12 ++++++++++++
cmk_base/core_config.py | 8 +++-----
tests/unit/cmk_base/test_config.py | 24 ++++++++++++++++++++++++
3 files changed, 39 insertions(+), 5 deletions(-)
diff --git a/cmk_base/config.py b/cmk_base/config.py
index 38107df..96d9173 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -2565,6 +2565,18 @@ class HostConfig(object):
return entries[0]
@property
+ def ping_levels(self):
+ # type: () -> Dict[str, Union[int, float]]
+ levels = {} # type: Dict[str, Union[int, float]]
+
+ values = self._config_cache.host_extra_conf(self.hostname, ping_levels)
+ # TODO: Use host_extra_conf_merged?)
+ for value in values[::-1]: # make first rules have precedence
+ levels.update(value)
+
+ return levels
+
+ @property
def hostgroups(self):
# type: () -> List[str]
"""Returns the list of hostgroups of this host
diff --git a/cmk_base/core_config.py b/cmk_base/core_config.py
index 4964d29..fb498ff 100644
--- a/cmk_base/core_config.py
+++ b/cmk_base/core_config.py
@@ -190,15 +190,13 @@ def _icons_and_actions_of(config_cache, what, hostname,
svcdesc=None, checkname=
def check_icmp_arguments_of(config_cache, hostname, add_defaults=True, family=None):
- values = config_cache.host_extra_conf(hostname, config.ping_levels)
- levels = {}
- for value in values[::-1]: # make first rules have precedence
- levels.update(value)
+ host_config = config_cache.get_host_config(hostname)
+ levels = host_config.ping_levels
+
if not add_defaults and not levels:
return ""
if family is None:
- host_config = config_cache.get_host_config(hostname)
family = 6 if host_config.is_ipv6_primary else 4
args = []
diff --git a/tests/unit/cmk_base/test_config.py b/tests/unit/cmk_base/test_config.py
index 0537c7d..9b55acb 100644
--- a/tests/unit/cmk_base/test_config.py
+++ b/tests/unit/cmk_base/test_config.py
@@ -424,6 +424,30 @@ def test_host_config_explicit_check_command(monkeypatch, hostname,
core_name, re
@pytest.mark.parametrize("hostname,result", [
+ ("testhost1", {}),
+ ("testhost2", {
+ "ding": 1,
+ "dong": 1
+ }),
+])
+def test_host_config_ping_levels(monkeypatch, hostname, result):
+ ts = Scenario().add_host(hostname)
+ ts.set_ruleset("ping_levels", [
+ ({
+ "ding": 1,
+ }, [], ["testhost2"], {}),
+ ({
+ "ding": 3,
+ }, [], ["testhost2"], {}),
+ ({
+ "dong": 1,
+ }, [], ["testhost2"], {}),
+ ])
+ config_cache = ts.apply(monkeypatch)
+ assert config_cache.get_host_config(hostname).ping_levels == result
+
+
+(a)pytest.mark.parametrize("hostname,result"sult", [
("testhost1", ["check_mk"]),
("testhost2", ["dingdong"]),
])