Module: check_mk
Branch: master
Commit: 577fe86b8e88e3cf99fe06fef093c7f38123a4b7
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=577fe86b8e88e3…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Tue Nov 13 14:46:23 2018 +0100
YAPFed notification scripts
Change-Id: Ib0e6e594314b7b6c196043a2db1394c4f21278ee
---
notifications/sms | 19 +++++++++++--------
1 file changed, 11 insertions(+), 8 deletions(-)
diff --git a/notifications/sms b/notifications/sms
index 10ec05f..deb6ab2 100755
--- a/notifications/sms
+++ b/notifications/sms
@@ -25,7 +25,6 @@
# 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
@@ -36,7 +35,7 @@ import shutil
import tempfile
send_path = None
-for binary in [ 'sendsms', 'smssend' ]:
+for binary in ['sendsms', 'smssend']:
if os.system('which %s >/dev/null 2>/dev/null' % binary) == 0:
send_path = binary
@@ -46,8 +45,9 @@ 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
+ 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'] + " "
@@ -56,7 +56,7 @@ 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" ]:
+ 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] + " "
@@ -66,7 +66,7 @@ if os.environ['NOTIFY_WHAT'] == 'SERVICE':
message += os.environ['NOTIFY_SERVICEDESC']
else:
- if notification_type in [ "PROBLEM", "RECOVERY" ]:
+ if notification_type in ["PROBLEM", "RECOVERY"]:
message += "is " + os.environ['NOTIFY_HOSTSTATE']
# Ouput the other State
@@ -90,18 +90,21 @@ elif notification_type == "CUSTOM":
message += " " + os.environ['NOTIFY_NOTIFICATIONCOMMENT']
recipient = os.environ['NOTIFY_CONTACTPAGER'].replace(" ",
"")
+
+
def quote_message(msg, max_length=None):
if max_length:
- return "'" + msg.replace("'",
"'\"'\"'")[:max_length-2] + "'"
+ return "'" + msg.replace("'",
"'\"'\"'")[:max_length - 2] + "'"
return "'" + msg.replace("'",
"'\"'\"'") + "'"
+
if send_path:
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.
- fd, path = tempfile.mkstemp(prefix = 'cmk_sms_')
+ fd, path = tempfile.mkstemp(prefix='cmk_sms_')
os.write(fd, 'To: %s\n\n%s' % (recipient, quote_message(message)))
os.close(fd)
os.chmod(path, 0660)