Module: check_mk
Branch: master
Commit: d8ff2e5ddf2db80494eb38dd6acb1f47fccab7c0
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=d8ff2e5ddf2db8…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Apr 22 17:12:24 2019 +0200
Cleanup config.parents_of
CMK-2030
Change-Id: I05be7e80214df5565ccc6f71833bb903459ca6eb
---
cmk_base/config.py | 26 +++++++++++---------------
cmk_base/core_nagios.py | 2 +-
cmk_base/dump_host.py | 2 +-
cmk_base/parent_scan.py | 5 ++++-
4 files changed, 17 insertions(+), 18 deletions(-)
diff --git a/cmk_base/config.py b/cmk_base/config.py
index cc65ed1..9920e9d 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -736,21 +736,6 @@ def get_additional_ipaddresses_of(hostname):
host_attributes.get(hostname, {}).get("additional_ipv6addresses",
[]))
-def parents_of(hostname):
- # type: (str) -> List[str]
- config_cache = get_config_cache()
- par = config_cache.host_extra_conf(hostname, parents)
- # Use only those parents which are defined and active in
- # all_hosts.
- used_parents = []
- for p in par:
- ps = p.split(",")
- for pss in ps:
- if pss in config_cache.all_active_realhosts():
- used_parents.append(pss)
- return used_parents
-
-
#
# Management board
#
@@ -2490,6 +2475,7 @@ class HostConfig(object):
self.alias = self._get_alias()
self.is_cluster = self._is_cluster()
self.part_of_clusters = self._config_cache.clusters_of(hostname)
+ self.parents = self._get_parents()
# TODO: Rename self.tags to self.tag_list and self.tag_groups to self.tags
self.tags = self._config_cache.tag_list_of_host(self.hostname)
@@ -2570,6 +2556,16 @@ class HostConfig(object):
return aliases[0]
+ def _get_parents(self):
+ # type: () -> List[str]
+ """Use only those parents which are defined and active in
all_hosts"""
+ used_parents = []
+ for parent_names in self._config_cache.host_extra_conf(self.hostname, parents):
+ for parent_name in parent_names.split(","):
+ if parent_name in self._config_cache.all_active_realhosts():
+ used_parents.append(parent_name)
+ return used_parents
+
def _get_host_labels(self):
"""Returns the effective set of host labels from all available
sources
diff --git a/cmk_base/core_nagios.py b/cmk_base/core_nagios.py
index d879052..b390a58 100644
--- a/cmk_base/core_nagios.py
+++ b/cmk_base/core_nagios.py
@@ -236,7 +236,7 @@ def _create_nagios_host_spec(cfg, config_cache, hostname, attrs):
config.extra_host_conf.get("parents", []))
if not extra_conf_parents:
- parents_list = config.parents_of(hostname)
+ parents_list = host_config.parents
if parents_list:
host_spec["parents"] = ",".join(parents_list)
diff --git a/cmk_base/dump_host.py b/cmk_base/dump_host.py
index 202da44..7219d50 100644
--- a/cmk_base/dump_host.py
+++ b/cmk_base/dump_host.py
@@ -84,7 +84,7 @@ def dump_host(hostname):
if host_config.is_cluster:
parents_list = config.nodes_of(hostname)
else:
- parents_list = config.parents_of(hostname)
+ parents_list = host_config.parents
if len(parents_list) > 0:
console.output(tty.yellow + "Parents: " + tty.normal +
", ".join(parents_list) + "\n")
diff --git a/cmk_base/parent_scan.py b/cmk_base/parent_scan.py
index 0da264d..3f888b1 100644
--- a/cmk_base/parent_scan.py
+++ b/cmk_base/parent_scan.py
@@ -82,8 +82,11 @@ def do_scan_parents(hosts):
while len(chunk) < config.max_num_processes and len(hosts) > 0:
host = hosts[0]
del hosts[0]
+
+ host_config = config_cache.get_host_config(host)
+
# skip hosts that already have a parent
- if config.parents_of(host):
+ if host_config.parents:
console.verbose("(manual parent) ")
continue
chunk.append(host)