Module: check_mk
Branch: master
Commit: 51ab70e6eb1c456a40249a861d29658f6608e1ff
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=51ab70e6eb1c45…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Apr 25 07:58:31 2019 +0200
Move config.cmc_*_rrd_config processing to HostConfig
CMK-2030
Change-Id: I610d354c4e727a8e8603bd32f9babb0325930e09
---
cmk_base/config.py | 16 +++++++++++++++
tests/unit/cmk_base/test_config.py | 40 ++++++++++++++++++++++++++++++++++++++
2 files changed, 56 insertions(+)
diff --git a/cmk_base/config.py b/cmk_base/config.py
index 4c225c8..80469cc 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -2686,6 +2686,14 @@ class HostConfig(object):
return list(set(cgrs))
@property
+ def rrd_config(self):
+ # type: () -> Optional[Dict]
+ entries = self._config_cache.host_extra_conf(self.hostname, cmc_host_rrd_config)
+ if not entries:
+ return None
+ return entries[0]
+
+ @property
def management_address(self):
# type: () -> Optional[str]
attributes_of_host = host_attributes.get(self.hostname, {})
@@ -2989,6 +2997,14 @@ class ConfigCache(object):
return match_object
+ def rrd_config_of_service(self, hostname, description):
+ # type: (str, Text) -> Optional[Dict]
+ rrdconf = self.service_extra_conf(hostname, description, cmc_service_rrd_config)
+ if not rrdconf:
+ return None
+
+ return rrdconf[0]
+
def set_all_processed_hosts(self, all_processed_hosts):
self._all_processed_hosts = set(all_processed_hosts)
diff --git a/tests/unit/cmk_base/test_config.py b/tests/unit/cmk_base/test_config.py
index 2485dc2..b8d8cbd 100644
--- a/tests/unit/cmk_base/test_config.py
+++ b/tests/unit/cmk_base/test_config.py
@@ -655,6 +655,26 @@ def test_host_config_contactgroups(monkeypatch, hostname, result):
@pytest.mark.parametrize("hostname,result", [
+ ("testhost1", None),
+ ("testhost2", {
+ "1": 1
+ }),
+])
+def test_host_config_rrd_config(monkeypatch, hostname, result):
+ ts = Scenario().add_host(hostname)
+ ts.set_ruleset("cmc_host_rrd_config", [
+ ({
+ "1": 1
+ }, [], ["testhost2"], {}),
+ ({
+ "2": 2
+ }, [], ["testhost2"], {}),
+ ])
+ config_cache = ts.apply(monkeypatch)
+ assert config_cache.get_host_config(hostname).rrd_config == result
+
+
+(a)pytest.mark.parametrize("hostname,result"sult", [
("testhost1", {}),
("testhost2", {
'empty_output': 1
@@ -944,6 +964,26 @@ def test_labels_of_service(monkeypatch):
}
+(a)pytest.mark.parametrize("hostname,result"sult", [
+ ("testhost1", None),
+ ("testhost2", {
+ "1": 1
+ }),
+])
+def test_config_cache_rrd_config_of_service(monkeypatch, hostname, result):
+ ts = Scenario().add_host(hostname)
+ ts.set_ruleset("cmc_service_rrd_config", [
+ ({
+ "1": 1
+ }, [], ["testhost2"], ["CPU load$"], {}),
+ ({
+ "2": 2
+ }, [], ["testhost2"], ["CPU load$"], {}),
+ ])
+ config_cache = ts.apply(monkeypatch)
+ assert config_cache.rrd_config_of_service(hostname, "CPU load") == result
+
+
def test_config_cache_get_host_config():
cache = config.ConfigCache()
assert cache._host_configs == {}