forked from GithubBackups/healthchecks
sendalerts management command prints error messages to stdout.
This commit is contained in:
parent
156f4dbeea
commit
c7a651c330
@ -47,7 +47,9 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
tmpl = "\nSending alert, status=%s, code=%s\n"
|
tmpl = "\nSending alert, status=%s, code=%s\n"
|
||||||
self.stdout.write(tmpl % (check.status, check.code))
|
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()
|
connection.close()
|
||||||
return True
|
return True
|
||||||
|
@ -67,8 +67,13 @@ class Check(models.Model):
|
|||||||
if self.status not in ("up", "down"):
|
if self.status not in ("up", "down"):
|
||||||
raise NotImplementedError("Unexpected status: %s" % self.status)
|
raise NotImplementedError("Unexpected status: %s" % self.status)
|
||||||
|
|
||||||
|
errors = []
|
||||||
for channel in self.channel_set.all():
|
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):
|
def get_status(self):
|
||||||
if self.status in ("new", "paused"):
|
if self.status in ("new", "paused"):
|
||||||
@ -153,6 +158,8 @@ class Channel(models.Model):
|
|||||||
n.error = error
|
n.error = error
|
||||||
n.save()
|
n.save()
|
||||||
|
|
||||||
|
return error
|
||||||
|
|
||||||
def test(self):
|
def test(self):
|
||||||
return self.transport().test()
|
return self.transport().test()
|
||||||
|
|
||||||
|
@ -44,7 +44,7 @@ class NotifyTestCase(BaseTestCase):
|
|||||||
self.channel.notify(self.check)
|
self.channel.notify(self.check)
|
||||||
|
|
||||||
n = Notification.objects.get()
|
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")
|
@patch("hc.api.transports.requests.get")
|
||||||
def test_webhooks_ignore_up_events(self, mock_get):
|
def test_webhooks_ignore_up_events(self, mock_get):
|
||||||
|
@ -73,7 +73,7 @@ class Webhook(Transport):
|
|||||||
# Well, we tried
|
# Well, we tried
|
||||||
return "Connection timed out"
|
return "Connection timed out"
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
return "A connection to %s failed" % self.channel.value
|
return "Connection failed"
|
||||||
|
|
||||||
|
|
||||||
class JsonTransport(Transport):
|
class JsonTransport(Transport):
|
||||||
@ -87,7 +87,7 @@ class JsonTransport(Transport):
|
|||||||
# Well, we tried
|
# Well, we tried
|
||||||
return "Connection timed out"
|
return "Connection timed out"
|
||||||
except requests.exceptions.ConnectionError:
|
except requests.exceptions.ConnectionError:
|
||||||
return "A connection to %s failed" % url
|
return "Connection failed"
|
||||||
|
|
||||||
|
|
||||||
class Slack(JsonTransport):
|
class Slack(JsonTransport):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user