Created
February 18, 2012 20:41
-
-
Save uid0/1860956 to your computer and use it in GitHub Desktop.
Using twilio as a nagios sms gateway
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/env python | |
from twilio.rest import TwilioRestClient | |
import getopt, sys | |
def usage(): | |
print "Usage Instructions for alertsms.py" | |
print " -h --help: Shows this text, exits" | |
print " -o --output [number]: sends SMS to that number" | |
print " -v: enables verbose output" | |
print " -i --input [message]: message to send" | |
def main(): | |
try: | |
opts, args = getopt.getopt(sys.argv[1:], "hi:o:v", ["help","input=" "output="]) | |
except getopt.GetoptError, err: | |
print str(err) | |
usage() | |
sys.exit(2) | |
output = None | |
message = "Test from Nagios SMS Gateway." | |
verbose = False | |
for o, a in opts: | |
if o == "-v": | |
verbose = True | |
elif o in ("-h", "--help"): | |
usage() | |
sys.exit() | |
elif o in ("-o", "--output"): | |
output = a | |
elif o in ("-i", "--input"): | |
message = a | |
else: | |
assert False, "unhandled option" | |
account = "ACCOUNT_NUMBER_HERE" | |
token = "ACCOUNT_TOKEN_HERE" | |
client = TwilioRestClient(account, token) | |
if verbose == True: | |
print "Sending " + message + " to " + output | |
message = client.sms.messages.create(to=output, from_="PHONENUMBERHERE", | |
body=message) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment