diff --git a/hc/api/admin.py b/hc/api/admin.py index f43e8c15..2ed84e53 100644 --- a/hc/api/admin.py +++ b/hc/api/admin.py @@ -67,6 +67,7 @@ class ChannelsAdmin(admin.ModelAdmin): list_select_related = ("user", ) list_display = ("id", "code", "email", "formatted_kind", "value", "num_notifications") + list_filter = ("kind", ) def email(self, obj): return obj.user.email if obj.user else None @@ -76,6 +77,10 @@ class ChannelsAdmin(admin.ModelAdmin): return "PagerDuty" elif obj.kind == "webhook": return "Webhook" + elif obj.kind == "slack": + return "Slack" + elif obj.kind == "hipchat": + return "HipChat" elif obj.kind == "email" and obj.email_verified: return "Email" elif obj.kind == "email" and not obj.email_verified: diff --git a/hc/api/migrations/0013_auto_20151001_2029.py b/hc/api/migrations/0013_auto_20151001_2029.py new file mode 100644 index 00000000..8a045cd4 --- /dev/null +++ b/hc/api/migrations/0013_auto_20151001_2029.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import models, migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('api', '0012_auto_20150930_1922'), + ] + + operations = [ + migrations.AlterField( + model_name='channel', + name='kind', + field=models.CharField(max_length=20, choices=[('email', 'Email'), ('webhook', 'Webhook'), ('hipchat', 'HipChat'), ('slack', 'Slack'), ('pd', 'PagerDuty')]), + ), + ] diff --git a/hc/api/models.py b/hc/api/models.py index b6f5b7c9..6fe4bd51 100644 --- a/hc/api/models.py +++ b/hc/api/models.py @@ -20,6 +20,7 @@ STATUSES = (("up", "Up"), ("down", "Down"), ("new", "New")) DEFAULT_TIMEOUT = td(days=1) DEFAULT_GRACE = td(hours=1) CHANNEL_KINDS = (("email", "Email"), ("webhook", "Webhook"), + ("hipchat", "HipChat"), ("slack", "Slack"), ("pd", "PagerDuty")) @@ -132,7 +133,18 @@ class Channel(models.Model): "icon_url": "https://healthchecks.io/static/img/logo@2x.png" } - r = requests.post(self.value, data=json.dumps(payload)) + r = requests.post(self.value, json=payload) + + n.status = r.status_code + n.save() + elif self.kind == "hipchat": + text = render_to_string("hipchat_message.html", {"check": check}) + payload = { + "message": text, + "color": "green" if check.status == "up" else "red", + } + + r = requests.post(self.value, json=payload) n.status = r.status_code n.save() diff --git a/static/js/channels.js b/static/js/channels.js index 7ed85e34..fa2264a4 100644 --- a/static/js/channels.js +++ b/static/js/channels.js @@ -3,16 +3,17 @@ $(function() { email: "address@example.org", webhook: "http://", slack: "https://hooks.slack.com/...", + hipchat: "https://api.hipchat.com/...", pd: "service key" } - $("#add-check-kind").change(function() { + $("#add-channel-kind").change(function() { $(".channels-add-help p").hide(); - var v = $("#add-check-kind").val(); + var v = $("#add-channel-kind").val(); $(".channels-add-help p." + v).show(); - $("#add-check-value").attr("placeholder", placeholders[v]); + $("#add-channel-value").attr("placeholder", placeholders[v]); }); $(".edit-checks").click(function() { diff --git a/templates/front/channels.html b/templates/front/channels.html index d975a4f6..77167aaf 100644 --- a/templates/front/channels.html +++ b/templates/front/channels.html @@ -22,6 +22,7 @@ {% if ch.kind == "email" %} Email {% endif %} {% if ch.kind == "webhook" %} Webhook {% endif %} {% if ch.kind == "slack" %} Slack {% endif %} + {% if ch.kind == "hipchat" %} HipChat {% endif %} {% if ch.kind == "pd" %} PagerDuty {% endif %}