Module: check_mk
Branch: master
Commit: 52a5b426a11220cbc398dad80b1931b1a4eafbe4
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=52a5b426a11220…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Jan 12 12:00:24 2017 +0100
4276 Actions can now access the event macros via environment variables
In previous versios the actions of the Event Console could only get the
variables of the events via substitution of macros.
These information are now also available as environment variables with
the prefix <tt>EVENT_</tt>. For example the text of the event is available as
<tt>EVENT_TEXT</tt> as environment variable.
Change-Id: I2b0535af5415fbd865b261bf8e3010059e9610ea
---
.werks/4276 | 14 ++++++++++++++
ChangeLog | 1 +
bin/mkeventd | 35 ++++++++++++++++++++++++++---------
web/plugins/wato/mkeventd.py | 9 ++++++++-
4 files changed, 49 insertions(+), 10 deletions(-)
diff --git a/.werks/4276 b/.werks/4276
new file mode 100644
index 0000000..644b9b8
--- /dev/null
+++ b/.werks/4276
@@ -0,0 +1,14 @@
+Title: Actions can now access the event macros via environment variables
+Level: 1
+Component: ec
+Compatible: compat
+Version: 1.4.0i4
+Date: 1484218737
+Class: feature
+
+In previous versios the actions of the Event Console could only get the
+variables of the events via substitution of macros.
+
+These information are now also available as environment variables with
+the prefix <tt>EVENT_</tt>. For example the text of the event is available as
+<tt>EVENT_TEXT</tt> as environment variable.
diff --git a/ChangeLog b/ChangeLog
index 1d8cd99..2f56990 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -93,6 +93,7 @@
Event Console:
* 4154 Do not send notifications if host found and currently in downtime...
NOTE: Please refer to the migration notes!
+ * 4276 Actions can now access the event macros via environment variables...
* 4155 FIX: Do not perform actions on events if overflow limit is active...
* 4156 FIX: Fix off-by-one error in EC limit handling...
* 4199 FIX: Fix detection of replication mode if EC is distributed...
diff --git a/bin/mkeventd b/bin/mkeventd
index 171ff3d..8461815 100755
--- a/bin/mkeventd
+++ b/bin/mkeventd
@@ -112,6 +112,7 @@ event_columns = [
( "event_match_groups", "" ),
( "event_contact_groups", "" ),
( "event_ipaddress", "" ), # introduced in 1.2.7
+ ( "event_orig_host", "" ),
]
grepping_filters = [
@@ -3858,7 +3859,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(escape_null_bytes(substitute_event_tags(settings["script"], get_quoted_event(event))))
+ execute_script(escape_null_bytes(substitute_event_tags(settings["script"], get_quoted_event(event))), event)
log_event_history(event, "SCRIPT", user, action['id'])
else:
log("Cannot execute action %s: invalid action type %s" % (action["id"], action_type))
@@ -3868,7 +3869,7 @@ def do_event_action(action, event, user=""):
log("Error during execution of action %s: %s" % (action["id"], format_exception()))
-def substitute_event_tags(text, event):
+def get_event_tags(event):
substs = [("match_group_%d" % (nr+1), g)
for (nr, g)
in enumerate(event.get("match_groups", ()))]
@@ -3881,14 +3882,22 @@ def substitute_event_tags(text, event):
if type(v) in [ str, unicode ]:
return v
else:
- return str(v)
+ return "%s" % v
+ tags = {}
for key, value in substs:
if type(value) == tuple:
value = " ".join(map(to_string, value))
else:
value = to_string(value)
+ tags[key] = value
+
+ return tags
+
+
+def substitute_event_tags(text, event):
+ for key, value in get_event_tags(event).items():
text = text.replace('$%s$' % key.upper(), value)
return text
@@ -3923,7 +3932,16 @@ def send_email(to, subject, body):
return True
-def execute_script(body):
+def execute_script(body, event):
+ script_env = os.environ.copy()
+
+ for key, value in get_event_tags(event).items():
+ if type(key) == unicode:
+ key = key.encode("utf-8")
+ if type(value) == unicode:
+ value = value.encode("utf-8")
+ script_env["EVENT_" + key.upper()] = value
+
# Traps can contain 0-Bytes. We need to remove this from the script
# body. Otherwise suprocess.Popen will crash.
p = subprocess.Popen(
@@ -3931,12 +3949,11 @@ def execute_script(body):
shell = True,
executable = '/bin/bash',
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
- close_fds=True
+ close_fds=True,
+ env = script_env,
)
- output = p.stdout.read()
- exitcode = p.wait()
-
- log(' Exitcode: %d' % exitcode)
+ output = p.communicate()[0]
+ log(' Exitcode: %d' % p.returncode)
if output:
log(' Output: %s' % output)
diff --git a/web/plugins/wato/mkeventd.py b/web/plugins/wato/mkeventd.py
index 67fd8dd..bbab703 100644
--- a/web/plugins/wato/mkeventd.py
+++ b/web/plugins/wato/mkeventd.py
@@ -48,6 +48,7 @@ mkeventd_status_file = cmk.paths.omd_root + "/var/mkeventd/status"
# '----------------------------------------------------------------------'
substitute_help = _("""
The following macros will be substituted by value from the actual event:
+<br><br>
<table class=help>
<tr><td class=tt>$ID$</td><td>Event ID</td></tr>
<tr><td class=tt>$COUNT$</td><td>Number of occurrances</td></tr>
@@ -57,6 +58,7 @@ The following macros will be substituted by value from the actual event:
<tr><td class=tt>$COMMENT$</td><td>Event comment</td></tr>
<tr><td class=tt>$SL$</td><td>Service Level</td></tr>
<tr><td class=tt>$HOST$</td><td>Host name (as sent by syslog)</td></tr>
+<tr><td class=tt>$ORIG_HOST$</td><td>Original host name when host name has been rewritten, empty otherwise</td></tr>
<tr><td class=tt>$CONTACT$</td><td>Contact information</td></tr>
<tr><td class=tt>$APPLICATION$</td><td>Syslog tag / Application</td></tr>
<tr><td class=tt>$PID$</td><td>Process ID of the origin process</td></tr>
@@ -176,7 +178,12 @@ vs_mkeventd_actions = \
( "script",
TextAreaUnicode(
title = _("Script body"),
- help = _("This script will be executed using the BASH shell. ") + substitute_help,
+ help = _("This script will be executed using the BASH shell. ") \
+ + substitute_help \
+ + "<br>" \
+ + _("These information are also available as environment variables with the prefix "
+ "<tt>EVENT_</tt>. For example the text of the event is available as "
+ "<tt>EVENT_TEXT</tt> as environment variable."),
cols = 64,
rows = 10,
attrencode = True,
Module: check_mk
Branch: master
Commit: 6b3f2f3ce33e83b33a0eb4a3aa9dfce639f2c988
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6b3f2f3ce33e83…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Jan 12 12:01:55 2017 +0100
4277 Script actions: New event macro ORIG_HOST
The scripts can now access a macros $ORIG_HOST$ (or environment var EVENT_ORIG_HOST)
to get the original host name when host name has been rewritten. The value is empty
when not doing host name rewrite.
Change-Id: I6ca609383e1cc085af0d1716e5a021c0f46fb4f3
---
.werks/4277 | 11 +++++++++++
ChangeLog | 1 +
2 files changed, 12 insertions(+)
diff --git a/.werks/4277 b/.werks/4277
new file mode 100644
index 0000000..b842a47
--- /dev/null
+++ b/.werks/4277
@@ -0,0 +1,11 @@
+Title: Script actions: New event macro ORIG_HOST
+Level: 1
+Component: ec
+Compatible: compat
+Version: 1.4.0i4
+Date: 1484218852
+Class: feature
+
+The scripts can now access a macros $ORIG_HOST$ (or environment var EVENT_ORIG_HOST)
+to get the original host name when host name has been rewritten. The value is empty
+when not doing host name rewrite.
diff --git a/ChangeLog b/ChangeLog
index 2f56990..5919c17 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -94,6 +94,7 @@
* 4154 Do not send notifications if host found and currently in downtime...
NOTE: Please refer to the migration notes!
* 4276 Actions can now access the event macros via environment variables...
+ * 4277 Script actions: New event macro ORIG_HOST...
* 4155 FIX: Do not perform actions on events if overflow limit is active...
* 4156 FIX: Fix off-by-one error in EC limit handling...
* 4199 FIX: Fix detection of replication mode if EC is distributed...
Module: check_mk
Branch: master
Commit: 945543eb384346669c7b832d8f37a709c6ac5dff
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=945543eb384346…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Jan 12 09:41:41 2017 +0100
Updated bug entries #2471
Change-Id: Ic54d17ee657357ba83bb66884e8a32b2e75a9d9a
---
.bugs/2471 | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/.bugs/2471 b/.bugs/2471
index 67cb037..564e4a8 100644
--- a/.bugs/2471
+++ b/.bugs/2471
@@ -1,10 +1,12 @@
Title: Sidebar slow on new apache process because of werk loading
Component: multisite
-State: open
+Class: bug
+State: done
Date: 2016-09-28 11:33:19
Targetversion: 1.2.8
-Class: bug
When rendering the side bar for the first time in a new apache process, all werk files
are loaded which seem to take a lot of time in some installations. This should be
optimized.
+
+2017-01-12 09:41:39: changed state open -> done
Module: check_mk
Branch: master
Commit: 6d8d54036c7f4246ffdf0155befa90c49957cf17
URL: http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=6d8d54036c7f42…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Thu Jan 12 07:59:28 2017 +0100
Updated bug entries #2490
Change-Id: Iecf3f5017ad58feb380c9b0e311ea5d689380aaf
---
.bugs/2490 | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/.bugs/2490 b/.bugs/2490
index 4769b8f..7f3118e 100644
--- a/.bugs/2490
+++ b/.bugs/2490
@@ -1,9 +1,11 @@
Title: Buttons for downtimes (e.g. "This week") noch localized
Component: multisite
-State: open
+Class: bug
+State: done
Date: 2016-05-04 11:07:20
Targetversion: future
-Class: bug
Since this is now configured via a global option the translation does not
work anymore. Maybe we need to use the user_localizations for this.
+
+2017-01-12 07:59:24: changed state open -> done