Module: check_mk
Branch: master
Commit: 928ca9d5b8ee6b086f6b7d6dc6773306e24da2a4
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=928ca9d5b8ee6b…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Apr 15 20:18:48 2019 +0200
Cleanup all direct config.in_binary_hostlist calls
Change-Id: I5a8331717f13de010c9324afb3073199bdfe539f
---
cmk_base/check_api.py | 4 +++-
cmk_base/config.py | 30 +++++++++++++++++++-----------
cmk_base/ip_lookup.py | 6 ++++--
cmk_base/parent_scan.py | 4 +++-
cmk_base/snmp_scan.py | 3 ++-
5 files changed, 31 insertions(+), 16 deletions(-)
diff --git a/cmk_base/check_api.py b/cmk_base/check_api.py
index ff08847..274bdd1 100644
--- a/cmk_base/check_api.py
+++ b/cmk_base/check_api.py
@@ -211,7 +211,9 @@ def host_extra_conf(hostname, ruleset):
return _config.get_config_cache().host_extra_conf(hostname, ruleset)
-in_binary_hostlist = _config.in_binary_hostlist
+# Compatibility wrapper for the pre 1.6 existant conf.service_extra_conf()
+def in_binary_hostlist(hostname, ruleset):
+ return _config.get_config_cache().in_binary_hostlist(hostname, ruleset)
# Compatibility wrapper for the pre 1.6 existant conf.host_extra_conf_merged()
diff --git a/cmk_base/config.py b/cmk_base/config.py
index 2346751..b37f010 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -699,6 +699,8 @@ def all_active_hosts_with_duplicates():
# Returns a set of active hosts for this site
def filter_active_hosts(hostlist, keep_offline_hosts=False, keep_duplicates=False):
+ config_cache = get_config_cache()
+
if only_hosts is None and distributed_wato_site is None:
active_hosts = hostlist
@@ -713,13 +715,14 @@ def filter_active_hosts(hostlist, keep_offline_hosts=False,
keep_duplicates=Fals
active_hosts = hostlist
else:
active_hosts = [
- hostname for hostname in hostlist if in_binary_hostlist(hostname,
only_hosts)
+ hostname for hostname in hostlist
+ if config_cache.in_binary_hostlist(hostname, only_hosts)
]
else:
active_hosts = [
hostname for hostname in hostlist
- if (keep_offline_hosts or in_binary_hostlist(hostname, only_hosts)) and
+ if (keep_offline_hosts or config_cache.in_binary_hostlist(hostname,
only_hosts)) and
host_is_member_of_site(hostname, distributed_wato_site)
]
@@ -748,16 +751,25 @@ def duplicate_hosts():
#
# This is not optimized for performance, so use in specific situations.
def all_offline_hosts():
+ config_cache = get_config_cache()
+
hostlist = filter_active_hosts(
all_configured_realhosts().union(all_configured_clusters()),
keep_offline_hosts=True)
- return [hostname for hostname in hostlist if not in_binary_hostlist(hostname,
only_hosts)]
+ return [
+ hostname for hostname in hostlist
+ if not config_cache.in_binary_hostlist(hostname, only_hosts)
+ ]
def all_configured_offline_hosts():
+ config_cache = get_config_cache()
hostlist = all_configured_realhosts().union(all_configured_clusters())
- return set([hostname for hostname in hostlist if not in_binary_hostlist(hostname,
only_hosts)])
+ return set([
+ hostname for hostname in hostlist
+ if not config_cache.in_binary_hostlist(hostname, only_hosts)
+ ])
#.
@@ -1003,7 +1015,7 @@ def snmp_port_of(hostname):
def is_bulkwalk_host(hostname):
# type: (str) -> bool
if bulkwalk_hosts:
- return in_binary_hostlist(hostname, bulkwalk_hosts)
+ return get_config_cache().in_binary_hostlist(hostname, bulkwalk_hosts)
return False
@@ -1017,7 +1029,7 @@ def bulk_walk_size_of(hostname):
def is_snmpv2or3_without_bulkwalk_host(hostname):
- return in_binary_hostlist(hostname, snmpv2c_hosts)
+ return get_config_cache().in_binary_hostlist(hostname, snmpv2c_hosts)
# TODO: Replace call sites with HostConfig access and remove this
@@ -1029,7 +1041,7 @@ def is_inline_snmp_host(hostname):
# TODO: Better use "inline_snmp" once we have moved the code to an own
module
has_inline_snmp = "netsnmp" in sys.modules
return has_inline_snmp and use_inline_snmp \
- and not in_binary_hostlist(hostname, non_inline_snmp_hosts)
+ and not get_config_cache().in_binary_hostlist(hostname,
non_inline_snmp_hosts)
#
@@ -1617,10 +1629,6 @@ def in_extraconf_hostlist(hostlist, hostname):
return False
-def in_binary_hostlist(hostname, conf):
- return get_config_cache().in_binary_hostlist(hostname, conf)
-
-
def parse_host_rule(rule):
rule, rule_options = get_rule_options(rule)
diff --git a/cmk_base/ip_lookup.py b/cmk_base/ip_lookup.py
index 36621e4..1bd9f9c 100644
--- a/cmk_base/ip_lookup.py
+++ b/cmk_base/ip_lookup.py
@@ -75,7 +75,9 @@ def lookup_ip_address(hostname, family=None):
if config.fake_dns:
return config.fake_dns
- host_config = config.get_config_cache().get_host_config(hostname)
+ config_cache = config.get_config_cache()
+
+ host_config = config_cache.get_host_config(hostname)
# Honor simulation mode und usewalk hosts. Never contact the network.
if config.simulation_mode or _enforce_localhost or \
@@ -96,7 +98,7 @@ def lookup_ip_address(hostname, family=None):
# Hosts listed in dyndns hosts always use dynamic DNS lookup.
# The use their hostname as IP address at all places
- if config.in_binary_hostlist(hostname, config.dyndns_hosts):
+ if config_cache.in_binary_hostlist(hostname, config.dyndns_hosts):
return hostname
return cached_dns_lookup(hostname, family)
diff --git a/cmk_base/parent_scan.py b/cmk_base/parent_scan.py
index cba42d6..3f787e3 100644
--- a/cmk_base/parent_scan.py
+++ b/cmk_base/parent_scan.py
@@ -45,10 +45,12 @@ import cmk_base.ip_lookup as ip_lookup
def do_scan_parents(hosts):
+ config_cache = config.get_config_cache()
+
if not hosts:
hosts = [
h for h in config.all_active_realhosts()
- if config.in_binary_hostlist(h, config.scanparent_hosts)
+ if config_cache.in_binary_hostlist(h, config.scanparent_hosts)
]
parent_hosts = []
diff --git a/cmk_base/snmp_scan.py b/cmk_base/snmp_scan.py
index 45fe57f..67961cb 100644
--- a/cmk_base/snmp_scan.py
+++ b/cmk_base/snmp_scan.py
@@ -74,7 +74,8 @@ def _snmp_scan(host_config,
snmp.initialize_single_oid_cache(host_config)
console.vverbose(" SNMP scan:\n")
- if not config.in_binary_hostlist(host_config.hostname,
config.snmp_without_sys_descr):
+ if not config.get_config_cache().in_binary_hostlist(host_config.hostname,
+ config.snmp_without_sys_descr):
for oid, name in [(".1.3.6.1.2.1.1.1.0", "system
description"),
(".1.3.6.1.2.1.1.2.0", "system object")]:
value = snmp.get_single_oid(host_config, oid, do_snmp_scan=do_snmp_scan)