Module: check_mk
Branch: master
Commit: 01a225a8aac369013465a5a20edfdde344cc1e66
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=01a225a8aac369…
Author: Mathias Kettner <mk(a)mathias-kettner.de>
Date: Tue Feb 12 16:49:41 2013 +0100
FIX: support non-Ascii characters in matching expressions
Note: you need to edit and save each affected rule once in order
to make the fix work.
---
ChangeLog | 5 ++++
mkeventd/bin/mkeventd | 13 +++++++---
mkeventd/web/plugins/wato/mkeventd.py | 8 +++---
web/htdocs/valuespec.py | 43 +++++++++++++++++++++-----------
4 files changed, 46 insertions(+), 23 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index f7d89d1..b76cebd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,11 @@
BI:
* FIX: fix exception in BI-Boxes views of host groups
+ Event Console:
+ * FIX: support non-Ascii characters in matching expressions. Note:
+ you need to edit and save each affected rule once in order
+ to make the fix work.
+
1.2.2b1:
Core:
* cmk --notify: added notification script to generate HTML mails including
diff --git a/mkeventd/bin/mkeventd b/mkeventd/bin/mkeventd
index fa58bff..d020bb5 100755
--- a/mkeventd/bin/mkeventd
+++ b/mkeventd/bin/mkeventd
@@ -171,12 +171,15 @@ def regex(reg):
# neccessary to use regular expression logic in order
# to match it.
def is_regex(text):
- return text != text.translate(None, ".*?[](){}\\^$+|")
+ for c in text:
+ if c in ".*?[](){}\\^$+|":
+ return True
+ return False
def match(pattern, text, complete = True):
if pattern == None:
return True
- elif type(pattern) == str:
+ elif type(pattern) in [ str, unicode ]:
if complete:
return pattern == text.lower()
else:
@@ -1135,9 +1138,11 @@ class EventServer:
else:
rule[key] = rule[key].lower()
except Exception, e:
+ if opt_debug:
+ raise
rule["disabled"] = True
count_disabled += 1
- log("Ignoring rule %s because of an invalid regex (%s)." %
+ log("Ignoring rule '%s' because of an invalid regex (%s)." %
(rule["id"], e))
if g_config["rule_optimizer"]:
@@ -1231,7 +1236,7 @@ class EventServer:
g_event_status.count_rule_match(rule["id"])
if g_config["log_rulehits"]:
- log("Rule %s hit by message %s/%s - '%s'." % (
+ log("Rule '%s' hit by message %s/%s - '%s'." % (
rule["id"],
syslog_facilities[event["facility"]], syslog_priorities[event["priority"]],
event["text"]))
diff --git a/mkeventd/web/plugins/wato/mkeventd.py b/mkeventd/web/plugins/wato/mkeventd.py
index 6f59953..a622e7d 100644
--- a/mkeventd/web/plugins/wato/mkeventd.py
+++ b/mkeventd/web/plugins/wato/mkeventd.py
@@ -465,7 +465,7 @@ vs_mkeventd_rule = Dictionary(
),
),
( "match",
- RegExp(
+ RegExpUnicode(
title = _("Text to match"),
help = _("The rules does only apply when the given regular expression matches "
"the message text (infix search)."),
@@ -473,7 +473,7 @@ vs_mkeventd_rule = Dictionary(
)
),
( "match_host",
- RegExp(
+ RegExpUnicode(
title = _("Match host"),
help = _("The rules does only apply when the given regular expression matches "
"the host name the message originates from. Note: in some cases the "
@@ -481,7 +481,7 @@ vs_mkeventd_rule = Dictionary(
)
),
( "match_application",
- RegExp(
+ RegExpUnicode(
title = _("Match syslog application (tag)"),
help = _("Regular expression for matching the syslog tag (case insenstive)"),
)
@@ -521,7 +521,7 @@ vs_mkeventd_rule = Dictionary(
),
),
( "match_ok",
- RegExp(
+ RegExpUnicode(
title = _("Text to cancel event"),
help = _("If a matching message appears with this text, then an event created "
"by this rule will automatically be cancelled (if host, application and match groups match). "),
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index 9b8794b..00b5d0c 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -341,6 +341,20 @@ class TextAscii(ValueSpec):
if not self._regex.match(value):
raise MKUserError(varprefix, self._regex_error)
+class TextUnicode(TextAscii):
+ def __init__(self, **kwargs):
+ TextAscii.__init__(self, **kwargs)
+
+ def render_input(self, varprefix, value):
+ html.text_input(varprefix, value, size = self._size)
+
+ def from_html_vars(self, varprefix):
+ return html.var_utf8(varprefix, "").strip()
+
+ def validate_datatype(self, value, varprefix):
+ if type(value) not in [ str, unicode ]:
+ raise MKUserError(varprefix, _("The value must be of type str or unicode, but it has type %s") % type(value))
+
# Internal ID as used in many places (for contact names, group name,
# an so on)
class ID(TextAscii):
@@ -360,7 +374,20 @@ class RegExp(TextAscii):
try:
re.compile(value)
except sre_constants.error, e:
- raise MKUserError(varprefix, _('Invalid regex: %s') % e)
+ raise MKUserError(varprefix, _('Invalid regular expression: %s') % e)
+
+class RegExpUnicode(TextUnicode):
+ def __init__(self, **kwargs):
+ TextUnicode.__init__(self, attrencode = True, **kwargs)
+
+ def validate_value(self, value, varprefix):
+ TextUnicode.validate_value(self, value, varprefix)
+
+ # Check if the string is a valid regex
+ try:
+ re.compile(value)
+ except sre_constants.error, e:
+ raise MKUserError(varprefix, _('Invalid regular expression: %s') % e)
class EmailAddress(TextAscii):
def __init__(self, **kwargs):
@@ -466,20 +493,6 @@ class HTTPUrl(TextAscii):
url, text)
-class TextUnicode(TextAscii):
- def __init__(self, **kwargs):
- TextAscii.__init__(self, **kwargs)
-
- def render_input(self, varprefix, value):
- html.text_input(varprefix, value, size = self._size)
-
- def from_html_vars(self, varprefix):
- return html.var_utf8(varprefix, "").strip()
-
- def validate_datatype(self, value, varprefix):
- if type(value) not in [ str, unicode ]:
- raise MKUserError(varprefix, _("The value must be of type str or unicode, but it has type %s") % type(value))
-
class TextAreaUnicode(TextUnicode):
def __init__(self, **kwargs):
TextUnicode.__init__(self, **kwargs)