Skip to content
Permalink
Browse files

refined new host regex functions

  • Loading branch information
Bastian-Kuhn committed Feb 27, 2014
1 parent ae1d167 commit aeb8ab49a281cd92b27b2ee8a921f4abf179238d
Showing with 33 additions and 10 deletions.
  1. +1 −1 modules/check_mk.py
  2. +32 −9 web/htdocs/wato.py
@@ -1871,7 +1871,7 @@ def in_extraconf_hostlist(hostlist, hostname):
if not use_regex and hostname == hostentry:
return not negate
# Handle Regex
elif re.match(regex(hostentry), hostname):
elif regex(hostentry).match(hostname):
return not negate
except MKGeneralException:
if opt_debug:
raise MKGeneralException(_("Invalid rule <tt>%s</tt>") % (orig_rule,))



def rule_matches_host_and_item(rulespec, tag_specs, host_list, item_list,
rule_folder, host_folder, hostname, item):
reasons = []
host = host_folder[".hosts"][hostname]
hostname_match = False
negate = False
regex_match = False

for check_host in host_list:
if hostname == check_host:
hostname_match = True
break
else:
if check_host[0] == '!':
check_host = check_host[1:]
negate = True
if check_host[0] == '~':
check_host = check_host[1:]
regex_match = True

if not regex_match and hostname == check_host:
if negate:
break
hostname_match = True
break
elif regex_match and regex(check_host).match(hostname):
if negate:
break
hostname_match = True
break

# No Match until now, but negate, so thats a match
if negate:
hostname_match = True
break

if not (
(hostname in host_list)
or
(("!"+hostname) not in host_list
and len(host_list) > 0
and host_list[-1] == ALL_HOSTS[0])
or len([ x for x in host_list if x.startswith('~') and re.match(x[1:], hostname) ]) > 0):
reasons.append(_("The host name does not match."))
if not hostname_match:
reasons.append(_("The host name does not match."))

tags_match = True
for tag in tag_specs:

0 comments on commit aeb8ab4

Please sign in to comment.
You can’t perform that action at this time.