Module: check_mk
Branch: master
Commit: b57350c265f0e53fb637fc22160e016870c13038
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b57350c265f0e5…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Mar 7 12:07:03 2017 +0100
Try to fix bug #2527
Change-Id: I4a64b847a9fa37399ae8fdabd2184f49df7c959f
---
modules/check_mk.py | 1 -
web/htdocs/watolib.py | 36 +++++++++++++++---------------------
2 files changed, 15 insertions(+), 22 deletions(-)
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 10ce0f7..5b41a29 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -1101,7 +1101,6 @@ def in_extraconf_hostlist(hostlist, hostname):
hostentry = hostentry[1:]
use_regex = True
- hostentry = hostentry
try:
if not use_regex and hostname == hostentry:
return not negate
diff --git a/web/htdocs/watolib.py b/web/htdocs/watolib.py
index 36fc386..bbaca75 100644
--- a/web/htdocs/watolib.py
+++ b/web/htdocs/watolib.py
@@ -6962,40 +6962,34 @@ class Rule(object):
def _matches_hostname(self, hostname):
- negate = False
- regex_match = False
- hostname_match = False
+ if not self.host_list:
+ return False # empty list of explicit host does never match
+
+ # Assume WATO conforming rule where either *all* or *none* of the
+ # host expressions are negated.
+ negate = self.host_list[0].startswith("!")
for check_host in self.host_list:
- if check_host == "@all" or hostname == check_host:
- hostname_match = True
- break
+ if check_host == "@all":
+ return not negate
- if check_host[0] == '!':
+ if check_host[0] == '!': # strip negate character
check_host = check_host[1:]
- negate = True
+
if check_host[0] == '~':
check_host = check_host[1:]
regex_match = True
+ else:
+ regex_match = False
if not regex_match and hostname == check_host:
- if negate:
- break
- hostname_match = True
- break
+ return not negate
elif regex_match and regex(check_host).match(hostname):
- if negate:
- break
- hostname_match = True
- break
+ return not negate
- # No Match until now, but negate, so thats a match
- if negate:
- hostname_match = True
- break
+ return not negate
- return hostname_match
def matches_item(self, item):