Skip to content

Instantly share code, notes, and snippets.

@oremj
Created February 18, 2010 23:55
Show Gist options
  • Save oremj/308251 to your computer and use it in GitHub Desktop.
Save oremj/308251 to your computer and use it in GitHub Desktop.
nagios-send-sms.py
#!/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