Module: check_mk
Branch: master
Commit: 132abde4dde991677b960c2db8884bd74490927d
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=132abde4dde991…
Author: Andreas Boesl <ab(a)mathias-kettner.de>
Date: Fri Jan 29 13:12:52 2016 +0100
#2986 FIX Event Console: Text elements of events are now correctly quoted in shell
scripts
Text elements (message, comment, contact, etc.) of an event may contain
<i>'</i> and <i>"</i>.
The previous event console had troubles evaluating these event. Some shell scripts even
got stuck..
For example: <tt>TEXT=my"text</tt><br>
Shell script: <tt>echo $TEXT$ > /tmp/mylog</tt><br>
The actual command looks like <tt>echo my"text >
/tmp/mylog</tt><br> -> broken command.
---
.werks/2986 | 15 +++++++++++++++
ChangeLog | 1 +
mkeventd/bin/mkeventd | 25 ++++++++++++++++++++++++-
3 files changed, 40 insertions(+), 1 deletion(-)
diff --git a/.werks/2986 b/.werks/2986
new file mode 100644
index 0000000..f3c4d1a
--- /dev/null
+++ b/.werks/2986
@@ -0,0 +1,15 @@
+Title: Event Console: Text elements of events are now correctly quoted in shell scripts
+Level: 1
+Component: ec
+Compatible: compat
+Version: 1.2.7i4
+Date: 1454069066
+Class: fix
+
+Text elements (message, comment, contact, etc.) of an event may contain
<i>'</i> and <i>"</i>.
+The previous event console had troubles evaluating these event. Some shell scripts even
got stuck..
+
+For example: <tt>TEXT=my"text</tt><br>
+Shell script: <tt>echo $TEXT$ > /tmp/mylog</tt><br>
+The actual command looks like <tt>echo my"text >
/tmp/mylog</tt><br> -> broken command.
+
diff --git a/ChangeLog b/ChangeLog
index 349c8a0..d36d1da 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -342,6 +342,7 @@
* 2795 FIX: mkeventd: send email action did not work if message text contains
umlauts...
* 2862 FIX: Fixed handling of umlauts in mails send by the EC
* 2893 FIX: Improved error handling of sending mails via Event Console
+ * 2986 FIX: Event Console: Text elements of events are now correctly quoted in shell
scripts...
Livestatus:
* 2743 FIX: Fixed handling of column types in "GET columns"...
diff --git a/mkeventd/bin/mkeventd b/mkeventd/bin/mkeventd
index 088961c..5b5471d 100755
--- a/mkeventd/bin/mkeventd
+++ b/mkeventd/bin/mkeventd
@@ -3253,6 +3253,29 @@ def do_event_actions(actions, event, is_cancelling):
# Rule actions are currently done synchronously. Actions should
# not hang for more than a couple of ms.
+
+def get_quoted_event(event):
+ new_event = {}
+ fields_to_quote = [ "application", "match_groups",
"text", "comment", "contact" ]
+ for key, value in event.items():
+ if key not in fields_to_quote:
+ new_event[key] = value
+ else:
+ try:
+ if type(value) in [list, tuple]:
+ new_value = map(quote_shell_string, value)
+ if type(value) == tuple:
+ new_value = tuple(value)
+ else:
+ new_value = quote_shell_string(value)
+ new_event[key] = new_value
+ except Exception, e:
+ # If anything unforeseen happens, we use the intial value
+ new_event[key] = value
+ log("Unable to quote event text %r: %r, %r" % (key,value, e))
+
+ return new_event
+
def do_event_action(action, event, user=""):
if action["disabled"]:
log("Skipping disabled action %s." % action["id"])
@@ -3267,7 +3290,7 @@ def do_event_action(action, event, user=""):
send_email(to, subject, body)
log_event_history(event, "EMAIL", user, "%s|%s" % (to,
subject))
elif action_type == 'script':
- execute_script(substitute_event_tags(settings["script"], event))
+ execute_script(substitute_event_tags(settings["script"],
get_quoted_event(event)))
log_event_history(event, "SCRIPT", user, action['id'])
else:
log("Cannot execute action %s: invalid action type %s" %
(action["id"], action_type))