/usr/share/check_mk/notifications/sms is in check-mk-server 1.2.6p12-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | #!/usr/bin/python
# SMS (using smstools)
# +------------------------------------------------------------------+
# | ____ _ _ __ __ _ __ |
# | / ___| |__ ___ ___| | __ | \/ | |/ / |
# | | | | '_ \ / _ \/ __| |/ / | |\/| | ' / |
# | | |___| | | | __/ (__| < | | | | . \ |
# | \____|_| |_|\___|\___|_|\_\___|_| |_|_|\_\ |
# | |
# | Copyright Mathias Kettner 2013 mk@mathias-kettner.de |
# +------------------------------------------------------------------+
#
# This file is part of Check_MK.
# The official homepage is at http://mathias-kettner.de/check_mk.
#
# check_mk is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation in version 2. check_mk is distributed
# in the hope that it will be useful, but WITHOUT ANY WARRANTY; with-
# out even the implied warranty of MERCHANTABILITY or FITNESS FOR A
# PARTICULAR PURPOSE. See the GNU General Public License for more de-
# ails. You should have received a copy of the GNU General Public
# License along with GNU Make; see the file COPYING. If not, write
# to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301 USA.
# Notification via sms using the sms tools
# Note: You have to add the side user to the sendsms group
# and restart the site
import os, sys
send_path = None
for binary in [ 'sendsms', 'smssend' ]:
if os.system('which %s >/dev/null' % binary) == 0:
send_path = binary
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
message = os.environ['NOTIFY_HOSTNAME'] + " "
notification_type = os.environ["NOTIFY_NOTIFICATIONTYPE"]
# Prepare Default information and Type PROBLEM, RECOVERY
if os.environ['NOTIFY_WHAT'] == 'SERVICE':
if notification_type in [ "PROBLEM", "RECOVERY" ]:
message += os.environ['NOTIFY_SERVICESTATE'][:2] + " "
avail_len = max_len - len(message)
message += os.environ['NOTIFY_SERVICEDESC'][:avail_len] + " "
avail_len = max_len - len(message)
message += os.environ['NOTIFY_SERVICEOUTPUT'][:avail_len]
else:
message += os.environ['NOTIFY_SERVICEDESC']
else:
if notification_type in [ "PROBLEM", "RECOVERY" ]:
message += "is " + os.environ['NOTIFY_HOSTSTATE']
# Ouput the other State
if notification_type.startswith("FLAP"):
if "START" in notification_type:
message += " Started Flapping"
else:
message += " Stopped Flapping"
elif notification_type.startswith("DOWNTIME"):
what = notification_type[8:].title()
message += " Downtime " + what
message += " " + os.environ['NOTIFY_NOTIFICATIONCOMMENT']
elif notification_type == "ACKNOWLEDGEMENT":
message += " Acknowledged"
message += " " + os.environ['NOTIFY_NOTIFICATIONCOMMENT']
elif notification_type == "CUSTOM":
message += " Custom Notification"
message += " " + os.environ['NOTIFY_NOTIFICATIONCOMMENT']
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)
|