Skip to content
Permalink
Browse files

7429 FIX pushover: fix broken error handling

Since its introduction in version 1.2.8 the error handling of the
pushover notification script is broken. Notifications were always
handled as successful even if the Pushover API returned an error.
Version 1.5.0 introduced another bug that printed an error
message to the notify.log for successful notifications.

Change-Id: I6801451fdc6b09398f147cba3174ae38aa86b844
  • Loading branch information...
7omb committed Jun 27, 2019
1 parent 159dd01 commit 7eaaa3ea298d8fa8b768254f1ee19ea48c35c4fd
Showing with 52 additions and 13 deletions.
  1. +15 −0 .werks/7429
  2. +34 −12 cmk/notification_plugins/pushover.py
  3. +3 −1 notifications/pushover
@@ -0,0 +1,15 @@
Title: pushover: fix broken error handling
Level: 2
Component: notifications
Class: fix
Compatible: compat
Edition: cre
State: unknown
Version: 1.7.0i1
Date: 1561628038

Since its introduction in version 1.2.8 the error handling of the
pushover notification script is broken. Notifications were always
handled as successful even if the Pushover API returned an error.
Version 1.5.0 introduced another bug that printed an error
message to the notify.log for successful notifications.
@@ -36,7 +36,7 @@ def main():
api_key = context["PARAMETER_API_KEY"]
recipient_key = context["PARAMETER_RECIPIENT_KEY"]

send_push_notification(api_key, recipient_key, subject, text, context)
return send_push_notification(api_key, recipient_key, subject, text, context)


def get_subject(context):
@@ -112,16 +112,38 @@ def send_push_notification(api_key, recipient_key, subject, text, context):
if context.get("PARAMETER_SOUND", "none") != "none":
params.append(("sound", context["PARAMETER_SOUND"]))

proxy_url = context.get("PARAMETER_PROXY_URL")
proxies = {"https": proxy_url} if proxy_url else None

session = requests.Session()
if context.get("PARAMETER_PROXY_URL"):
try:
response = session.post(
api_url, params=dict(params), proxies={"https": context["PARAMETER_PROXY_URL"]})
else:
response = session.post(api_url, params=dict(params))

if response.status_code == '200':
return True

sys.stdout.write("Failed to send notification. Status: %s, Response: %s\n" %
(response.status_code, response.text))
return False
api_url,
params=dict(params),
proxies=proxies,
)
except requests.exceptions.ProxyError:
sys.stdout.write("Cannot connect to proxy: %s\n" % context["PARAMETER_PROXY_URL"])
return 1
except requests.exceptions.RequestException:
sys.stdout.write("POST request to server failed: %s\n" % api_url)
return 1

if response.status_code != 200:
sys.stdout.write("Failed to send notification. Status: %s, Response: %s\n" %
(response.status_code, response.text))
return 1

try:
data = response.json()
except ValueError:
sys.stdout.write("Failed to decode JSON response: %s\n" % response.text)
return 1

# According to the Pushover API the status should be 1 if we get a 200,
# but check it just in case
if data.get("status") != 1:
sys.stdout.write("Received an error from the Pushover API: %s" % response.text)
return 1

return 0
@@ -1,7 +1,9 @@
#!/usr/bin/env python
# Push Notifications (using Pushover)

import sys

from cmk.notification_plugins import pushover

if __name__ == "__main__":
pushover.main()
sys.exit(pushover.main())

0 comments on commit 7eaaa3e

Please sign in to comment.
You can’t perform that action at this time.