Module: check_mk
Branch: master
Commit: 161ad561173b20855b38a42ae030bb9af61114aa
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=161ad561173b20…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri May 3 12:14:13 2019 +0200
Cleanup ancient match case from in_binary_hostlist()
Change-Id: I2aad4699c428c2c6d69d557dec00adef8df4fb70
---
cmk_base/config.py | 74 +++++++++++++++++++++++++++---------------------------
1 file changed, 37 insertions(+), 37 deletions(-)
diff --git a/cmk_base/config.py b/cmk_base/config.py
index 2f1344e..dec2944 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -3633,47 +3633,47 @@ class ConfigCache(object):
except KeyError:
pass
- # if we have just a list of strings just take it as list of hostnames
if conf and isinstance(conf[0], str):
- result = hostname in conf
- cache[cache_id] = result
- else:
- 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
+ raise NotImplementedError("Unsupported ruleset found: %s. Please "
+ "remove the configuration in case you don't need it "
+ "anymore. Otherwise contact the checkMK team." % conf)
- 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
+ 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:
- 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
+ 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]
Module: check_mk
Branch: master
Commit: b05b41626ae07bdd74c3cca87242eb7e091ade3d
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b05b41626ae07b…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu May 2 20:55:49 2019 +0200
Move last host_extra_conf to cmk_base.config
* The agent bakery config computation is a bit special. The rule
matching logic has now been moved to cmk_base.config.
* Added tests for it
* The value merging logic remains in cmk_base.cee.agent_bakery for
the moment because it is based on the bakery plugins which should
be cleaned up in the near future.
CMK-2030
Change-Id: Icf06e4f2e50f403b8253e380bdfdcdb66a4a014b
---
cmk_base/config.py | 66 ++++++++++++++++++++++++++----------
tests/unit/cmk_base/test_rulesets.py | 9 +++--
2 files changed, 55 insertions(+), 20 deletions(-)
diff --git a/cmk_base/config.py b/cmk_base/config.py
index 0fa8ef9..2f1344e 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -1204,22 +1204,6 @@ def in_extraconf_hostlist(hostlist, hostname):
return False
-def parse_host_rule(rule):
- rule, rule_options = get_rule_options(rule)
-
- num_elements = len(rule)
- if num_elements == 2:
- item, hostlist = rule
- tags = []
- elif num_elements == 3:
- item, tags, hostlist = rule
- else:
- raise MKGeneralException("Invalid entry '%r' in host configuration list: must "
- "have 2 or 3 entries" % (rule,))
-
- return item, tags, hostlist, rule_options
-
-
def get_rule_options(entry):
"""Get the options from a rule.
@@ -3376,7 +3360,7 @@ class ConfigCache(object):
console.warning('deprecated entry [ "" ] in host configuration list')
for rule in ruleset:
- item, tags, hostlist, rule_options = parse_host_rule(rule)
+ item, tags, hostlist, rule_options = self._parse_host_rule(rule)
if rule_options.get("disabled"):
continue
@@ -3386,6 +3370,21 @@ class ConfigCache(object):
return new_rules
+ def _parse_host_rule(self, rule):
+ rule, rule_options = get_rule_options(rule)
+
+ num_elements = len(rule)
+ if num_elements == 2:
+ item, hostlist = rule
+ tags = []
+ elif num_elements == 3:
+ item, tags, hostlist = rule
+ else:
+ raise MKGeneralException("Invalid entry '%r' in host configuration list: must "
+ "have 2 or 3 entries" % (rule,))
+
+ return item, tags, hostlist, rule_options
+
def service_extra_conf(self, hostname, service, ruleset):
"""Compute outcome of a service rule set that has an item."""
# When the requested host is part of the local sites configuration,
@@ -3746,6 +3745,39 @@ class CEEConfigCache(ConfigCache):
return None
return entries[0]
+ # TODO: Cleanup the GENERIC_AGENT duplication with cmk_base.cee.agent_bakyery.GENERIC_AGENT
+ def matched_agent_config_entries(self, hostname):
+ # type: (Union[bool, str]) -> Dict[str, Any]
+ GENERIC_AGENT = True
+ matched = {}
+ for varname, ruleset in agent_config.items() + [("agent_port", agent_ports),
+ ("agent_encryption", agent_encryption)]:
+ if hostname is GENERIC_AGENT:
+ matched[varname] = self._generic_host_extra_conf(ruleset)
+ else:
+ matched[varname] = self.host_extra_conf(hostname, ruleset)
+
+ return matched
+
+ def _generic_host_extra_conf(self, ruleset):
+ """Compute ruleset for "generic" host
+
+ This fictious host has no name and no tags. It matches all rules that
+ do not require specific hosts or tags. But it matches rules that e.g.
+ except specific hosts or tags (is not, has not set)
+ """
+ entries = []
+
+ for rule in ruleset:
+ item, tags, hostlist = self._parse_host_rule(rule)[:-1]
+ if tags and not hosttags_match_taglist([], tags):
+ continue
+ if not in_extraconf_hostlist(hostlist, ""):
+ continue
+
+ entries.append(item)
+ return entries
+
# TODO: Find a clean way to move this to cmk_base.cee. This will be possible once the
# configuration settings are not held in cmk_base.config namespace anymore.
diff --git a/tests/unit/cmk_base/test_rulesets.py b/tests/unit/cmk_base/test_rulesets.py
index b3ef5e5..7654c0a 100644
--- a/tests/unit/cmk_base/test_rulesets.py
+++ b/tests/unit/cmk_base/test_rulesets.py
@@ -210,22 +210,25 @@ def test_in_extraconf_hostlist():
def test_parse_host_rule():
+ config_cache = config.get_config_cache()
options = {'description': u'Put all hosts into the contact group "all"'}
entry = ('all', [], config.ALL_HOSTS, options)
- assert config.parse_host_rule(entry) == ('all', [], config.ALL_HOSTS, options)
+ assert config_cache._parse_host_rule(entry) == ('all', [], config.ALL_HOSTS, options)
def test_parse_host_rule_without_tags():
+ config_cache = config.get_config_cache()
options = {'description': u'Put all hosts into the contact group "all"'}
entry = ('all', config.ALL_HOSTS, options)
- assert config.parse_host_rule(entry) == ('all', [], config.ALL_HOSTS, options)
+ assert config_cache._parse_host_rule(entry) == ('all', [], config.ALL_HOSTS, options)
def test_parse_host_rule_invalid_length():
+ config_cache = config.get_config_cache()
options = {'description': u'Put all hosts into the contact group "all"'}
entry = (None, None, 'all', config.ALL_HOSTS, options)
with pytest.raises(MKGeneralException):
- assert config.parse_host_rule(entry)
+ assert config_cache._parse_host_rule(entry)
def test_get_rule_options_regular_rule():
Module: check_mk
Branch: master
Commit: c309c7b794758866a88e04695428c74c72677dd0
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c309c7b7947588…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu May 2 11:09:26 2019 +0200
Move config.cmc_service_check_timeout processing to CEEConfigCache
CMK-2030
Change-Id: Ia334a6d82b89d19e0c42b417258e4f4fd3fe9ff8
---
cmk_base/config.py | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/cmk_base/config.py b/cmk_base/config.py
index 2b9a972..d6f177e 100644
--- a/cmk_base/config.py
+++ b/cmk_base/config.py
@@ -3695,6 +3695,15 @@ class CEEConfigCache(ConfigCache):
spec.update(entry)
return spec
+ def check_timeout_of_service(self, hostname, description):
+ # type: (str, Text) -> int
+ """Returns the check timeout in seconds"""
+ entries = self.service_extra_conf(hostname, description, cmc_service_check_timeout)
+ if not entries:
+ return cmc_check_timeout
+
+ return entries[0]
+
# TODO: Find a clean way to move this to cmk_base.cee. This will be possible once the
# configuration settings are not held in cmk_base.config namespace anymore.