Module: check_mk
Branch: master
Commit: 78c084f689eb4d7e6483ab871d52d27b30cdd6db
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=78c084f689eb4d…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Apr 7 14:46:25 2015 +0200
Fix service rule execution for more complex regular expressions
e.g. such containing \ and +
---
.bugs/2298 | 8 ++++++--
modules/check_mk.py | 6 +++++-
2 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/.bugs/2298 b/.bugs/2298
index 037371d..6deab96 100644
--- a/.bugs/2298
+++ b/.bugs/2298
@@ -1,8 +1,12 @@
Title: Service Discovery Checks reports disabled services as new
Component: checks
-State: open
+Class: bug
+State: done
Date: 2015-04-01 14:03:37
Targetversion: 1.2.7
-Class: bug
error does not occur in 1.2.6, but in 2015-04-01
+
+2015-04-07 14:45:29: changed state open -> done
+Fixed. The detection for regular expressions was incomplete and just checked
+for the characters '*$|[', the complete list is now .?*+^$|[](){}\
diff --git a/modules/check_mk.py b/modules/check_mk.py
index 9382e32..69c674e 100755
--- a/modules/check_mk.py
+++ b/modules/check_mk.py
@@ -1686,9 +1686,11 @@ def get_rule_options(entry):
# This function tries to parse the pattern and return different kind of matching
# functions which can then be performed faster than just using the regex match.
def convert_pattern(pattern):
+ # TODO: Wouldn't it be faster to declare these functions in global scope
+ # i.e. only once?
def is_regex(pattern):
for c in pattern:
- if c in '*$|[':
+ if c in '.?*+^$|[](){}\\':
return True
return False
@@ -1717,6 +1719,7 @@ def convert_pattern(pattern):
elif is_prefix_match(pattern):
# prefix match with tailing .*
pattern = pattern[:-2]
+ # TODO: Should we not rather use startswith()?
return negate, lambda txt: txt[:len(pattern)] == pattern
elif is_regex(pattern):
@@ -1725,6 +1728,7 @@ def convert_pattern(pattern):
else:
# prefix match without any regex chars
+ # TODO: Should we not rather use startswith()?
return negate, lambda txt: txt[:len(pattern)] == pattern