Module: check_mk
Branch: master
Commit: 83e3030ea6cde23722213419065cd1d7d1867694
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=83e3030ea6cde2…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Mon Mar 21 12:49:16 2016 +0100
New helper function generic_host_extra_conf
---
modules/check_mk.py | 51 ++++++++++++++++++++++++++++++++++++---------------
1 file changed, 36 insertions(+), 15 deletions(-)
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 280ea23..3287a46 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -709,20 +709,10 @@ def convert_host_ruleset(ruleset):
sys.stderr.write('WARNING: deprecated entry [ "" ] in host
configuration list\n')
for rule in ruleset:
- rule, rule_options = get_rule_options(rule)
+ item, tags, hostlist, rule_options = parse_host_rule(rule)
if rule_options.get("disabled"):
continue
- 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,))
-
# Directly compute set of all matching hosts here, this
# will avoid recomputation later
new_rules.append((item, all_matching_hosts(tags, hostlist,
with_foreign_hosts=True)))
@@ -739,14 +729,45 @@ def host_extra_conf(hostname, ruleset):
entries = []
for item, hostname_list in ruleset:
- # Hack for the agent bakery: The hostname may be "True" which is used
- # for the generic agent. When the hostname is True it should match
- # without conditions.
- if hostname == True or hostname in hostname_list:
+ if hostname in hostname_list:
entries.append(item)
return entries
+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
+
+
+# Needed for agent bakery: 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)
+def generic_host_extra_conf(ruleset):
+ entries = []
+
+ for rule in ruleset:
+ item, tags, hostlist, rule_options = parse_host_rule(rule)
+ if tags and not hosttags_match_taglist([], tags):
+ continue
+ if not in_extraconf_hostlist(hostlist, ""):
+ continue
+
+ entries.append(item)
+ return entries
+
+
def host_extra_conf_merged(hostname, conf):
rule_dict = {}
for rule in host_extra_conf(hostname, conf):