Skip to content

Instantly share code, notes, and snippets.

@kwmiebach
Forked from uid0/alertsms.py
Last active August 29, 2015 14:24
Show Gist options
  • Save kwmiebach/4c8d8e50b7323ef6baf8 to your computer and use it in GitHub Desktop.
Save kwmiebach/4c8d8e50b7323ef6baf8 to your computer and use it in GitHub Desktop.
#!/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