Module: check_mk
Branch: master
Commit: c96c11100572615f60c9fb437edd5cc3d4a00d29
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=c96c1110057261…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Wed Aug 27 11:05:25 2014 +0200
#1157 FIX Fixed SMS plugin on at least debian (distrs which have no sendsms/smssend)
Some distros do not provide the sendsms/smssend script with the smstools package.
In this cases the script for sending SMS did not work. This commit adds a dedection
when smssend/sendsms are not available whether the spool directory at
/var/spool/sms/outgoing is available or not. When it is available, the SMS notification
plugin drops a file to this directory which should then be processed by smsd.
---
.werks/1157 | 13 +++++++++++++
ChangeLog | 4 ++--
notifications/sms | 29 ++++++++++++++++++++++-------
3 files changed, 37 insertions(+), 9 deletions(-)
diff --git a/.werks/1157 b/.werks/1157
new file mode 100644
index 0000000..9f0e556
--- /dev/null
+++ b/.werks/1157
@@ -0,0 +1,13 @@
+Title: Fixed SMS plugin on at least debian (distrs which have no sendsms/smssend)
+Level: 1
+Component: notifications
+Compatible: compat
+Version: 1.2.5i6
+Date: 1409130157
+Class: fix
+
+Some distros do not provide the sendsms/smssend script with the smstools package.
+In this cases the script for sending SMS did not work. This commit adds a dedection
+when smssend/sendsms are not available whether the spool directory at
+/var/spool/sms/outgoing is available or not. When it is available, the SMS notification
+plugin drops a file to this directory which should then be processed by smsd.
diff --git a/ChangeLog b/ChangeLog
index 35e04df..ed8e512 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -59,9 +59,9 @@
* 1145 FIX: windows_tasks: handle case correctly where task is currently running...
* 1378 FIX: mk_logwatch: remove exceeding \n when rewriting message and using \0...
* 1147 FIX: upc_capacity, ups_socomec_capacity: Fix checking of battery left
levels...
+ * 1099 FIX: tsm_scratch: now returns the variable name instead the values during
inventory...
* 0650 FIX: f5_bigip_pool: limits to the number of active nodes are now correctly
applied...
NOTE: Please refer to the migration notes!
- * 1099 FIX: tsm_scratch: now returns the variable name instead the values during
inventory...
Multisite:
* 1066 Implemented Dashboard Designer...
@@ -70,7 +70,6 @@
* 1154 FIX: Availability: Fixed unwanted redirect to edit annotation page after
editing availability options...
WATO:
- * 1095 New WATO Web-API: Now able to manage hosts via web automation calls
* 1096 New WATO webservices: manage hosts via webinterface...
* 1155 NagVis map edit/view permissions can now be set using roles...
* 1064 FIX: Fixed rare issue with WATO communication in distributed setups (different
OS versions)...
@@ -83,6 +82,7 @@
Notifications:
* 1156 FIX: Graphs in HTML mails are now sent again where they where missing...
+ * 1157 FIX: Fixed SMS plugin on at least debian (distrs which have no
sendsms/smssend)...
Event Console:
* 1007 FIX: check_mkevents: fix case where events contain binary zeroes
diff --git a/notifications/sms b/notifications/sms
index ba310f2..6156fa1 100755
--- a/notifications/sms
+++ b/notifications/sms
@@ -37,8 +37,13 @@ for binary in [ 'sendsms', 'smssend' ]:
if os.system('which %s >/dev/null' % binary) == 0:
send_path = binary
-if not send_path:
- sys.stderr.write('Error: SMS Tools binaries (sendsms or smssend) not
found\n')
+smsd_user = 'smsd'
+spool_dir = '/var/spool/sms/outgoing'
+if not os.path.exists(spool_dir):
+ spool_dir = None
+
+if not send_path and not spool_dir:
+ sys.stderr.write('Error: SMS Tools binaries (sendsms or smssend) not found and
spool dir does not exists.\n')
sys.exit(2) # Fatal error, no retry
max_len = 160
@@ -54,8 +59,18 @@ if os.environ['NOTIFY_WHAT'] == 'SERVICE':
else:
message += "is " + os.environ['NOTIFY_HOSTSTATE']
-empf = os.environ['NOTIFY_CONTACTPAGER'].replace( " ", "")
-if 0 == os.system("%s %s '%s'" % (send_path, empf, message[:160])):
- sys.exit(0)
-else:
- sys.exit(1)
+recipient = os.environ['NOTIFY_CONTACTPAGER'].replace( " ",
"")
+
+if send_path:
+ if os.system("%s %s '%s'" % (send_path, recipient, 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, message))
+ os.close(fd)
+ os.chmod(path, 0660)
+ filename = path.split('/')[-1]
+ shutil.move(path, spool_dir + '/' + filename)