Pushover API expects form-data instead of JSON

This commit is contained in:
Pēteris Caune 2016-01-31 20:57:39 +02:00
parent a71ce64579
commit 24c111738a
2 changed files with 14 additions and 2 deletions

View File

@ -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"])

View File

@ -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 = {