Module: check_mk
Branch: master
Commit: 36c1927d2a1e2c8365f9eedae502ea3c0445f15e
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=36c1927d2a1e2c…
Author: Tom Baerwinkel <tb(a)mathias-kettner.de>
Date: Thu Mar 21 16:14:09 2019 +0100
7068 FIX Truncate values of the notification context which are too long
If the the value stored in the notification context was larger than
the OS limit MAX_ARG_STRLEN a failed notification was produced and
the error 'OSError: [Errno 7] Argument list too long' appeared in
the notify.log. This was usually the case for very long values in
the long outputs of a service like e.g. fileinfo.groups. Now the
values are truncated and the text 'Attention: Removed remaining
content because it was too long.' is shown at the end.
Change-Id: I726dc536378f54da5dccf624d551b1565ecf0d47
---
.werks/7068 | 16 ++++++++++++++++
cmk_base/notify.py | 35 +++++++++++++++++++++--------------
2 files changed, 37 insertions(+), 14 deletions(-)
diff --git a/.werks/7068 b/.werks/7068
new file mode 100644
index 0000000..3bfc58b
--- /dev/null
+++ b/.werks/7068
@@ -0,0 +1,16 @@
+Title: Truncate values of the notification context which are too long
+Level: 1
+Component: notifications
+Compatible: compat
+Edition: cre
+Version: 1.6.0i1
+Date: 1553180240
+Class: fix
+
+If the the value stored in the notification context was larger than
+the OS limit MAX_ARG_STRLEN a failed notification was produced and
+the error 'OSError: [Errno 7] Argument list too long' appeared in
+the notify.log. This was usually the case for very long values in
+the long outputs of a service like e.g. fileinfo.groups. Now the
+values are truncated and the text 'Attention: Removed remaining
+content because it was too long.' is shown at the end.
diff --git a/cmk_base/notify.py b/cmk_base/notify.py
index f669089..94f90ea 100755
--- a/cmk_base/notify.py
+++ b/cmk_base/notify.py
@@ -1310,18 +1310,6 @@ def path_to_notification_script(plugin):
#
# Note: this function is *not* being called for bulk notification.
def call_notification_script(plugin, plugin_context):
- # FIXME: This is a temporary workaround to avoid a possible crash of
- # subprocess.Popen when a crash dump occurs. Since in this case the
- # LONGSERVICEOUTPUT and LONGSERVICEOUTPUT_HTML contain very long base64
- # encoded strings an 'OSError: [Errno 7] Argument list too long' may
- # occur. To avoid this we replace the base64 encoded strings here.
- if plugin_context.get('LONGSERVICEOUTPUT', '').startswith('Crash
dump:\\n'):
- plugin_context[
- 'LONGSERVICEOUTPUT'] = u'Check failed:\\nA crash report can be
submitted via the user interface.'
- if plugin_context.get('LONGSERVICEOUTPUT_HTML',
'').startswith('Crash dump:\\n'):
- plugin_context[
- 'LONGSERVICEOUTPUT_HTML'] = u'Check failed:\\nA crash report can
be submitted via the user interface.'
-
core_notification_log(plugin, plugin_context)
def plugin_log(s):
@@ -1374,8 +1362,27 @@ def call_notification_script(plugin, plugin_context):
# Construct the environment for the notification script
def notification_script_env(plugin_context):
- return dict(os.environ.items() +
- [("NOTIFY_" + k, v.encode("utf-8")) for k, v in
plugin_context.items()])
+ # Use half of the maximum allowed string length MAX_ARG_STRLEN
+ # which is usually 32 pages on Linux (see "man execve").
+ #
+ # Assumption: We don't have to consider ARG_MAX, i.e. the maximum
+ # size of argv + envp, because it is derived from RLIMIT_STACK
+ # and large enough.
+ try:
+ max_length = 32 * os.sysconf("SC_PAGESIZE") // 2
+ except ValueError:
+ max_length = 32 * 4046 // 2
+
+ def format_(value):
+ if len(value) > max_length:
+ value = value[:max_length] + "...\nAttention: Removed remaining content
because it was too long."
+ return value.encode("utf-8")
+
+ notify_env = {
+ "NOTIFY_" + variable: format_(value) for variable, value in
plugin_context.iteritems()
+ }
+ notify_env.update(os.environ)
+ return notify_env
class NotificationTimeout(Exception):