diff --git a/hc/api/tests/test_notify.py b/hc/api/tests/test_notify.py index 3101c075..8b2326c7 100644 --- a/hc/api/tests/test_notify.py +++ b/hc/api/tests/test_notify.py @@ -150,5 +150,5 @@ class NotifyTestCase(BaseTestCase): assert Notification.objects.count() == 1 args, kwargs = mock_post.call_args - json = kwargs["json"] + json = kwargs["data"] self.assertIn("DOWN", json["title"]) diff --git a/hc/api/transports.py b/hc/api/transports.py index b6a3ffd9..81ba0fef 100644 --- a/hc/api/transports.py +++ b/hc/api/transports.py @@ -124,9 +124,21 @@ class PagerDuty(JsonTransport): return self.post(self.URL, payload) -class Pushover(JsonTransport): +class Pushover(Transport): URL = "https://api.pushover.net/1/messages.json" + def post(self, url, payload): + headers = {"User-Agent": "healthchecks.io"} + try: + r = requests.post(url, data=payload, timeout=5, headers=headers) + if r.status_code not in (200, 201, 204): + return "Received status code %d" % r.status_code + except requests.exceptions.Timeout: + # Well, we tried + return "Connection timed out" + except requests.exceptions.ConnectionError: + return "Connection failed" + def notify(self, check): others = self.checks().filter(status="down").exclude(code=check.code) ctx = {