Browse Source

Add Slack integration

pull/7/head
Pēteris Caune 9 years ago
parent
commit
7bb17cefad
5 changed files with 34 additions and 3 deletions
  1. +15
    -1
      hc/api/models.py
  2. +1
    -0
      static/js/channels.js
  3. +7
    -0
      templates/front/channels.html
  4. +3
    -2
      templates/front/welcome.html
  5. +8
    -0
      templates/slack_message.html

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

@ -9,6 +9,7 @@ from django.conf import settings
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.db import models from django.db import models
from django.template.loader import render_to_string
from django.utils import timezone from django.utils import timezone
import requests import requests
@ -19,7 +20,7 @@ STATUSES = (("up", "Up"), ("down", "Down"), ("new", "New"))
DEFAULT_TIMEOUT = td(days=1) DEFAULT_TIMEOUT = td(days=1)
DEFAULT_GRACE = td(hours=1) DEFAULT_GRACE = td(hours=1)
CHANNEL_KINDS = (("email", "Email"), ("webhook", "Webhook"), CHANNEL_KINDS = (("email", "Email"), ("webhook", "Webhook"),
("pd", "PagerDuty"))
("slack", "Slack"), ("pd", "PagerDuty"))
class Check(models.Model): class Check(models.Model):
@ -123,6 +124,19 @@ class Channel(models.Model):
pass pass
n.save() n.save()
elif self.kind == "slack":
text = render_to_string("slack_message.html", {"check": check})
payload = {
"text": text,
"username": "healthchecks.io",
"icon_url": "https://healthchecks.io/static/img/[email protected]"
}
r = requests.post(self.value, data=json.dumps(payload))
n.status = r.status_code
n.save()
elif self.kind == "pd": elif self.kind == "pd":
if check.status == "down": if check.status == "down":
event_type = "trigger" event_type = "trigger"


+ 1
- 0
static/js/channels.js View File

@ -2,6 +2,7 @@ $(function() {
var placeholders = { var placeholders = {
email: "[email protected]", email: "[email protected]",
webhook: "http://", webhook: "http://",
slack: "https://hooks.slack.com/...",
pd: "service key" pd: "service key"
} }


+ 7
- 0
templates/front/channels.html View File

@ -21,6 +21,7 @@
<td> <td>
{% if ch.kind == "email" %} Email {% endif %} {% if ch.kind == "email" %} Email {% endif %}
{% if ch.kind == "webhook" %} Webhook {% endif %} {% if ch.kind == "webhook" %} Webhook {% endif %}
{% if ch.kind == "slack" %} Slack {% endif %}
{% if ch.kind == "pd" %} PagerDuty {% endif %} {% if ch.kind == "pd" %} PagerDuty {% endif %}
</td> </td>
<td> <td>
@ -68,6 +69,7 @@
<select id="add-check-kind" class="form-control" name="kind"> <select id="add-check-kind" class="form-control" name="kind">
<option value="email">Email</option> <option value="email">Email</option>
<option value="webhook">Webhook</option> <option value="webhook">Webhook</option>
<option value="slack">Slack</option>
<option value="pd">PagerDuty</option> <option value="pd">PagerDuty</option>
</select> </select>
</td> </td>
@ -103,6 +105,11 @@
<span class="word-down">down</span> and will resolve it <span class="word-down">down</span> and will resolve it
when same check goes <span class="word-up">up</span> when same check goes <span class="word-up">up</span>
</p> </p>
<p class="channels-help-hidden slack">
Healthchecks.io will post to a Slack channel when
a check goes
<span class="word-up">up</span> or <span class="word-down">down</span>.
</p>
</td> </td>
</tr> </tr>


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

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


+ 8
- 0
templates/slack_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