Module: check_mk
Branch: master
Commit: 29b7f0c4e91f2d3005237786c15065f70e9090c8
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=29b7f0c4e91f2d…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Apr 24 07:22:01 2019 +0200
Move config.datasource_programs ruleset processing to HostConfig
CMK-2030
Change-Id: Ib570d590d62fe40886ce2a79a895a52b44c42620
---
cmk_base/config.py | 13 +++++++++++++
cmk_base/data_sources/__init__.py | 6 +++---
tests/unit/cmk_base/test_config.py | 13 +++++++++++++
3 files changed, 29 insertions(+), 3 deletions(-)
diff --git a/cmk_base/config.py b/cmk_base/config.py
index 7d719fe..06cb8cd 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -2510,6 +2510,19 @@ class HostConfig(object):
return spec # return the whole spec in case of an "at least version"
config
@property
+ def datasource_program(self):
+ # type: () -> Optional[str]
+ """Return the command line to execute instead of contacting the
agent
+
+ In case no datasource program is configured for a host return None
+ """
+ programs = self._config_cache.host_extra_conf(self.hostname,
datasource_programs)
+ if not programs:
+ return None
+
+ return programs[0]
+
+ @property
def hostgroups(self):
# type: () -> List[str]
"""Returns the list of hostgroups of this host
diff --git a/cmk_base/data_sources/__init__.py b/cmk_base/data_sources/__init__.py
index 9a6523a..7aa1803 100644
--- a/cmk_base/data_sources/__init__.py
+++ b/cmk_base/data_sources/__init__.py
@@ -179,9 +179,9 @@ class DataSources(object):
if special_agents:
return special_agents[0]
- programs = self._config_cache.host_extra_conf(self._hostname,
config.datasource_programs)
- if programs:
- return DSProgramDataSource(self._hostname, self._ipaddress, programs[0])
+ datasource_program = self._host_config.datasource_program
+ if datasource_program is not None:
+ return DSProgramDataSource(self._hostname, self._ipaddress,
datasource_program)
return TCPDataSource(self._hostname, self._ipaddress)
diff --git a/tests/unit/cmk_base/test_config.py b/tests/unit/cmk_base/test_config.py
index f99fd00..5b76c12 100644
--- a/tests/unit/cmk_base/test_config.py
+++ b/tests/unit/cmk_base/test_config.py
@@ -343,6 +343,19 @@ def test_host_config_agent_target_version(monkeypatch, hostname,
result):
@pytest.mark.parametrize("hostname,result", [
+ ("testhost1", None),
+ ("testhost2", "echo 1"),
+])
+def test_host_config_datasource_program(monkeypatch, hostname, result):
+ ts = Scenario().add_host(hostname)
+ ts.set_ruleset("datasource_programs", [
+ ("echo 1", [], ["testhost2"], {}),
+ ])
+ config_cache = ts.apply(monkeypatch)
+ assert config_cache.get_host_config(hostname).datasource_program == result
+
+
+(a)pytest.mark.parametrize("hostname,result"sult", [
("testhost1", ["check_mk"]),
("testhost2", ["dingdong"]),
])