Module: check_mk
Branch: master
Commit: f23483709fede4bd806a3d80db673ea880b86c6a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=f23483709fede4…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Apr 24 10:13:52 2019 +0200
Move config.notification_parameters processing to HostConfig
CMK-2030
Change-Id: If136d6e34ea6b40172a6434f848a7d4f59a0adcf
---
cmk_base/config.py | 5 +++++
cmk_base/notify.py | 4 ++--
tests/unit/cmk_base/test_config.py | 25 +++++++++++++++++++++++++
3 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/cmk_base/config.py b/cmk_base/config.py
index 1c91ff7..1cf1594 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -2610,6 +2610,11 @@ class HostConfig(object):
hooks.append((hookname, entries[0]))
return hooks
+ def notification_plugin_parameters(self, plugin_name):
+ # type: (str) -> Dict
+ return self._config_cache.host_extra_conf_merged(
+ self.hostname, notification_parameters.get(plugin_name, []))
+
@property
def hostgroups(self):
# type: () -> List[str]
diff --git a/cmk_base/notify.py b/cmk_base/notify.py
index b60a033..bb99710 100755
--- a/cmk_base/notify.py
+++ b/cmk_base/notify.py
@@ -589,8 +589,8 @@ def rbn_fallback_contacts():
def rbn_finalize_plugin_parameters(hostname, plugin, rule_parameters):
# Right now we are only able to finalize notification plugins with dict parameters..
if isinstance(rule_parameters, dict):
- parameters = config.get_config_cache().host_extra_conf_merged(
- hostname, config.notification_parameters.get(plugin, []))
+ host_config = config.get_config_cache().get_host_config(hostname)
+ parameters = host_config.notification_plugin_parameters(plugin).copy()
parameters.update(rule_parameters)
return parameters
diff --git a/tests/unit/cmk_base/test_config.py b/tests/unit/cmk_base/test_config.py
index 66b5d49..ef3156a 100644
--- a/tests/unit/cmk_base/test_config.py
+++ b/tests/unit/cmk_base/test_config.py
@@ -544,6 +544,31 @@ def test_host_config_inventory_export_hooks(monkeypatch, hostname,
result):
@pytest.mark.parametrize("hostname,result", [
+ ("testhost1", {}),
+ ("testhost2", {
+ 'value1': 1,
+ 'value2': 2,
+ }),
+])
+def test_host_config_notification_plugin_parameters(monkeypatch, hostname, result):
+ ts = Scenario().add_host(hostname)
+ ts.set_option(
+ "notification_parameters", {
+ "mail": [
+ ({
+ "value1": 1,
+ }, [], ["testhost2"], {}),
+ ({
+ "value1": 2,
+ "value2": 2,
+ }, [], ["testhost2"], {}),
+ ],
+ })
+ config_cache = ts.apply(monkeypatch)
+ assert
config_cache.get_host_config(hostname).notification_plugin_parameters("mail") ==
result
+
+
+(a)pytest.mark.parametrize("hostname,result"sult", [
("testhost1", ["check_mk"]),
("testhost2", ["dingdong"]),
])