#!/usr/bin/python import sys import httplib, urllib import getopt def pushover(msg, title=""): conn = httplib.HTTPSConnection("api.pushover.net:443") conn.request("POST", "/1/messages.json", urllib.urlencode({ "token": "aNY2xeYydxzabzihTjb3P2LMHhqhr2", "user": "uDhH33UjQQDYtNzJb1ThRiWb9ingGK", "message": msg, "title": title, }), { "Content-type": "application/x-www-form-urlencoded" }) r1=conn.getresponse() #print r1.status, r1.reason return r1.status == 200 # # Main # helpflag=False verbose=False title="Nagios" optslist, args = [], [] try: optslist, args = getopt.getopt(sys.argv[1:], 'ht:v') except getopt.error, cause: helpflag=True lastyear=0 for o,a in optslist: if o == '-v': verbose=True elif o == '-t': title=a v=" ".join(args) rc=pushover(v, title) if verbose: if rc: print "delivered" else: print "NOT delivered"