Module: check_mk
Branch: master
Commit: 7e6f4796222bb019b68cfa8aeb949fe02cb24cef
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=7e6f4796222bb0…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Apr 24 07:44:38 2019 +0200
Move config.host_check_commands processing to HostConfig
CMK-2030
Change-Id: I5affcdc1612285ec4fc4290ed65c7c25ac2c5d9e
---
cmk_base/config.py | 12 ++++++++++++
cmk_base/core_config.py | 11 ++++-------
tests/unit/cmk_base/test_config.py | 21 +++++++++++++++++++++
3 files changed, 37 insertions(+), 7 deletions(-)
diff --git a/cmk_base/config.py b/cmk_base/config.py
index 41b6e28..38107df 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -2553,6 +2553,18 @@ class HostConfig(object):
return entries[0]
@property
+ def explicit_check_command(self):
+ # type: () -> Optional[str]
+ entries = self._config_cache.host_extra_conf(self.hostname, host_check_commands)
+ if not entries:
+ return None
+
+ if entries[0] == "smart" and monitoring_core != "cmc":
+ return "ping" # avoid problems when switching back to nagios core
+
+ return entries[0]
+
+ @property
def hostgroups(self):
# type: () -> List[str]
"""Returns the list of hostgroups of this host
diff --git a/cmk_base/core_config.py b/cmk_base/core_config.py
index 83e7b0c..4964d29 100644
--- a/cmk_base/core_config.py
+++ b/cmk_base/core_config.py
@@ -100,10 +100,10 @@ def host_check_command(config_cache,
is_clust,
hostcheck_commands_to_define=None,
custom_commands_to_define=None):
- # Check dedicated host check command
- values = config_cache.host_extra_conf(host_config.hostname,
config.host_check_commands)
- if values:
- value = values[0]
+
+ explicit_command = host_config.explicit_check_command
+ if explicit_command is not None:
+ value = explicit_command
elif host_config.is_no_ip_host:
value = "ok"
elif config.monitoring_core == "cmc":
@@ -111,9 +111,6 @@ def host_check_command(config_cache,
else:
value = "ping"
- if config.monitoring_core != "cmc" and value == "smart":
- value = "ping" # avoid problems when switching back to nagios core
-
if value == "smart" and not is_clust:
return "check-mk-host-smart"
diff --git a/tests/unit/cmk_base/test_config.py b/tests/unit/cmk_base/test_config.py
index 5e7a48b..0537c7d 100644
--- a/tests/unit/cmk_base/test_config.py
+++ b/tests/unit/cmk_base/test_config.py
@@ -402,6 +402,27 @@ def test_host_config_only_from(monkeypatch, hostname, result):
assert config_cache.get_host_config(hostname).only_from == result
+(a)pytest.mark.parametrize("hostname,core_name,result"sult", [
+ ("testhost1", "cmc", None),
+ ("testhost2", "cmc", "command1"),
+ ("testhost3", "cmc", "smart"),
+ ("testhost3", "nagios", "ping"),
+])
+def test_host_config_explicit_check_command(monkeypatch, hostname, core_name, result):
+ ts = Scenario().add_host(hostname)
+ ts.set_option("monitoring_core", core_name)
+ ts.set_option(
+ "host_check_commands",
+ [
+ ("command1", [], ["testhost2"], {}),
+ ("command2", [], ["testhost2"], {}),
+ ("smart", [], ["testhost3"], {}),
+ ],
+ )
+ config_cache = ts.apply(monkeypatch)
+ assert config_cache.get_host_config(hostname).explicit_check_command == result
+
+
@pytest.mark.parametrize("hostname,result", [
("testhost1", ["check_mk"]),
("testhost2", ["dingdong"]),