Module: check_mk
Branch: master
Commit: 179b01b69be7b15d283f23de78ab027facd17faf
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=179b01b69be7b1…
Author: Sebastian Herbord <sh(a)mathias-kettner.de>
Date: Wed Jun 22 15:00:32 2016 +0200
3146 FIX notification scripts will now also timeout when sending a bulk notification
Werk #2843 introduced a timeout for notification scripts, as a single long-running
notification
could stall the whole notification system.
That werk only affected regular notifications, not bulk notifications. This is now
rectified
---
.werks/3146 | 12 ++++++++++++
ChangeLog | 1 +
modules/notify.py | 29 ++++++++++++++++++++++-------
3 files changed, 35 insertions(+), 7 deletions(-)
diff --git a/.werks/3146 b/.werks/3146
new file mode 100644
index 0000000..8a73254
--- /dev/null
+++ b/.werks/3146
@@ -0,0 +1,12 @@
+Title: notification scripts will now also timeout when sending a bulk notification
+Level: 1
+Component: notifications
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.4.0i1
+Date: 1466600205
+
+Werk #2843 introduced a timeout for notification scripts, as a single long-running
notification
+could stall the whole notification system.
+That werk only affected regular notifications, not bulk notifications. This is now
rectified
diff --git a/ChangeLog b/ChangeLog
index 94947ab..78a8e79 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -458,6 +458,7 @@
NOTE: Please refer to the migration notes!
* 3426 FIX: sms: fixed wrong message handling after message was quoted and therefore
too long
* 3139 FIX: fixed a couple of minor issues in call to notification scripts...
+ * 3146 FIX: notification scripts will now also timeout when sending a bulk
notification...
BI:
* 3271 New option in aggregation for tuning aggregation of downtimes...
diff --git a/modules/notify.py b/modules/notify.py
index fbe7ffc..5407020 100644
--- a/modules/notify.py
+++ b/modules/notify.py
@@ -1528,13 +1528,28 @@ def call_bulk_notification_script(plugin, context_text):
if not path:
raise MKGeneralException("Notification plugin %s not found" % plugin)
- # Protocol: The script gets the context on standard input and
- # read until that is closed. It is being called with the parameter
- # --bulk.
- p = subprocess.Popen([path, "--bulk"], shell=False,
- stdout = subprocess.PIPE, stderr = subprocess.PIPE, stdin =
subprocess.PIPE)
- stdout_txt, stderr_txt = p.communicate(context_text.encode("utf-8"))
- exitcode = p.returncode
+ stdout_txt = stderr_txt = ""
+ try:
+ set_notification_timeout()
+
+ # Protocol: The script gets the context on standard input and
+ # read until that is closed. It is being called with the parameter
+ # --bulk.
+ p = subprocess.Popen([path, "--bulk"], shell=False,
+ stdout = subprocess.PIPE, stderr = subprocess.PIPE,
+ stdin = subprocess.PIPE)
+
+ stdout_txt, stderr_txt = p.communicate(context_text.encode("utf-8"))
+ exitcode = p.returncode
+
+ clear_notification_timeout()
+ except NotificationTimeout:
+ notify_log("Notification plugin did not finish within %d seconds.
Terminating." %
+ notification_plugin_timeout)
+ # p.kill() requires python 2.6!
+ os.kill(p.pid, signal.SIGTERM)
+ exitcode = 1
+
if exitcode:
notify_log("ERROR: script %s --bulk returned with exit code %s" %
(path, exitcode))
for line in (stdout_txt + stderr_txt).splitlines():