Browse Source

HipChat integration

pull/7/head
Pēteris Caune 9 years ago
parent
commit
ebe5d2d91d
7 changed files with 61 additions and 8 deletions
  1. +5
    -0
      hc/api/admin.py
  2. +19
    -0
      hc/api/migrations/0013_auto_20151001_2029.py
  3. +13
    -1
      hc/api/models.py
  4. +4
    -3
      static/js/channels.js
  5. +9
    -2
      templates/front/channels.html
  6. +3
    -2
      templates/front/welcome.html
  7. +8
    -0
      templates/hipchat_message.html

+ 5
- 0
hc/api/admin.py View File

@ -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:


+ 19
- 0
hc/api/migrations/0013_auto_20151001_2029.py View File

@ -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')]),
),
]

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

@ -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/[email protected]"
}
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()


+ 4
- 3
static/js/channels.js View File

@ -3,16 +3,17 @@ $(function() {
email: "[email protected]",
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() {


+ 9
- 2
templates/front/channels.html View File

@ -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 %}
</td>
<td>
@ -66,17 +67,18 @@
<tr>
<form method="post" action="{% url 'hc-add-channel' %}">
<td>
<select id="add-check-kind" class="form-control" name="kind">
<select id="add-channel-kind" class="form-control" name="kind">
<option value="email">Email</option>
<option value="webhook">Webhook</option>
<option value="slack">Slack</option>
<option value="hipchat">HipChat</option>
<option value="pd">PagerDuty</option>
</select>
</td>
<td class="form-inline">
{% csrf_token %}
<input
id="add-check-value"
id="add-channel-value"
name="value"
class="form-control"
type="text"
@ -110,6 +112,11 @@
a check goes
<span class="word-up">up</span> or <span class="word-down">down</span>.
</p>
<p class="channels-help-hidden hipchat">
Healthchecks.io will post to a HipChat channel when
a check goes
<span class="word-up">up</span> or <span class="word-down">down</span>.
</p>
</td>
</tr>


+ 3
- 2
templates/front/welcome.html View File

@ -223,8 +223,9 @@
<div class="col-sm-4">
<p>
You can specify additional email addresses, webhooks,
<a href="https://www.pagerduty.com/">PagerDuty</a>
and <a href="https://slack.com/">Slack</a>
<a href="https://www.pagerduty.com/">PagerDuty</a>,
<a href="https://slack.com/">Slack</a>
and <a href="https://www.hipchat.com/">HipChat</a>
accounts to send notifications to.
</p>
</div>


+ 8
- 0
templates/hipchat_message.html View File

@ -0,0 +1,8 @@
{% 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 %}

Loading…
Cancel
Save