Module: check_mk
Branch: master
Commit: fc76c799e95fd78eb811bc3a413c0656b53da970
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=fc76c799e95fd7…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu May 2 11:18:36 2019 +0200
Move config.check_periods processing to ConfigCache
CMK-2030
Change-Id: Ib0c06138d57daa587d56e440bec1b4984e6deeca
---
cmk_base/config.py | 7 +++++++
tests/unit/cmk_base/test_config.py | 13 +++++++++++++
2 files changed, 20 insertions(+)
diff --git a/cmk_base/config.py b/cmk_base/config.py
index d6f177e..48da6b5 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -3075,6 +3075,13 @@ class ConfigCache(object):
return list(cgrs)
+ def passive_check_period_of_service(self, hostname, description):
+ # type: (str, Text) -> str
+ passive_check_period = self.service_extra_conf(hostname, description,
check_periods)
+ if not passive_check_period:
+ return "24X7"
+ return passive_check_period[0]
+
def get_explicit_service_custom_variables(self, hostname, description):
# type: (str, Text) -> Dict[str, str]
try:
diff --git a/tests/unit/cmk_base/test_config.py b/tests/unit/cmk_base/test_config.py
index 1732197..5e29a3f 100644
--- a/tests/unit/cmk_base/test_config.py
+++ b/tests/unit/cmk_base/test_config.py
@@ -1094,6 +1094,19 @@ def test_config_cache_contactgroups_of_service(monkeypatch,
hostname, result):
assert config_cache.contactgroups_of_service(hostname, "CPU load") ==
result
+(a)pytest.mark.parametrize("hostname,result"sult", [
+ ("testhost1", "24X7"),
+ ("testhost2", "workhours"),
+])
+def test_config_cache_passive_check_period_of_service(monkeypatch, hostname, result):
+ ts = Scenario().add_host(hostname)
+ ts.set_ruleset("check_periods", [
+ ("workhours", [], ["testhost2"], ["CPU load$"],
{}),
+ ])
+ config_cache = ts.apply(monkeypatch)
+ assert config_cache.passive_check_period_of_service(hostname, "CPU load")
== result
+
+
@pytest.mark.parametrize("edition_short,expected_cache_class_name,expected_host_class_name",
[
("cme", "CEEConfigCache", "CEEHostConfig"),
("cee", "CEEConfigCache", "CEEHostConfig"),