Module: check_mk
Branch: master
Commit: 37e03b1a5c5348a7682d00f52f42cc2b47829b43
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=37e03b1a5c5348…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon May 6 09:29:31 2019 +0200
Minor cleanup: Move in_binary_hostlist to related methods
Change-Id: I431342e15861e6ee0ec5ec77440ec8b51beba9bf
---
cmk_base/config.py | 106 ++++++++++++++++++++++++++---------------------------
1 file changed, 53 insertions(+), 53 deletions(-)
diff --git a/cmk_base/config.py b/cmk_base/config.py
index 0c70683..9920e5c 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -3342,6 +3342,59 @@ class ConfigCache(object):
return self._host_extra_conf_match_cache[cache_id][hostname]
+ def in_binary_hostlist(self, hostname, conf):
+ cache = self._in_binary_hostlist_cache
+
+ cache_id = id(conf), hostname
+ try:
+ return cache[cache_id]
+ except KeyError:
+ pass
+
+ if conf and isinstance(conf[0], str):
+ raise NotImplementedError("Unsupported ruleset found: %s. Please "
+ "remove the configuration in case you
don't need it "
+ "anymore. Otherwise contact the checkMK
team." % conf)
+
+ for entry in conf:
+ actual_host_tags = self.tag_list_of_host(hostname)
+ entry, rule_options = get_rule_options(entry)
+ if rule_options.get("disabled"):
+ continue
+
+ try:
+ # Negation via 'NEGATE'
+ if entry[0] == NEGATE:
+ entry = entry[1:]
+ negate = True
+ else:
+ negate = False
+ # entry should be one-tuple or two-tuple. Tuple's elements are
+ # lists of strings. User might forget comma in one tuple. Then the
+ # entry is the list itself.
+ if isinstance(entry, list):
+ hostlist = entry
+ tags = []
+ else:
+ if len(entry) == 1: # 1-Tuple with list of hosts
+ hostlist = entry[0]
+ tags = []
+ else:
+ tags, hostlist = entry
+
+ if hosttags_match_taglist(actual_host_tags, tags) and \
+ in_extraconf_hostlist(hostlist, hostname):
+ cache[cache_id] = not negate
+ break
+ except:
+ # TODO: Fix this too generic catching (+ bad error message)
+ raise MKGeneralException("Invalid entry '%r' in host
configuration list: "
+ "must be tuple with 1 or 2 entries" %
(entry,))
+ else:
+ cache[cache_id] = False
+
+ return cache[cache_id]
+
def _convert_host_ruleset(self, ruleset, with_foreign_hosts):
new_rules = []
if len(ruleset) == 1 and ruleset[0] == "":
@@ -3612,59 +3665,6 @@ class ConfigCache(object):
return hostname
- def in_binary_hostlist(self, hostname, conf):
- cache = self._in_binary_hostlist_cache
-
- cache_id = id(conf), hostname
- try:
- return cache[cache_id]
- except KeyError:
- pass
-
- if conf and isinstance(conf[0], str):
- raise NotImplementedError("Unsupported ruleset found: %s. Please "
- "remove the configuration in case you
don't need it "
- "anymore. Otherwise contact the checkMK
team." % conf)
-
- for entry in conf:
- actual_host_tags = self.tag_list_of_host(hostname)
- entry, rule_options = get_rule_options(entry)
- if rule_options.get("disabled"):
- continue
-
- try:
- # Negation via 'NEGATE'
- if entry[0] == NEGATE:
- entry = entry[1:]
- negate = True
- else:
- negate = False
- # entry should be one-tuple or two-tuple. Tuple's elements are
- # lists of strings. User might forget comma in one tuple. Then the
- # entry is the list itself.
- if isinstance(entry, list):
- hostlist = entry
- tags = []
- else:
- if len(entry) == 1: # 1-Tuple with list of hosts
- hostlist = entry[0]
- tags = []
- else:
- tags, hostlist = entry
-
- if hosttags_match_taglist(actual_host_tags, tags) and \
- in_extraconf_hostlist(hostlist, hostname):
- cache[cache_id] = not negate
- break
- except:
- # TODO: Fix this too generic catching (+ bad error message)
- raise MKGeneralException("Invalid entry '%r' in host
configuration list: "
- "must be tuple with 1 or 2 entries" %
(entry,))
- else:
- cache[cache_id] = False
-
- return cache[cache_id]
-
def get_config_cache():
# type: () -> ConfigCache