diff --git a/hc/api/models.py b/hc/api/models.py index d2c1b601..e35058d3 100644 --- a/hc/api/models.py +++ b/hc/api/models.py @@ -141,7 +141,7 @@ class Channel(models.Model): elif self.kind == "pd": return transports.PagerDuty(self) elif self.kind == "po": - return transports.Pushover() + return transports.Pushover(self) else: raise NotImplementedError("Unknown channel kind: %s" % self.kind) diff --git a/hc/api/tests/test_notify.py b/hc/api/tests/test_notify.py index a3f1afe8..3101c075 100644 --- a/hc/api/tests/test_notify.py +++ b/hc/api/tests/test_notify.py @@ -131,6 +131,19 @@ class NotifyTestCase(BaseTestCase): @patch("hc.api.transports.requests.post") def test_hipchat(self, mock_post): self._setup_data("hipchat", "123") + mock_post.return_value.status_code = 204 + + self.channel.notify(self.check) + n = Notification.objects.first() + self.assertEqual(n.error, "") + + args, kwargs = mock_post.call_args + json = kwargs["json"] + self.assertIn("DOWN", json["message"]) + + @patch("hc.api.transports.requests.post") + def test_pushover(self, mock_post): + self._setup_data("po", "123|0") mock_post.return_value.status_code = 200 self.channel.notify(self.check) @@ -138,4 +151,4 @@ class NotifyTestCase(BaseTestCase): args, kwargs = mock_post.call_args json = kwargs["json"] - self.assertIn("DOWN", json["message"]) + self.assertIn("DOWN", json["title"]) diff --git a/hc/api/transports.py b/hc/api/transports.py index 0e21d466..b6a3ffd9 100644 --- a/hc/api/transports.py +++ b/hc/api/transports.py @@ -67,7 +67,7 @@ class Webhook(Transport): headers = {"User-Agent": "healthchecks.io"} try: r = requests.get(self.channel.value, timeout=5, headers=headers) - if r.status_code not in (200, 201): + if r.status_code not in (200, 201, 204): return "Received status code %d" % r.status_code except requests.exceptions.Timeout: # Well, we tried @@ -81,7 +81,7 @@ class JsonTransport(Transport): headers = {"User-Agent": "healthchecks.io"} try: r = requests.post(url, json=payload, timeout=5, headers=headers) - if r.status_code not in (200, 201): + if r.status_code not in (200, 201, 204): return "Received status code %d" % r.status_code except requests.exceptions.Timeout: # Well, we tried