Created
February 18, 2010 23:55
-
-
Save oremj/308251 to your computer and use it in GitHub Desktop.
nagios-send-sms.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import sys | |
from urllib import quote | |
from urllib2 import urlopen | |
SMS_URL = "http://host/sendmsg" | |
SMS_PASSWD = "" | |
SMS_USER = "" | |
NOTIF_ARGS = [ | |
'author', | |
'comment', | |
'notiftype', | |
'output', | |
'phone' | |
] | |
def ordered_params(params): | |
return "&".join("=".join(map(quote, p)) for p in params) | |
def send_notif(phone, msg): | |
params = ( | |
('user', SMS_USER), | |
('passwd', SMS_PASSWD), | |
('cat', '1'), | |
('to', phone), | |
('text', msg) | |
) | |
urlopen("%s?%s" % (SMS_URL, ordered_params(params))).read() | |
if __name__ == "__main__": | |
if sys.argv[1] == 'service-notif': | |
args = dict(zip(NOTIF_ARGS, sys.argv[2:])) | |
send_notif(args['phone'], '%s' % " ".join(args[k] for k in NOTIF_ARGS if k != 'phone')) | |
elif sys.argv[1] == 'host-notif': | |
args = dict(zip(NOTIF_ARGS, sys.argv[2:])) | |
send_notif(args['phone'], '%s' % " ".join(args[k] for k in NOTIF_ARGS if k != 'phone')) | |
else: | |
exit(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment