Browse Source

Alternate flow for setting up PagerDuty integration, without using PD Connect

pull/307/head
Pēteris Caune 5 years ago
parent
commit
f6d36b3491
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
9 changed files with 165 additions and 15 deletions
  1. +5
    -0
      hc/front/forms.py
  2. +32
    -0
      hc/front/tests/test_add_pd.py
  3. +1
    -0
      hc/front/urls.py
  4. +28
    -10
      hc/front/views.py
  5. BIN
      static/img/integrations/setup_pd_s1.png
  6. BIN
      static/img/integrations/setup_pd_s2.png
  7. +5
    -3
      templates/front/channels.html
  8. +0
    -2
      templates/front/welcome.html
  9. +94
    -0
      templates/integrations/add_pd.html

+ 5
- 0
hc/front/forms.py View File

@ -175,3 +175,8 @@ class AddMatrixForm(forms.Form):
class AddAppriseForm(forms.Form):
error_css_class = "has-error"
url = forms.CharField(max_length=512)
class AddPdForm(forms.Form):
error_css_class = "has-error"
value = forms.CharField(max_length=32)

+ 32
- 0
hc/front/tests/test_add_pd.py View File

@ -0,0 +1,32 @@
from hc.api.models import Channel
from hc.test import BaseTestCase
class AddPdTestCase(BaseTestCase):
url = "/integrations/add_pd/"
def test_instructions_work(self):
self.client.login(username="[email protected]", password="password")
r = self.client.get(self.url)
self.assertContains(r, "Paste the Integration Key down below")
def test_it_works(self):
# Integration key is 32 characters long
form = {"value": "12345678901234567890123456789012"}
self.client.login(username="[email protected]", password="password")
r = self.client.post(self.url, form)
self.assertRedirects(r, "/integrations/")
c = Channel.objects.get()
self.assertEqual(c.kind, "pd")
self.assertEqual(c.value, "12345678901234567890123456789012")
def test_it_trims_whitespace(self):
form = {"value": " 123456 "}
self.client.login(username="[email protected]", password="password")
self.client.post(self.url, form)
c = Channel.objects.get()
self.assertEqual(c.value, "123456")

+ 1
- 0
hc/front/urls.py View File

@ -27,6 +27,7 @@ channel_urls = [
path("add_email/", views.add_email, name="hc-add-email"),
path("add_webhook/", views.add_webhook, name="hc-add-webhook"),
path("add_shell/", views.add_shell, name="hc-add-shell"),
path("add_pd/", views.add_pd, name="hc-add-pd"),
path("add_pdc/", views.add_pdc, name="hc-add-pdc"),
path("add_pdc/<str:state>/", views.add_pdc, name="hc-add-pdc-state"),
path("add_pagertree/", views.add_pagertree, name="hc-add-pagertree"),


+ 28
- 10
hc/front/views.py View File

@ -34,19 +34,20 @@ from hc.api.models import (
)
from hc.api.transports import Telegram
from hc.front.forms import (
AddWebhookForm,
NameTagsForm,
TimeoutForm,
AddUrlForm,
AddAppriseForm,
AddEmailForm,
AddMatrixForm,
AddOpsGenieForm,
CronForm,
AddPdForm,
AddShellForm,
AddSmsForm,
AddUrlForm,
AddWebhookForm,
ChannelNameForm,
CronForm,
EmailSettingsForm,
AddMatrixForm,
AddAppriseForm,
AddShellForm,
NameTagsForm,
TimeoutForm,
)
from hc.front.schemas import telegram_callback
from hc.front.templatetags.hc_extras import num_down_title, down_title, sortchecks
@ -252,7 +253,6 @@ def index(request):
"enable_telegram": settings.TELEGRAM_TOKEN is not None,
"enable_sms": settings.TWILIO_AUTH is not None,
"enable_whatsapp": settings.TWILIO_USE_WHATSAPP,
"enable_pd": settings.PD_VENDOR_KEY is not None,
"enable_trello": settings.TRELLO_APP_KEY is not None,
"enable_matrix": settings.MATRIX_ACCESS_TOKEN is not None,
"enable_apprise": settings.APPRISE_ENABLED is True,
@ -649,7 +649,7 @@ def channels(request):
"enable_telegram": settings.TELEGRAM_TOKEN is not None,
"enable_sms": settings.TWILIO_AUTH is not None,
"enable_whatsapp": settings.TWILIO_USE_WHATSAPP,
"enable_pd": settings.PD_VENDOR_KEY is not None,
"enable_pdc": settings.PD_VENDOR_KEY is not None,
"enable_trello": settings.TRELLO_APP_KEY is not None,
"enable_matrix": settings.MATRIX_ACCESS_TOKEN is not None,
"enable_apprise": settings.APPRISE_ENABLED is True,
@ -863,6 +863,24 @@ def _get_validated_code(request, session_key, key="code"):
return request.GET.get(key)
@login_required
def add_pd(request):
if request.method == "POST":
form = AddPdForm(request.POST)
if form.is_valid():
channel = Channel(project=request.project, kind="pd")
channel.value = form.cleaned_data["value"]
channel.save()
channel.assign_all_checks()
return redirect("hc-channels")
else:
form = AddPdForm()
ctx = {"page": "channels", "form": form}
return render(request, "integrations/add_pd.html", ctx)
def add_pdc(request, state=None):
if settings.PD_VENDOR_KEY is None:
raise Http404("pagerduty integration is not available")


BIN
static/img/integrations/setup_pd_s1.png View File

Before After
Width: 770  |  Height: 678  |  Size: 60 KiB

BIN
static/img/integrations/setup_pd_s2.png View File

Before After
Width: 856  |  Height: 300  |  Size: 28 KiB

+ 5
- 3
templates/front/channels.html View File

@ -251,7 +251,6 @@
<a href="{% url 'hc-add-opsgenie' %}" class="btn btn-primary">Add Integration</a>
</li>
{% if enable_pd %}
<li>
<img src="{% static 'img/integrations/pd.png' %}"
class="icon" alt="PagerDuty icon" />
@ -259,9 +258,12 @@
<h2>PagerDuty</h2>
<p>On-call scheduling, alerting, and incident tracking.</p>
<a href="{% url 'hc-add-pdc' %}" class="btn btn-primary">Add Integration</a>
{% if enable_pdc %}
<a href="{% url 'hc-add-pdc' %}" class="btn btn-primary">Add Integration</a>
{% else %}
<a href="{% url 'hc-add-pd' %}" class="btn btn-primary">Add Integration</a>
{% endif %}
</li>
{% endif %}
<li>
<img src="{% static 'img/integrations/pagerteam.png' %}"


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

@ -378,14 +378,12 @@
</div>
</div>
{% if enable_pd %}
<div class="col-md-2 col-sm-4 col-xs-6">
<div class="integration">
<img src="{% static 'img/integrations/pd.png' %}" class="icon" alt="" />
<h3>PagerDuty<br><small>Incident Management</small></h3>
</div>
</div>
{% endif %}
<div class="col-md-2 col-sm-4 col-xs-6">
<div class="integration">


+ 94
- 0
templates/integrations/add_pd.html View File

@ -0,0 +1,94 @@
{% extends "base.html" %}
{% load compress humanize staticfiles hc_extras %}
{% block title %}Add PagerDuty - {% site_name %}{% endblock %}
{% block content %}
<div class="row">
<div class="col-sm-12">
<h1>PagerDuty</h1>
<p>
If your team uses <a href="https://www.pagerduty.com/">PagerDuty</a>,
you can set up {% site_name %} to create a PagerDuty incident
when a check goes down, and resolve it when a check goes back up.
</p>
<h2>Setup Guide</h2>
<div class="row ai-step">
<div class="col-sm-6">
<span class="step-no">1</span>
<p>
Log into your PagerDuty account,
go to <strong>Configuration &gt; Services</strong>,
and click on <strong>New Service</strong>.
</p>
<p>
Give it a descriptive name, and
for Integration Type select
<strong>Use our API directly</strong>.
</p>
</div>
<div class="col-sm-6">
<img
class="ai-guide-screenshot"
alt="Screenshot"
src="{% static 'img/integrations/setup_pd_s1.png' %}">
</div>
</div>
<div class="row ai-step">
<div class="col-sm-6">
<span class="step-no">2</span>
After adding the new service, take note of its
<strong>Integration Key</strong>, a long string
of letters and digits.
</div>
<div class="col-sm-6">
<img
class="ai-guide-screenshot"
alt="Screenshot"
src="{% static 'img/integrations/setup_pd_s2.png' %}">
</div>
</div>
<div class="row ai-step">
<div class="col-sm-6">
<span class="step-no">3</span>
<p>Paste the Integration Key down below. Save the integration, and it's done!</p>
</div>
</div>
<h2>Integration Settings</h2>
<form method="post" class="form-horizontal" action="{% url 'hc-add-pd' %}">
{% csrf_token %}
<div class="form-group {{ form.value.css_classes }}">
<label for="api-key" class="col-sm-2 control-label">Integration Key</label>
<div class="col-sm-4">
<input
id="api-key"
type="text"
class="form-control"
name="value"
placeholder=""
value="{{ form.value.value|default:"" }}">
{% if form.value.errors %}
<div class="help-block">
{{ form.value.errors|join:"" }}
</div>
{% endif %}
</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 %}

Loading…
Cancel
Save