@ -1,19 +1,6 @@ | |||
from datetime import timedelta as td | |||
from django import forms | |||
TIMEOUT_CHOICES = ( | |||
("15 minutes", td(minutes=15)), | |||
("30 minutes", td(minutes=30)), | |||
("1 hour", td(hours=1)), | |||
("3 hours", td(hours=3)), | |||
("6 hours", td(hours=6)), | |||
("12 hours", td(hours=12)), | |||
("1 day", td(days=1)), | |||
("2 days", td(days=2)), | |||
("3 days", td(days=3)), | |||
("1 week", td(weeks=1)) | |||
) | |||
from hc.api.models import TIMEOUT_CHOICES | |||
class TimeoutForm(forms.Form): | |||
@ -1,16 +1,18 @@ | |||
from django.conf import settings | |||
from django.core.mail import send_mail | |||
from django.template.loader import render_to_string | |||
def send_status_notification(check): | |||
if check.status == "down": | |||
subject = "Alert DOWN" | |||
body = "Hi, the check %s has gone down" % check.code | |||
elif check.status == "up": | |||
subject = "Alert UP" | |||
body = "Hi, the check %s has gone up" % check.code | |||
else: | |||
raise NotImplemented("Unexpected status: %s" % check.status) | |||
def send(to, template_directory, ctx): | |||
""" Send HTML email using Mandrill. | |||
send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [check.user.email], | |||
fail_silently=False) | |||
Expect template_directory to be a path containing | |||
- subject.txt | |||
- body.html | |||
""" | |||
from_email = settings.DEFAULT_FROM_EMAIL | |||
subject = render_to_string("%s/subject.txt" % template_directory, ctx) | |||
body = render_to_string("%s/body.html" % template_directory, ctx) | |||
send_mail(subject, "", from_email, [to], html_message=body) |
@ -0,0 +1,51 @@ | |||
{% load humanize %} | |||
<p>Hello,</p> | |||
<p>This is a notification sent by healthchecks.io</p> | |||
<p>The check "{{ check.name }}" has gone {{ check.status }}.</p> | |||
<p>Here is a summary of all your checks:</p> | |||
<table> | |||
<tr> | |||
<th></th> | |||
<th>Name</th> | |||
<th>URL</th> | |||
<th>Frequency</th> | |||
<th>Last Ping</th> | |||
</tr> | |||
{% for check in checks %} | |||
<tr> | |||
<td> | |||
{% if check.status == "new" %} | |||
<span class="glyphicon glyphicon-question-sign new"></span> | |||
{% elif now < check.alert_after %} | |||
<span class="glyphicon glyphicon-ok-sign up"></span> | |||
{% else %} | |||
<span class="glyphicon glyphicon-exclamation-sign down"></span> | |||
{% endif %} | |||
</td> | |||
<td> | |||
{{ check.name }} | |||
</td> | |||
<td class="url-cell"> | |||
<code>{{ check.url }}</code> | |||
</td> | |||
<td> | |||
{% for label, value in timeout_choices %} | |||
{% if check.timeout == value %} | |||
{{ label }} | |||
{% endif %} | |||
{% endfor %} | |||
</td> | |||
<td> | |||
{% if check.last_ping %} | |||
{{ check.last_ping|naturaltime }} | |||
{% else %} | |||
Never | |||
{% endif %} | |||
</td> | |||
</tr> | |||
{% endfor %} | |||
</table> | |||
@ -0,0 +1,2 @@ | |||
{{ check.name }} is {{ check.status }} | |||
@ -0,0 +1,5 @@ | |||
<p>Hello from healthchecks.io!</p> | |||
<p>Here's a link to log yourself in:</p> | |||
<p><a href="{{ login_link }}">{{ login_link }}</a></p> | |||
@ -0,0 +1 @@ | |||
Log in to healthchecks.io |