@ -92,7 +92,7 @@ class Check(models.Model): | |||||
self.channel_set.add(*channels) | self.channel_set.add(*channels) | ||||
def tags_list(self): | def tags_list(self): | ||||
return self.tags.split(" ") | |||||
return [t.strip() for t in self.tags.split(" ") if t.strip()] | |||||
class Ping(models.Model): | class Ping(models.Model): | ||||
@ -148,14 +148,9 @@ class Channel(models.Model): | |||||
n.save() | n.save() | ||||
elif self.kind == "slack": | elif self.kind == "slack": | ||||
tmpl = "integrations/slack_message.html" | |||||
tmpl = "integrations/slack_message.json" | |||||
text = render_to_string(tmpl, {"check": check}) | text = render_to_string(tmpl, {"check": check}) | ||||
payload = { | |||||
"text": text, | |||||
"username": "healthchecks.io", | |||||
"icon_url": "https://healthchecks.io/static/img/[email protected]" | |||||
} | |||||
payload = json.loads(text) | |||||
r = requests.post(self.value, json=payload, timeout=5) | r = requests.post(self.value, json=payload, timeout=5) | ||||
n.status = r.status_code | n.status = r.status_code | ||||
@ -0,0 +1,15 @@ | |||||
from django.test import TestCase | |||||
from hc.api.models import Check | |||||
class CheckModelTestCase(TestCase): | |||||
def test_it_strips_tags(self): | |||||
check = Check() | |||||
check.tags = " foo bar " | |||||
self.assertEquals(check.tags_list(), ["foo", "bar"]) | |||||
check.tags = " " | |||||
self.assertEquals(check.tags_list(), []) |
@ -1,8 +0,0 @@ | |||||
{% load humanize %} | |||||
{% if check.status == "down" %} | |||||
The check "{{ check.name_then_code }}" is DOWN. | |||||
Last ping was {{ check.last_ping|naturaltime }} | |||||
{% else %} | |||||
The check "{{ check.name_then_code }}" received a ping and is now UP. | |||||
{% endif %} |
@ -0,0 +1,45 @@ | |||||
{% load hc_extras humanize %} | |||||
{ | |||||
"username": "healthchecks.io", | |||||
"icon_url": "https://healthchecks.io/static/img/[email protected]", | |||||
"attachments": [{ | |||||
{% if check.status == "up" %} | |||||
"color": "good", | |||||
{% else %} | |||||
"color": "danger", | |||||
{% endif %} | |||||
"fallback": "The check \"{{ check.name_then_code|escapejs }}\" is {{ check.status|upper }}.", | |||||
"mrkdwn_in": ["fields"], | |||||
"text": "“{{ check.name_then_code|escapejs }}” is {{ check.status|upper }}.", | |||||
"fields": [ | |||||
{ | |||||
"title": "Period", | |||||
"value": "{{ check.timeout|hc_duration }}", | |||||
"short": true | |||||
}, | |||||
{ | |||||
"title": "Last Ping", | |||||
{% if check.last_ping %} | |||||
"value": "{{ check.last_ping|naturaltime }}", | |||||
{% else %} | |||||
"value": "Never", | |||||
{% endif %} | |||||
"short": true | |||||
}, | |||||
{% if check.tags_list %} | |||||
{ | |||||
"title": "Tags", | |||||
"value": "{% for tag in check.tags_list %}`{{ tag|escapejs }}` {% endfor %}", | |||||
"short": true | |||||
}, | |||||
{% endif %} | |||||
{ | |||||
"title": "Total Pings", | |||||
"value": {{ check.n_pings }}, | |||||
"short": true | |||||
} | |||||
] | |||||
}] | |||||
} | |||||