diff --git a/hc/api/migrations/0058_auto_20190312_1716.py b/hc/api/migrations/0058_auto_20190312_1716.py index dbd86a39..17f827f4 100644 --- a/hc/api/migrations/0058_auto_20190312_1716.py +++ b/hc/api/migrations/0058_auto_20190312_1716.py @@ -13,6 +13,6 @@ class Migration(migrations.Migration): migrations.AlterField( model_name='channel', name='kind', - field=models.CharField(choices=[('email', 'Email'), ('webhook', 'Webhook'), ('hipchat', 'HipChat'), ('slack', 'Slack'), ('pd', 'PagerDuty'), ('pagertree', 'PagerTree'), ('po', 'Pushover'), ('pushbullet', 'Pushbullet'), ('opsgenie', 'OpsGenie'), ('victorops', 'VictorOps'), ('discord', 'Discord'), ('telegram', 'Telegram'), ('sms', 'SMS'), ('zendesk', 'Zendesk'), ('trello', 'Trello'), ('matrix', 'Matrix')], max_length=20), + field=models.CharField(choices=[('email', 'Email'), ('webhook', 'Webhook'), ('hipchat', 'HipChat'), ('slack', 'Slack'), ('pd', 'PagerDuty'), ('pagertree', 'PagerTree'), ('pagerteam', 'PagerTeam') ('po', 'Pushover'), ('pushbullet', 'Pushbullet'), ('opsgenie', 'OpsGenie'), ('victorops', 'VictorOps'), ('discord', 'Discord'), ('telegram', 'Telegram'), ('sms', 'SMS'), ('zendesk', 'Zendesk'), ('trello', 'Trello'), ('matrix', 'Matrix')], max_length=20), ), ] diff --git a/hc/api/models.py b/hc/api/models.py index 562a9138..19ddfc3f 100644 --- a/hc/api/models.py +++ b/hc/api/models.py @@ -33,6 +33,7 @@ CHANNEL_KINDS = (("email", "Email"), ("slack", "Slack"), ("pd", "PagerDuty"), ("pagertree", "PagerTree"), + ("pagerteam", "PagerTeam"), ("po", "Pushover"), ("pushbullet", "Pushbullet"), ("opsgenie", "OpsGenie"), @@ -322,6 +323,8 @@ class Channel(models.Model): return transports.PagerDuty(self) elif self.kind == "pagertree": return transports.PagerTree(self) + elif self.kind == "pagerteam": + return transports.PagerTeam(self) elif self.kind == "victorops": return transports.VictorOps(self) elif self.kind == "pushbullet": diff --git a/hc/api/tests/test_notify.py b/hc/api/tests/test_notify.py index 641df621..ca5ffb19 100644 --- a/hc/api/tests/test_notify.py +++ b/hc/api/tests/test_notify.py @@ -294,6 +294,18 @@ class NotifyTestCase(BaseTestCase): payload = kwargs["json"] self.assertEqual(payload["event_type"], "trigger") + @patch("hc.api.transports.requests.request") + def test_pagerteam(self, mock_post): + self._setup_data("pagerteam", "123") + mock_post.return_value.status_code = 200 + + self.channel.notify(self.check) + assert Notification.objects.count() == 1 + + args, kwargs = mock_post.call_args + payload = kwargs["json"] + self.assertEqual(payload["event_type"], "trigger") + @patch("hc.api.transports.requests.request") def test_slack(self, mock_post): self._setup_data("slack", "123") diff --git a/hc/api/transports.py b/hc/api/transports.py index 72e21b05..a9797289 100644 --- a/hc/api/transports.py +++ b/hc/api/transports.py @@ -269,6 +269,24 @@ class PagerTree(HttpTransport): return self.post(url, json=payload, headers=headers) +class PagerTeam(HttpTransport): + def notify(self, check): + url = self.channel.value + headers = { + "Conent-Type": "application/json" + } + payload = { + "incident_key": str(check.code), + "event_type": "trigger" if check.status == "down" else "resolve", + "title": tmpl("pagerteam_title.html", check=check), + "description": tmpl("pagerteam_description.html", check=check), + "client": settings.SITE_NAME, + "client_url": settings.SITE_ROOT, + "tags": ",".join(check.tags_list()) + } + + return self.post(url, json=payload, headers=headers) + class Pushbullet(HttpTransport): def notify(self, check): diff --git a/hc/front/urls.py b/hc/front/urls.py index 92e1163d..ae51beeb 100644 --- a/hc/front/urls.py +++ b/hc/front/urls.py @@ -24,6 +24,7 @@ channel_urls = [ path('add_pd/', views.add_pd, name="hc-add-pd"), path('add_pd//', views.add_pd, name="hc-add-pd-state"), path('add_pagertree/', views.add_pagertree, name="hc-add-pagertree"), + path('add_pagerteam/', views.add_pagerteam, name="hc-add-pagerteam"), path('add_slack/', views.add_slack, name="hc-add-slack"), path('add_slack_btn/', views.add_slack_btn, name="hc-add-slack-btn"), path('add_pushbullet/', views.add_pushbullet, name="hc-add-pushbullet"), diff --git a/hc/front/views.py b/hc/front/views.py index c7fd0737..9542fe7a 100644 --- a/hc/front/views.py +++ b/hc/front/views.py @@ -749,6 +749,23 @@ def add_pagertree(request): ctx = {"page": "channels", "form": form} return render(request, "integrations/add_pagertree.html", ctx) +@login_required +def add_pagerteam(request): + if request.method == "POST": + form = AddUrlForm(request.POST) + if form.is_valid(): + channel = Channel(project=request.project, kind="pagerteam") + channel.value = form.cleaned_data["value"] + channel.save() + + channel.assign_all_checks() + return redirect("hc-channels") + else: + form = AddUrlForm() + + ctx = {"page": "channels", "form": form} + return render(request, "integrations/add_pagerteam.html", ctx) + def add_slack(request): if not settings.SLACK_CLIENT_ID and not request.user.is_authenticated: diff --git a/templates/front/channels.html b/templates/front/channels.html index a8bfd522..31cbc96b 100644 --- a/templates/front/channels.html +++ b/templates/front/channels.html @@ -47,6 +47,8 @@ PagerDuty account {{ ch.pd_account }} {% elif ch.kind == "pagertree" %} PagerTree + {% elif ch.kind == "pagerteam" %} + PagerTeam {% elif ch.kind == "opsgenie" %} OpsGenie {% elif ch.kind == "victorops" %} diff --git a/templates/front/details_events.html b/templates/front/details_events.html index 22f300b4..f01f2468 100644 --- a/templates/front/details_events.html +++ b/templates/front/details_events.html @@ -64,6 +64,8 @@ Sent alert to PagerDuty {% elif event.channel.kind == "pagertree" %} Sent alert to PagerTree + {% elif event.channel.kind == "pagerteam" %} + Sent alert to Pager Team {% elif event.channel.kind == "opsgenie" %} Sent alert to OpsGenie {% elif event.channel.kind == "hipchat" %} @@ -92,4 +94,4 @@ {% endif %} {% else %}
This check has not received any pings yet.
-{% endif %} \ No newline at end of file +{% endif %} diff --git a/templates/front/log.html b/templates/front/log.html index 45807b7a..00bc0483 100644 --- a/templates/front/log.html +++ b/templates/front/log.html @@ -107,6 +107,8 @@ Sent alert to PagerDuty {% elif event.channel.kind == "pagertree" %} Sent alert to PagerTree + {% elif event.channel.kind == "pagerteam" %} + Sent alert to Pager Team {% elif event.channel.kind == "opsgenie" %} Sent alert to OpsGenie {% elif event.channel.kind == "hipchat" %} diff --git a/templates/front/welcome.html b/templates/front/welcome.html index ea95c22e..5a7d43df 100644 --- a/templates/front/welcome.html +++ b/templates/front/welcome.html @@ -399,6 +399,13 @@ +
+
+ Pager Team icon +

Pager Team
On-call rotations without limits

+
+
+ {% if enable_trello %}