Module: check_mk
Branch: master
Commit: b256a3fcb68e02816d9480818d2173d3bc7ceb34
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=b256a3fcb68e02…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Mon Mar 9 15:15:00 2015 +0100
Reverted try to improve regex performance (was not sufficient)
---
modules/check_mk.py | 49 ++-----------------------------------------------
modules/discovery.py | 4 ++--
2 files changed, 4 insertions(+), 49 deletions(-)
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 6343558..edbe621 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -1701,7 +1701,6 @@ def convert_service_ruleset(ruleset):
g_converted_rulesets_cache[id(ruleset)] = new_rules
return new_rules
-
# Compute outcome of a service rule set that has an item
def service_extra_conf(hostname, service, ruleset):
try:
@@ -1761,49 +1760,6 @@ def in_boolean_serviceconf_list(hostname, service_description,
ruleset):
return False # no match. Do not ignore
-def intelligent_regex_match(pattern, text):
- def is_regex(pattern):
- for c in pattern:
- if c in '*$|[':
- return True
- return False
-
- def is_infix_string_search(pattern):
- return pattern.startswith('.*') and not is_regex(pattern[2:])
-
- def is_exact_match(pattern):
- return pattern[-1] == '$' and not is_regex(pattern[:-1])
-
- if pattern == '':
- return True # empty patterns match always
-
- # FIXME: Autochecks contain UTF-8 encoded item strings
- if type(text) == str:
- text = text.decode('utf-8')
-
- if is_exact_match(pattern):
- # Exact string match
- return pattern[:-1] == text
-
- elif is_infix_string_search(pattern):
- # Using regex to search a substring within text
- return pattern[2:] in text
-
- elif is_regex(pattern):
- # Non specific regex. Use real prefix regex matching
- return regex(pattern).match(text) != None
-
- else:
- # prefix string match
- try:
- return text.startswith(pattern)
- except UnicodeDecodeError:
- # FIXME: items in autochecks might contain umlauts, the strings
- # are saved as UTF-8 encoded ascii strings. should be saved as
- # unicode strings in this case or at least converted after reading.
- return text.startswith(pattern)
-
-
# Entries in list are hostnames that must equal the hostname.
# Expressions beginning with ! are negated: if they match,
# the item is excluded from the list. Expressions beginning
@@ -1849,7 +1805,7 @@ def in_extraconf_hostlist(hostlist, hostname):
return not negate
# Handle Regex. Note: hostname == True -> generic unknown host
elif use_regex and hostname != True:
- if intelligent_regex_match(hostentry, hostname):
+ if regex(hostentry).match(hostname) != None:
return not negate
except MKGeneralException:
if opt_debug:
@@ -1868,7 +1824,7 @@ def in_extraconf_servicelist(servlist, item):
for pattern in servlist:
negate, pattern = parse_negated(pattern)
- if intelligent_regex_match(pattern, item):
+ if regex(pattern).match(item) != None:
g_extraconf_servicelist_cache[cache_id] = not negate
return not negate
@@ -4550,7 +4506,6 @@ def do_update(with_precompile):
raise
sys.exit(1)
-
def do_check_nagiosconfig():
if monitoring_core == 'nagios':
command = nagios_binary + " -vp " + nagios_config_file + "
2>&1"
diff --git a/modules/discovery.py b/modules/discovery.py
index 1c7008c..0b6630b 100644
--- a/modules/discovery.py
+++ b/modules/discovery.py
@@ -739,8 +739,8 @@ def read_autochecks_of(hostname, world="config"):
for entry in autochecks_raw:
if len(entry) == 4: # old format where hostname is at the first place
entry = entry[1:]
- ct, it, par = entry
- autochecks.append( (ct, it, compute_check_parameters(hostname, ct, it, par)) )
+ check_type, item, parameters = entry
+ autochecks.append((check_type, item, compute_check_parameters(hostname,
check_type, item, parameters)))
return autochecks