Module: check_mk
Branch: master
Commit: b5840731a87ee45771af5e81ede38fe0b2ea882a
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b5840731a87ee4…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu May 2 08:06:08 2019 +0200
Move config.extra_service_conf processing to ConfigCache
CMK-2030
Change-Id: I5dc4ae6aa9291be335e240b6ffd3645afa5a0f0b
---
cmk_base/config.py | 13 +++++++++++++
cmk_base/core_config.py | 7 +------
tests/unit/cmk_base/test_config.py | 32 ++++++++++++++++++++++++++++++++
3 files changed, 46 insertions(+), 6 deletions(-)
diff --git a/cmk_base/config.py b/cmk_base/config.py
index c269c36..56a8571 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -3032,6 +3032,19 @@ class ConfigCache(object):
})
return labels
+ def get_extra_attributes_of_service(self, hostname, description):
+ # type: (str, Text) -> Dict[str, str]
+ attrs = {}
+ for key, conflist in extra_service_conf.items():
+ values = self.service_extra_conf(hostname, description, conflist)
+ if values:
+ if key[0] == "_":
+ key = key.upper()
+
+ if values[0] is not None:
+ attrs[key] = values[0]
+ return attrs
+
def get_explicit_service_custom_variables(self, hostname, description):
# type: (str, Text) -> Dict[str, str]
try:
diff --git a/cmk_base/core_config.py b/cmk_base/core_config.py
index 88e3458..7057e5c 100644
--- a/cmk_base/core_config.py
+++ b/cmk_base/core_config.py
@@ -326,12 +326,7 @@ def _extra_service_attributes(hostname, description, config_cache,
checkname, pa
description).iteritems():
attrs["_%s" % varname.upper()] = value
- for key, conflist in config.extra_service_conf.items():
- values = config_cache.service_extra_conf(hostname, description, conflist)
- if values:
- if key[0] == "_":
- key = key.upper()
- attrs[key] = values[0]
+ attrs.update(config_cache.get_extra_attributes_of_service(hostname, description))
# Add explicit custom_variables
for varname, value in config_cache.get_explicit_service_custom_variables(
diff --git a/tests/unit/cmk_base/test_config.py b/tests/unit/cmk_base/test_config.py
index 455680e..92d6923 100644
--- a/tests/unit/cmk_base/test_config.py
+++ b/tests/unit/cmk_base/test_config.py
@@ -1019,6 +1019,38 @@ def test_labels_of_service(monkeypatch):
}
+(a)pytest.mark.parametrize("hostname,result"sult", [
+ ("testhost1", {}),
+ ("testhost2", {
+ '_CUSTOM': ['value1'],
+ 'dingdong': ['value1']
+ }),
+])
+def test_config_cache_extra_attributes_of_service(monkeypatch, hostname, result):
+ ts = Scenario().add_host(hostname)
+ ts.set_option(
+ "extra_service_conf", {
+ "dingdong": [
+ ([
+ "value1",
+ ], [], ["testhost2"], "CPU load$", {}),
+ ([
+ "value2",
+ ], [], ["testhost2"], "CPU load$", {}),
+ ],
+ "_custom": [
+ ([
+ "value1",
+ ], [], ["testhost2"], "CPU load$", {}),
+ ([
+ "value2",
+ ], [], ["testhost2"], "CPU load$", {}),
+ ],
+ })
+ config_cache = ts.apply(monkeypatch)
+ assert config_cache.get_extra_attributes_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"),