Module: check_mk
Branch: master
Commit: ac910c9aaf963956a1dc5ad601f169c82076fbe7
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ac910c9aaf9639…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu May 2 08:27:48 2019 +0200
Move config.service_icons_and_actions processing to ConfigCache
CMK-2030
Change-Id: I7372d9343dac471799ce09b457fc34df0796dd5b
---
cmk_base/config.py | 14 ++++++++++++++
cmk_base/core_config.py | 20 +-------------------
tests/unit/cmk_base/test_config.py | 17 +++++++++++++++++
3 files changed, 32 insertions(+), 19 deletions(-)
diff --git a/cmk_base/config.py b/cmk_base/config.py
index 56a8571..76764fc 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -3045,6 +3045,20 @@ class ConfigCache(object):
attrs[key] = values[0]
return attrs
+ def icons_and_actions_of_service(self, hostname, description, checkname, params):
+ # type: (str, Text, str, Dict) -> List[str]
+ actions = set(self.service_extra_conf(hostname, description,
service_icons_and_actions))
+
+ # Some WATO rules might register icons on their own
+ if checkname:
+ checkgroup = check_info[checkname]["group"]
+ if checkgroup in ['ps', 'services'] and isinstance(params,
dict):
+ icon = params.get('icon')
+ if icon:
+ actions.add(icon)
+
+ return list(actions)
+
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 7057e5c..f5b3ea3 100644
--- a/cmk_base/core_config.py
+++ b/cmk_base/core_config.py
@@ -334,9 +334,7 @@ def _extra_service_attributes(hostname, description, config_cache,
checkname, pa
attrs["_%s" % varname.upper()] = value
# Add custom user icons and actions
- host_config = config_cache.get_host_config(hostname)
- actions = _icons_and_actions_of_service(config_cache, host_config, description,
checkname,
- params)
+ actions = config_cache.icons_and_actions_of_service(hostname, description, checkname,
params)
if actions:
attrs["_ACTIONS"] = ','.join(actions)
return attrs
@@ -348,22 +346,6 @@ def _custom_service_attributes_of(config_cache, hostname,
service_description):
config.custom_service_attributes)))
-def _icons_and_actions_of_service(config_cache, host_config, svcdesc, checkname,
params):
- actions = set(
- config_cache.service_extra_conf(host_config.hostname, svcdesc,
- config.service_icons_and_actions))
-
- # Some WATO rules might register icons on their own
- if checkname:
- checkgroup = config.check_info[checkname]["group"]
- if checkgroup in ['ps', 'services'] and isinstance(params,
dict):
- icon = params.get('icon')
- if icon:
- actions.add(icon)
-
- return list(actions)
-
-
#.
# .--HostAttributes------------------------------------------------------.
# | _ _ _ _ _ _ _ _ _ |
diff --git a/tests/unit/cmk_base/test_config.py b/tests/unit/cmk_base/test_config.py
index 92d6923..29f8a9d 100644
--- a/tests/unit/cmk_base/test_config.py
+++ b/tests/unit/cmk_base/test_config.py
@@ -1051,6 +1051,23 @@ def test_config_cache_extra_attributes_of_service(monkeypatch,
hostname, result)
assert config_cache.get_extra_attributes_of_service(hostname, "CPU load")
== result
+(a)pytest.mark.parametrize("hostname,result"sult", [
+ ("testhost1", []),
+ ("testhost2", ["icon1", "icon2"]),
+])
+def test_config_cache_icons_and_actions(monkeypatch, hostname, result):
+ config.load_checks(check_api.get_check_api_context, ["checks/ps"])
+ ts = Scenario().add_host(hostname)
+ ts.set_ruleset("service_icons_and_actions", [
+ ("icon1", [], ["testhost2"], "CPU load$", {}),
+ ("icon1", [], ["testhost2"], "CPU load$", {}),
+ ("icon2", [], ["testhost2"], "CPU load$", {}),
+ ])
+ config_cache = ts.apply(monkeypatch)
+ assert sorted(config_cache.icons_and_actions_of_service(hostname, "CPU
load", "ps",
+ {})) == sorted(result)
+
+
@pytest.mark.parametrize("edition_short,expected_cache_class_name,expected_host_class_name",
[
("cme", "CEEConfigCache", "CEEHostConfig"),
("cee", "CEEConfigCache", "CEEHostConfig"),