forked from GithubBackups/healthchecks
HipChat integration
This commit is contained in:
parent
23c8ac6a2b
commit
ebe5d2d91d
@ -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
hc/api/migrations/0013_auto_20151001_2029.py
Normal file
19
hc/api/migrations/0013_auto_20151001_2029.py
Normal 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')]),
|
||||
),
|
||||
]
|
@ -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()
|
||||
|
@ -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() {
|
||||
|
@ -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>
|
||||
|
||||
|
@ -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
templates/hipchat_message.html
Normal file
8
templates/hipchat_message.html
Normal 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…
x
Reference in New Issue
Block a user