From 637123a78090fd6cdd4be8c97cc80b5c14a91d10 Mon Sep 17 00:00:00 2001 From: Andreas Wrede Date: Sat, 8 Nov 2014 17:13:14 +0100 Subject: [PATCH] more comfort --- pushNagios.py | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/pushNagios.py b/pushNagios.py index 06c6938..52e19bb 100755 --- a/pushNagios.py +++ b/pushNagios.py @@ -2,22 +2,48 @@ import sys import httplib, urllib +import getopt -def pushover(msg): +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 -v=" ".join(sys.argv[1:]) -if pushover(v): - print "delivered" -else: - print "NOT delivered" +# +# 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"