Module: check_mk
Branch: master
Commit: dc82320b0511face6e4b5508bee4d750ae2e5254
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=dc82320b0511fa…
Author: Simon Betz <si(a)mathias-kettner.de>
Date: Mon Apr 25 16:49:16 2016 +0200
3426 FIX sms: fixed wrong message handling after message was quoted and therefore too
long
---
.werks/3426 | 10 ++++++++++
ChangeLog | 1 +
notifications/sms | 10 +++++++---
3 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/.werks/3426 b/.werks/3426
new file mode 100644
index 0000000..a088e73
--- /dev/null
+++ b/.werks/3426
@@ -0,0 +1,10 @@
+Title: sms: fixed wrong message handling after message was quoted and therefore too long
+Level: 1
+Component: notifications
+Class: fix
+Compatible: compat
+State: unknown
+Version: 1.2.9i1
+Date: 1461595506
+
+
diff --git a/ChangeLog b/ChangeLog
index 1707ac5..3e21c00 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -316,6 +316,7 @@
* 3380 FIX: Fixed graphs in service notifications having spaces in service
descriptions
* 3418 FIX: Do not send host notifications if a service group is required...
NOTE: Please refer to the migration notes!
+ * 3426 FIX: sms: fixed wrong message handling after message was quoted and therefore
too long
BI:
* 3271 New option in aggregation for tuning aggregation of downtimes...
diff --git a/notifications/sms b/notifications/sms
index 5512028..97edd9c6 100755
--- a/notifications/sms
+++ b/notifications/sms
@@ -87,17 +87,21 @@ elif notification_type == "CUSTOM":
message += " " + os.environ['NOTIFY_NOTIFICATIONCOMMENT']
recipient = os.environ['NOTIFY_CONTACTPAGER'].replace(" ",
"")
-quoted_message = "'" + message.replace("'",
"'\"'\"'") + "'"
+def quote_message(msg, max_length=None):
+ if max_length:
+ return "'" + msg.replace("'",
"'\"'\"'")[:max_length-2] + "'"
+ else:
+ return "'" + msg.replace("'",
"'\"'\"'") + "'"
if send_path:
- if os.system("%s %s %s" % (send_path, recipient, quoted_message[:160]))
>> 8 != 0:
+ if os.system("%s %s %s" % (send_path, recipient, quote_message(message,
160))) >> 8 != 0:
sys.exit(1)
elif spool_dir:
# On some distros, like debian, smstools does not ship with the sendsms/smssend
helper
# script. On this distro, simply drop the SMS in the outgoing spool directory.
import tempfile, shutil
fd, path = tempfile.mkstemp(prefix = 'cmk_sms_')
- os.write(fd, 'To: %s\n\n%s' % (recipient, quoted_message))
+ os.write(fd, 'To: %s\n\n%s' % (recipient, quote_message(message)))
os.close(fd)
os.chmod(path, 0660)
filename = path.split('/')[-1]