Browse Source

sendalerts management command prints error messages to stdout.

pull/40/head
Pēteris Caune 9 years ago
parent
commit
c7a651c330
4 changed files with 14 additions and 5 deletions
  1. +3
    -1
      hc/api/management/commands/sendalerts.py
  2. +8
    -1
      hc/api/models.py
  3. +1
    -1
      hc/api/tests/test_notify.py
  4. +2
    -2
      hc/api/transports.py

+ 3
- 1
hc/api/management/commands/sendalerts.py View File

@ -47,7 +47,9 @@ class Command(BaseCommand):
tmpl = "\nSending alert, status=%s, code=%s\n"
self.stdout.write(tmpl % (check.status, check.code))
check.send_alert()
errors = check.send_alert()
for ch, error in errors:
self.stdout.write("ERROR: %s %s %s\n" % (ch.kind, ch.value, error))
connection.close()
return True


+ 8
- 1
hc/api/models.py View File

@ -67,8 +67,13 @@ class Check(models.Model):
if self.status not in ("up", "down"):
raise NotImplementedError("Unexpected status: %s" % self.status)
errors = []
for channel in self.channel_set.all():
channel.notify(self)
error = channel.notify(self)
if error not in ("", "no-op"):
errors.append((channel, error))
return errors
def get_status(self):
if self.status in ("new", "paused"):
@ -153,6 +158,8 @@ class Channel(models.Model):
n.error = error
n.save()
return error
def test(self):
return self.transport().test()


+ 1
- 1
hc/api/tests/test_notify.py View File

@ -44,7 +44,7 @@ class NotifyTestCase(BaseTestCase):
self.channel.notify(self.check)
n = Notification.objects.get()
self.assertEqual(n.error, "A connection to http://example failed")
self.assertEqual(n.error, "Connection failed")
@patch("hc.api.transports.requests.get")
def test_webhooks_ignore_up_events(self, mock_get):


+ 2
- 2
hc/api/transports.py View File

@ -73,7 +73,7 @@ class Webhook(Transport):
# Well, we tried
return "Connection timed out"
except requests.exceptions.ConnectionError:
return "A connection to %s failed" % self.channel.value
return "Connection failed"
class JsonTransport(Transport):
@ -87,7 +87,7 @@ class JsonTransport(Transport):
# Well, we tried
return "Connection timed out"
except requests.exceptions.ConnectionError:
return "A connection to %s failed" % url
return "Connection failed"
class Slack(JsonTransport):


Loading…
Cancel
Save