Module: check_mk
Branch: master
Commit: 3008d945d6ca4b6c9f3b6a67476e0afe5812aa44
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=3008d945d6ca4b…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu May 2 10:07:43 2019 +0200
Move config.service_contactgroups processing to ConfigCache
CMK-2030
Change-Id: I8dd706a88385b21f2d61887c77df38c435d2d382
---
cmk_base/config.py | 11 +++++++++++
cmk_base/core_nagios.py | 8 +++-----
tests/unit/cmk_base/test_config.py | 13 +++++++++++++
3 files changed, 27 insertions(+), 5 deletions(-)
diff --git a/cmk_base/config.py b/cmk_base/config.py
index 0c19a08..2b9a972 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -3064,6 +3064,17 @@ class ConfigCache(object):
"""Returns the list of servicegroups of this
services"""
return self.service_extra_conf(hostname, description, service_groups)
+ def contactgroups_of_service(self, hostname, description):
+ # type: (str, Text) -> List[str]
+ """Returns the list of contactgroups of this
service"""
+ cgrs = set() # type: Set[str]
+ cgrs.update(self.service_extra_conf(hostname, description,
service_contactgroups))
+
+ if monitoring_core == "nagios" and enable_rulebased_notifications:
+ cgrs.add("check-mk-notify")
+
+ return list(cgrs)
+
def get_explicit_service_custom_variables(self, hostname, description):
# type: (str, Text) -> Dict[str, str]
try:
diff --git a/cmk_base/core_nagios.py b/cmk_base/core_nagios.py
index 65ddf06..b264f88 100644
--- a/cmk_base/core_nagios.py
+++ b/cmk_base/core_nagios.py
@@ -828,12 +828,10 @@ def _extra_service_conf_of(cfg, config_cache, hostname,
description):
service_spec = {}
# Contact groups
- sercgr = config_cache.service_extra_conf(hostname, description,
config.service_contactgroups)
- cfg.contactgroups_to_define.update(sercgr)
- if len(sercgr) > 0:
- if config.enable_rulebased_notifications:
- sercgr.append("check-mk-notify") # not nessary if not explicit
groups defined
+ sercgr = config_cache.contactgroups_of_service(hostname, description)
+ if sercgr:
service_spec["contact_groups"] = ",".join(sercgr)
+ cfg.contactgroups_to_define.update(sercgr)
sergr = config_cache.servicegroups_of_service(hostname, description)
if sergr:
diff --git a/tests/unit/cmk_base/test_config.py b/tests/unit/cmk_base/test_config.py
index 4f6faa9..1732197 100644
--- a/tests/unit/cmk_base/test_config.py
+++ b/tests/unit/cmk_base/test_config.py
@@ -1081,6 +1081,19 @@ def test_config_cache_servicegroups_of_service(monkeypatch,
hostname, result):
assert config_cache.servicegroups_of_service(hostname, "CPU load") ==
result
+(a)pytest.mark.parametrize("hostname,result"sult", [
+ ("testhost1", []),
+ ("testhost2", ["dingdong"]),
+])
+def test_config_cache_contactgroups_of_service(monkeypatch, hostname, result):
+ ts = Scenario().add_host(hostname)
+ ts.set_ruleset("service_contactgroups", [
+ ("dingdong", [], ["testhost2"], "CPU load", {}),
+ ])
+ config_cache = ts.apply(monkeypatch)
+ assert config_cache.contactgroups_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"),