@@ -34,11 +34,6 @@ class PushoverError(Exception): pass
3434def pushover (image , ** kwargs ):
3535 assert 'message' in kwargs
3636
37- if not 'token' in kwargs :
38- kwargs ['token' ] = os .environ ['PUSHOVER_TOKEN' ]
39- if not 'user' in kwargs :
40- kwargs ['user' ] = os .environ ['PUSHOVER_USER' ]
41-
4237 url = urljoin (PUSHOVER_API , "messages.json" )
4338 headers = { 'User-Agent' : 'mqttwarn' }
4439
@@ -70,9 +65,18 @@ def plugin(srv, item):
7065
7166 try :
7267 userkey = addrs [0 ]
73- appkey = addrs [1 ]
68+ token = addrs [1 ]
7469 except :
75- srv .logging .warn ("No pushover userkey/appkey configured for target `%s'" % (item .target ))
70+ srv .logging .warning ("Invalid address configuration for target `%s'" % (item .target ))
71+ return False
72+
73+ if userkey is None and "PUSHOVER_USER" in os .environ :
74+ userkey = os .environ ["PUSHOVER_USER" ].strip ()
75+ if token is None and "PUSHOVER_TOKEN" in os .environ :
76+ token = os .environ ["PUSHOVER_TOKEN" ].strip ()
77+
78+ if not userkey or not token :
79+ srv .logging .warning ("No pushover credentials configured for target `%s'" % (item .target ))
7680 return False
7781
7882 params = {
@@ -84,7 +88,7 @@ def plugin(srv, item):
8488 params ['sound' ] = addrs [2 ]
8589
8690 if len (addrs ) > 3 :
87- params ['sound ' ] = addrs [3 ]
91+ params ['devices ' ] = addrs [3 ]
8892
8993 if title is not None :
9094 params ['title' ] = title
@@ -112,22 +116,22 @@ def plugin(srv, item):
112116 authuser = item .data ['user' ]
113117 authpass = item .data ['password' ]
114118 if authtype == 'digest' :
115- image = requests .get (imageurl , stream = True ,auth = HTTPDigestAuth (authuser , authpass )).raw
119+ image = requests .get (imageurl , stream = True , auth = HTTPDigestAuth (authuser , authpass )).raw
116120 else :
117- image = requests .get (imageurl , stream = True ,auth = HTTPBasicAuth (authuser , authpass )).raw
121+ image = requests .get (imageurl , stream = True , auth = HTTPBasicAuth (authuser , authpass )).raw
118122 else :
119123 image = requests .get (imageurl , stream = True ).raw
120124 elif 'imagebase64' in item .data :
121125 imagebase64 = item .data ['imagebase64' ]
122126 srv .logging .debug ("Image (base64 encoded) detected" )
123- image = base64 .decodestring (imagebase64 )
127+ image = base64 .decodebytes (imagebase64 )
124128
125129 try :
126130 srv .logging .debug ("Sending pushover notification to %s [%s]...." % (item .target , params ))
127- pushover (image = image , user = userkey , token = appkey , ** params )
131+ pushover (image = image , user = userkey , token = token , ** params )
128132 srv .logging .debug ("Successfully sent pushover notification" )
129133 except Exception as e :
130- srv .logging .warn ("Error sending pushover notification: %s" % e )
134+ srv .logging .warning ("Error sending pushover notification: %s" % e )
131135 return False
132136
133137 return True
0 commit comments