Module: check_mk
Branch: master
Commit: 5a14ffc087ed4745e38565875f9cebd666df8bfd
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=5a14ffc087ed47…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Thu Jan 24 13:35:12 2019 +0100
Minor folderpath fixes for hosts specified in conf.d
Change-Id: I051ecb81b39a8da8fdac3b62b31887951cdf40c2
---
cmk_base/config.py | 12 ++++++++----
tests/unit/cmk_base/test_checks.py | 2 +-
tests/unit/cmk_base/test_config.py | 4 ++--
tests/unit/cmk_base/test_rulesets.py | 4 ++--
4 files changed, 13 insertions(+), 9 deletions(-)
diff --git a/cmk_base/config.py b/cmk_base/config.py
index a7ed32d..fd2df7f 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -2884,15 +2884,18 @@ class ConfigCache(object):
1.0 * len(self._all_processed_hosts) / len(used_groups))
def _initialize_host_lookup(self):
+ for hostname in self._all_configured_hosts:
+ dirname_of_host = os.path.dirname(host_paths[hostname])
+ if dirname_of_host[-1] != "/":
+ dirname_of_host += "/"
+ self._host_paths[hostname] = dirname_of_host
+
+ # Determine hosts within folders
dirnames = [
x[0][len(cmk.utils.paths.check_mk_config_dir):] + "/"
for x in os.walk(cmk.utils.paths.check_mk_config_dir)
]
- for hostname in self._all_configured_hosts:
- self._host_paths[hostname] = os.path.dirname(host_paths[hostname]) +
"/"
-
- # Determine hosts within folders
for dirname in dirnames:
for hostname in self._all_configured_hosts:
if self._host_paths[hostname].startswith(dirname):
@@ -2975,6 +2978,7 @@ class ConfigCache(object):
tags_set_without_folder = tags_set - rule_path_set
if rule_path_set:
+ # More than one dynamic folder in one rule is simply wrong..
rule_path = list(rule_path_set)[0]
else:
rule_path = "/+"
diff --git a/tests/unit/cmk_base/test_checks.py b/tests/unit/cmk_base/test_checks.py
index aaf1c45..84039ad 100644
--- a/tests/unit/cmk_base/test_checks.py
+++ b/tests/unit/cmk_base/test_checks.py
@@ -63,7 +63,7 @@ def test_do_status_data_inventory_for(monkeypatch, result, ruleset):
config.load_default_config()
monkeypatch.setattr(config, "all_hosts", ["abc"])
- monkeypatch.setattr(config, "host_paths", {"abc": ""})
+ monkeypatch.setattr(config, "host_paths", {"abc":
"/"})
monkeypatch.setattr(config, "active_checks", {
"cmk_inv": ruleset,
})
diff --git a/tests/unit/cmk_base/test_config.py b/tests/unit/cmk_base/test_config.py
index 830521c..d1c3a14 100644
--- a/tests/unit/cmk_base/test_config.py
+++ b/tests/unit/cmk_base/test_config.py
@@ -57,7 +57,7 @@ def test_is_no_ip_host(monkeypatch, hostname, tags, result):
])
def test_is_ipv6_primary_host(monkeypatch, hostname, tags, result, ruleset):
monkeypatch.setattr(config, "all_hosts", ["%s|%s" % (hostname,
"|".join(tags))])
- monkeypatch.setattr(config, "host_paths", {hostname: ""})
+ monkeypatch.setattr(config, "host_paths", {hostname: "/"})
monkeypatch.setattr(config, "tags_of_host", lambda h: {hostname: tags}[h])
monkeypatch.setattr(config, "primary_address_family", ruleset)
@@ -204,5 +204,5 @@ def test_http_proxy(http_proxy, result, monkeypatch):
def _setup_host(monkeypatch, hostname, tags):
monkeypatch.setattr(config, "all_hosts", ["%s|%s" % (hostname,
"|".join(tags))])
- monkeypatch.setattr(config, "host_paths", {hostname: ""})
+ monkeypatch.setattr(config, "host_paths", {hostname: "/"})
diff --git a/tests/unit/cmk_base/test_rulesets.py b/tests/unit/cmk_base/test_rulesets.py
index c6e6b09..b35f373 100644
--- a/tests/unit/cmk_base/test_rulesets.py
+++ b/tests/unit/cmk_base/test_rulesets.py
@@ -24,7 +24,7 @@ def clear_config_caches(monkeypatch):
def test_service_extra_conf(monkeypatch):
import cmk_base.config as config
monkeypatch.setattr(config, "all_hosts", ["host1|tag1|tag2",
"host2|tag1"])
- monkeypatch.setattr(config, "host_paths", {"host1": "",
"host2": ""})
+ monkeypatch.setattr(config, "host_paths", {"host1":
"/", "host2": "/"})
monkeypatch.setattr(config, "clusters", {})
config.get_config_cache().initialize()
@@ -68,7 +68,7 @@ def test_all_matching_hosts(monkeypatch):
monkeypatch.setattr(config, "distributed_wato_site", "site1")
monkeypatch.setattr(config, "all_hosts",
["host1|tag1|tag2", "host2|tag1",
"host3|tag1|site:site2"])
- monkeypatch.setattr(config, "host_paths", {"host1": "",
"host2": "", "host3": ""})
+ monkeypatch.setattr(config, "host_paths", {"host1":
"/", "host2": "/", "host3": "/"})
monkeypatch.setattr(config, "clusters", {})
config.get_config_cache().initialize()