Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#145028655 Send alerts via sms #9

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Open
Empty file added __init__.py
Empty file.
4 changes: 3 additions & 1 deletion hc/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
)
DEFAULT_TIMEOUT = td(days=1)
DEFAULT_GRACE = td(hours=1)
CHANNEL_KINDS = (("email", "Email"), ("webhook", "Webhook"),
CHANNEL_KINDS = (("sms", "SMS"), ("email", "Email"), ("webhook", "Webhook"),
("hipchat", "HipChat"),
("slack", "Slack"), ("pd", "PagerDuty"), ("po", "Pushover"),
("victorops", "VictorOps"))
Expand Down Expand Up @@ -167,6 +167,8 @@ def send_verify_link(self):

@property
def transport(self):
if self.kind == 'sms':
return transports.SMS(self)
if self.kind == "email":
return transports.Email(self)
elif self.kind == "webhook":
Expand Down
13 changes: 13 additions & 0 deletions hc/api/transports.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import requests
from six.moves.urllib.parse import quote
from twilio.rest import Client

from hc.lib import emails

Expand Down Expand Up @@ -89,6 +90,18 @@ def post(self, url, json, **kwargs):
def post_form(self, url, data):
return self.request("post", url, data=data)

class SMS(Transport):

def notify(self, check):
if check.status in ["up", "down"]:
message = "Hullo, your {} check is {}!".format(check.name, check.status)
to = self.channel.value
client = Client(settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN)
response = client.messages.create(body=message, to=to, from_='+12569989594')

if response.error_message:
return response.error_message


class Webhook(HttpTransport):
def notify(self, check):
Expand Down
1 change: 1 addition & 0 deletions hc/front/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
channel_urls = [
url(r'^$', views.channels, name="hc-channels"),
url(r'^add/$', views.add_channel, name="hc-add-channel"),
url(r'^add_sms/$', views.add_sms, name="hc-add-sms"),
url(r'^add_email/$', views.add_email, name="hc-add-email"),
url(r'^add_webhook/$', views.add_webhook, name="hc-add-webhook"),
url(r'^add_pd/$', views.add_pd, name="hc-add-pd"),
Expand Down
4 changes: 4 additions & 0 deletions hc/front/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,10 @@ def remove_channel(request, code):

return redirect("hc-channels")

@login_required
def add_sms(request):
ctx = {"page": "channels"}
return render(request, "integrations/add_sms.html", ctx)

@login_required
def add_email(request):
Expand Down
7 changes: 6 additions & 1 deletion hc/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@
'djmail',

'hc.accounts',
'django_twilio',
'hc.api',
'hc.front',
'hc.payments'
'hc.payments',
)

MIDDLEWARE = (
Expand Down Expand Up @@ -139,6 +140,10 @@
SLACK_CLIENT_ID = None
SLACK_CLIENT_SECRET = None

# sms integration
TWILIO_ACCOUNT_SID = 'ACacce7eab5f5f5018d1c78ba0bfc36aa7'
TWILIO_AUTH_TOKEN = '4b813e4109fe5f91e91568d202de0463'

# Pushover integration -- override these in local_settings
PUSHOVER_API_TOKEN = None
PUSHOVER_SUBSCRIPTION_URL = None
Expand Down
27 changes: 25 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
appdirs==1.4.3
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file has conflicts, resolve them.

Babel==2.4.0
boto==2.46.1
cssselect==1.0.1
cssutils==1.0.2
Django==1.10
django-appconf==1.0.1
django-compressor==2.1
django-phonenumber-field==1.3.0
django-sendsms==0.2.3
django-ses-backend==0.1.1
Django==1.10
django_compressor==2.1
django-twilio==0.8.0
djmail==0.11.0
funcsigs==1.0.2
futures==3.0.3
lxml==3.7.3
mock==2.0.0
packaging==16.8
patch==1.16
pbr==3.0.0
phonenumberslite==8.5.0
premailer==2.9.6
psycopg2==2.6.1
PyJWT==1.5.0
pyparsing==2.2.0
PySocks==1.6.7
pytz==2017.2
rcssmin==1.0.6
requests==2.9.1
rjsmin==1.0.12
six==1.10.0
twilio==6.3.0
Binary file added static/img/integrations/sms.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions static/js/channels.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ $(function() {
webhook: "http://",
slack: "https://hooks.slack.com/...",
hipchat: "https://api.hipchat.com/...",
sms: "+2547793222",
pd: "service key"
}

Expand Down
9 changes: 9 additions & 0 deletions templates/front/channels.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
{% for ch in channels %}
<tr class="channel-row">
<td>
{% if ch.kind == "sms" %} SMS {% endif %}
{% if ch.kind == "email" %} Email {% endif %}
{% if ch.kind == "webhook" %} Webhook {% endif %}
{% if ch.kind == "slack" %} Slack {% endif %}
Expand Down Expand Up @@ -126,6 +127,14 @@

<h1 class="ai-title">Add More</h1>
<ul class="add-integration">
<li>
<img src="{% static 'img/integrations/sms.png' %}"
class="icon" alt="SMS icon" />

<h2>SMS</h2>
<p>Receive an sms when check goes up or down.</p>
<a href="{% url 'hc-add-sms' %}" class="btn btn-primary">Add Integration</a>
</li>
<li>
<img src="{% static 'img/integrations/slack.png' %}"
class="icon" alt="Slack icon" />
Expand Down
58 changes: 58 additions & 0 deletions templates/integrations/add_sms.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{% extends "base.html" %}
{% load compress humanize staticfiles hc_extras %}

{% block title %}Add mobile numbers to send your notifications to - healthchecks.io{% endblock %}


{% block content %}
<div class="row">
<div class="col-sm-12">
<h1>SMS</h1>

<p>Get an sms message when your check goes up or down.</p>

<p>
<strong>Tip:</strong>
Add multiple phone numbers, to notify multiple team members.
</p>

<p>
<strong>Confirmation needed.</strong>
After entering a phone number(s), healthchecks.io will send out a confirmation link.
Only confirmed numbers will receive notifications.
</p>

<h2>Integration Settings</h2>

<form method="post" class="form-horizontal" action="{% url 'hc-add-channel' %}">
{% csrf_token %}
<input type="hidden" name="kind" value="sms" />
<div class="form-group">
<label for="sms" class="col-sm-2 control-label">Phone number</label>
<div class="col-sm-3">
<input
id="sms"
type="test"
class="form-control"
name="value"
placeholder="2547793222">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-primary">Save Integration</button>
</div>
</div>
</form>
</div>
</div>


{% endblock %}

{% block scripts %}
{% compress js %}
<script src="{% static 'js/jquery-2.1.4.min.js' %}"></script>
<script src="{% static 'js/bootstrap.min.js' %}"></script>
{% endcompress %}
{% endblock %}