forked from GithubBackups/healthchecks
Add the PD_ENABLED setting
This commit is contained in:
parent
8d5890d883
commit
28150e85fa
@ -18,6 +18,7 @@ All notable changes to this project will be documented in this file.
|
|||||||
- Add the MATTERMOST_ENABLED setting (#471)
|
- Add the MATTERMOST_ENABLED setting (#471)
|
||||||
- Add the MSTEAMS_ENABLED setting (#471)
|
- Add the MSTEAMS_ENABLED setting (#471)
|
||||||
- Add the OPSGENIE_ENABLED setting (#471)
|
- Add the OPSGENIE_ENABLED setting (#471)
|
||||||
|
- Add the PD_ENABLED setting (#471)
|
||||||
|
|
||||||
## Bug Fixes
|
## Bug Fixes
|
||||||
- Fix unwanted HTML escaping in SMS and WhatsApp notifications
|
- Fix unwanted HTML escaping in SMS and WhatsApp notifications
|
||||||
|
@ -28,6 +28,7 @@ MATRIX_USER_ID=
|
|||||||
MATTERMOST_ENABLED=True
|
MATTERMOST_ENABLED=True
|
||||||
MSTEAMS_ENABLED=True
|
MSTEAMS_ENABLED=True
|
||||||
OPSGENIE_ENABLED=True
|
OPSGENIE_ENABLED=True
|
||||||
|
PD_ENABLED=True
|
||||||
PD_VENDOR_KEY=
|
PD_VENDOR_KEY=
|
||||||
PING_BODY_LIMIT=10000
|
PING_BODY_LIMIT=10000
|
||||||
PING_EMAIL_DOMAIN=localhost
|
PING_EMAIL_DOMAIN=localhost
|
||||||
|
@ -25,32 +25,6 @@ class NotifyTestCase(BaseTestCase):
|
|||||||
self.channel.save()
|
self.channel.save()
|
||||||
self.channel.checks.add(self.check)
|
self.channel.checks.add(self.check)
|
||||||
|
|
||||||
@patch("hc.api.transports.requests.request")
|
|
||||||
def test_pd(self, mock_post):
|
|
||||||
self._setup_data("pd", "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")
|
|
||||||
self.assertEqual(payload["service_key"], "123")
|
|
||||||
|
|
||||||
@patch("hc.api.transports.requests.request")
|
|
||||||
def test_pd_complex(self, mock_post):
|
|
||||||
self._setup_data("pd", json.dumps({"service_key": "456"}))
|
|
||||||
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")
|
|
||||||
self.assertEqual(payload["service_key"], "456")
|
|
||||||
|
|
||||||
@patch("hc.api.transports.requests.request")
|
@patch("hc.api.transports.requests.request")
|
||||||
def test_pagertree(self, mock_post):
|
def test_pagertree(self, mock_post):
|
||||||
self._setup_data("pagertree", "123")
|
self._setup_data("pagertree", "123")
|
||||||
|
59
hc/api/tests/test_notify_pd.py
Normal file
59
hc/api/tests/test_notify_pd.py
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
from datetime import timedelta as td
|
||||||
|
import json
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from django.utils.timezone import now
|
||||||
|
from hc.api.models import Channel, Check, Notification
|
||||||
|
from hc.test import BaseTestCase
|
||||||
|
from django.test.utils import override_settings
|
||||||
|
|
||||||
|
|
||||||
|
class NotifyTestCase(BaseTestCase):
|
||||||
|
def _setup_data(self, value, status="down", email_verified=True):
|
||||||
|
self.check = Check(project=self.project)
|
||||||
|
self.check.status = status
|
||||||
|
self.check.last_ping = now() - td(minutes=61)
|
||||||
|
self.check.save()
|
||||||
|
|
||||||
|
self.channel = Channel(project=self.project)
|
||||||
|
self.channel.kind = "pd"
|
||||||
|
self.channel.value = value
|
||||||
|
self.channel.email_verified = email_verified
|
||||||
|
self.channel.save()
|
||||||
|
self.channel.checks.add(self.check)
|
||||||
|
|
||||||
|
@patch("hc.api.transports.requests.request")
|
||||||
|
def test_pd(self, mock_post):
|
||||||
|
self._setup_data("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")
|
||||||
|
self.assertEqual(payload["service_key"], "123")
|
||||||
|
|
||||||
|
@patch("hc.api.transports.requests.request")
|
||||||
|
def test_pd_complex(self, mock_post):
|
||||||
|
self._setup_data(json.dumps({"service_key": "456"}))
|
||||||
|
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")
|
||||||
|
self.assertEqual(payload["service_key"], "456")
|
||||||
|
|
||||||
|
@override_settings(PD_ENABLED=False)
|
||||||
|
def test_it_requires_pd_enabled(self):
|
||||||
|
self._setup_data("123")
|
||||||
|
self.channel.notify(self.check)
|
||||||
|
|
||||||
|
n = Notification.objects.get()
|
||||||
|
self.assertEqual(n.error, "PagerDuty notifications are not enabled.")
|
@ -318,6 +318,9 @@ class PagerDuty(HttpTransport):
|
|||||||
URL = "https://events.pagerduty.com/generic/2010-04-15/create_event.json"
|
URL = "https://events.pagerduty.com/generic/2010-04-15/create_event.json"
|
||||||
|
|
||||||
def notify(self, check):
|
def notify(self, check):
|
||||||
|
if not settings.PD_ENABLED:
|
||||||
|
return "PagerDuty notifications are not enabled."
|
||||||
|
|
||||||
description = tmpl("pd_description.html", check=check)
|
description = tmpl("pd_description.html", check=check)
|
||||||
payload = {
|
payload = {
|
||||||
"service_key": self.channel.pd_service_key,
|
"service_key": self.channel.pd_service_key,
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from django.test.utils import override_settings
|
||||||
from hc.api.models import Channel
|
from hc.api.models import Channel
|
||||||
from hc.test import BaseTestCase
|
from hc.test import BaseTestCase
|
||||||
|
|
||||||
@ -40,3 +41,9 @@ class AddPdTestCase(BaseTestCase):
|
|||||||
self.client.login(username="bob@example.org", password="password")
|
self.client.login(username="bob@example.org", password="password")
|
||||||
r = self.client.get(self.url)
|
r = self.client.get(self.url)
|
||||||
self.assertEqual(r.status_code, 403)
|
self.assertEqual(r.status_code, 403)
|
||||||
|
|
||||||
|
@override_settings(PD_ENABLED=False)
|
||||||
|
def test_it_handles_disabled_integration(self):
|
||||||
|
self.client.login(username="alice@example.org", password="password")
|
||||||
|
r = self.client.get(self.url)
|
||||||
|
self.assertEqual(r.status_code, 404)
|
||||||
|
@ -31,6 +31,13 @@ class AddPdConnectTestCase(BaseTestCase):
|
|||||||
r = self.client.get(self.url)
|
r = self.client.get(self.url)
|
||||||
self.assertEqual(r.status_code, 404)
|
self.assertEqual(r.status_code, 404)
|
||||||
|
|
||||||
|
@override_settings(PD_ENABLED=False)
|
||||||
|
def test_it_requires_pd_enabled(self):
|
||||||
|
self.client.login(username="alice@example.org", password="password")
|
||||||
|
|
||||||
|
r = self.client.get(self.url)
|
||||||
|
self.assertEqual(r.status_code, 404)
|
||||||
|
|
||||||
def test_it_requires_rw_access(self):
|
def test_it_requires_rw_access(self):
|
||||||
self.bobs_membership.rw = False
|
self.bobs_membership.rw = False
|
||||||
self.bobs_membership.save()
|
self.bobs_membership.save()
|
||||||
|
@ -25,6 +25,13 @@ class AddPdcCompleteTestCase(BaseTestCase):
|
|||||||
r = self.client.get(self.url)
|
r = self.client.get(self.url)
|
||||||
self.assertEqual(r.status_code, 404)
|
self.assertEqual(r.status_code, 404)
|
||||||
|
|
||||||
|
@override_settings(PD_ENABLED=False)
|
||||||
|
def test_it_requires_pd_enabled(self):
|
||||||
|
self.client.login(username="alice@example.org", password="password")
|
||||||
|
|
||||||
|
r = self.client.get(self.url)
|
||||||
|
self.assertEqual(r.status_code, 404)
|
||||||
|
|
||||||
def test_it_requires_rw_access(self):
|
def test_it_requires_rw_access(self):
|
||||||
self.bobs_membership.rw = False
|
self.bobs_membership.rw = False
|
||||||
self.bobs_membership.save()
|
self.bobs_membership.save()
|
||||||
|
@ -298,6 +298,7 @@ def index(request):
|
|||||||
"enable_mattermost": settings.MATTERMOST_ENABLED is True,
|
"enable_mattermost": settings.MATTERMOST_ENABLED is True,
|
||||||
"enable_msteams": settings.MSTEAMS_ENABLED is True,
|
"enable_msteams": settings.MSTEAMS_ENABLED is True,
|
||||||
"enable_opsgenie": settings.OPSGENIE_ENABLED is True,
|
"enable_opsgenie": settings.OPSGENIE_ENABLED is True,
|
||||||
|
"enable_pd": settings.PD_ENABLED is True,
|
||||||
"enable_pdc": settings.PD_VENDOR_KEY is not None,
|
"enable_pdc": settings.PD_VENDOR_KEY is not None,
|
||||||
"enable_pushbullet": settings.PUSHBULLET_CLIENT_ID is not None,
|
"enable_pushbullet": settings.PUSHBULLET_CLIENT_ID is not None,
|
||||||
"enable_pushover": settings.PUSHOVER_API_TOKEN is not None,
|
"enable_pushover": settings.PUSHOVER_API_TOKEN is not None,
|
||||||
@ -769,6 +770,7 @@ def channels(request, code):
|
|||||||
"enable_mattermost": settings.MATTERMOST_ENABLED is True,
|
"enable_mattermost": settings.MATTERMOST_ENABLED is True,
|
||||||
"enable_msteams": settings.MSTEAMS_ENABLED is True,
|
"enable_msteams": settings.MSTEAMS_ENABLED is True,
|
||||||
"enable_opsgenie": settings.OPSGENIE_ENABLED is True,
|
"enable_opsgenie": settings.OPSGENIE_ENABLED is True,
|
||||||
|
"enable_pd": settings.PD_ENABLED is True,
|
||||||
"enable_pdc": settings.PD_VENDOR_KEY is not None,
|
"enable_pdc": settings.PD_VENDOR_KEY is not None,
|
||||||
"enable_pushbullet": settings.PUSHBULLET_CLIENT_ID is not None,
|
"enable_pushbullet": settings.PUSHBULLET_CLIENT_ID is not None,
|
||||||
"enable_pushover": settings.PUSHOVER_API_TOKEN is not None,
|
"enable_pushover": settings.PUSHOVER_API_TOKEN is not None,
|
||||||
@ -1027,6 +1029,7 @@ def add_shell(request, code):
|
|||||||
return render(request, "integrations/add_shell.html", ctx)
|
return render(request, "integrations/add_shell.html", ctx)
|
||||||
|
|
||||||
|
|
||||||
|
@require_setting("PD_ENABLED")
|
||||||
@login_required
|
@login_required
|
||||||
def add_pd(request, code):
|
def add_pd(request, code):
|
||||||
project = _get_rw_project_for_user(request, code)
|
project = _get_rw_project_for_user(request, code)
|
||||||
@ -1047,12 +1050,14 @@ def add_pd(request, code):
|
|||||||
return render(request, "integrations/add_pd.html", ctx)
|
return render(request, "integrations/add_pd.html", ctx)
|
||||||
|
|
||||||
|
|
||||||
|
@require_setting("PD_ENABLED")
|
||||||
@require_setting("PD_VENDOR_KEY")
|
@require_setting("PD_VENDOR_KEY")
|
||||||
def pdc_help(request):
|
def pdc_help(request):
|
||||||
ctx = {"page": "channels"}
|
ctx = {"page": "channels"}
|
||||||
return render(request, "integrations/add_pdc.html", ctx)
|
return render(request, "integrations/add_pdc.html", ctx)
|
||||||
|
|
||||||
|
|
||||||
|
@require_setting("PD_ENABLED")
|
||||||
@require_setting("PD_VENDOR_KEY")
|
@require_setting("PD_VENDOR_KEY")
|
||||||
@login_required
|
@login_required
|
||||||
def add_pdc(request, code):
|
def add_pdc(request, code):
|
||||||
@ -1071,6 +1076,7 @@ def add_pdc(request, code):
|
|||||||
return render(request, "integrations/add_pdc.html", ctx)
|
return render(request, "integrations/add_pdc.html", ctx)
|
||||||
|
|
||||||
|
|
||||||
|
@require_setting("PD_ENABLED")
|
||||||
@require_setting("PD_VENDOR_KEY")
|
@require_setting("PD_VENDOR_KEY")
|
||||||
@login_required
|
@login_required
|
||||||
def add_pdc_complete(request, code, state):
|
def add_pdc_complete(request, code, state):
|
||||||
|
@ -209,6 +209,7 @@ MSTEAMS_ENABLED = envbool("MSTEAMS_ENABLED", "True")
|
|||||||
OPSGENIE_ENABLED = envbool("OPSGENIE_ENABLED", "True")
|
OPSGENIE_ENABLED = envbool("OPSGENIE_ENABLED", "True")
|
||||||
|
|
||||||
# PagerDuty
|
# PagerDuty
|
||||||
|
PD_ENABLED = envbool("PD_ENABLED", "True")
|
||||||
PD_VENDOR_KEY = os.getenv("PD_VENDOR_KEY")
|
PD_VENDOR_KEY = os.getenv("PD_VENDOR_KEY")
|
||||||
|
|
||||||
# Pushover integration
|
# Pushover integration
|
||||||
|
@ -149,10 +149,12 @@ integration.</p>
|
|||||||
<h2 id="OPSGENIE_ENABLED"><code>OPSGENIE_ENABLED</code></h2>
|
<h2 id="OPSGENIE_ENABLED"><code>OPSGENIE_ENABLED</code></h2>
|
||||||
<p>Default: <code>True</code></p>
|
<p>Default: <code>True</code></p>
|
||||||
<p>A boolean that turns on/off the Opsgenie integration. Enabled by default.</p>
|
<p>A boolean that turns on/off the Opsgenie integration. Enabled by default.</p>
|
||||||
|
<h2 id="PD_ENABLED"><code>PD_ENABLED</code></h2>
|
||||||
|
<p>Default: <code>True</code></p>
|
||||||
|
<p>A boolean that turns on/off the Pagerduty integration. Enabled by default.</p>
|
||||||
<h2 id="PD_VENDOR_KEY"><code>PD_VENDOR_KEY</code></h2>
|
<h2 id="PD_VENDOR_KEY"><code>PD_VENDOR_KEY</code></h2>
|
||||||
<p>Default: <code>None</code></p>
|
<p>Default: <code>None</code></p>
|
||||||
<p><a href="https://www.pagerduty.com/">PagerDuty</a> vendor key,
|
<p><a href="https://www.pagerduty.com/">PagerDuty</a> vendor key, used by the PagerDuty integration.</p>
|
||||||
required by the PagerDuty integration.</p>
|
|
||||||
<h2 id="PING_BODY_LIMIT"><code>PING_BODY_LIMIT</code></h2>
|
<h2 id="PING_BODY_LIMIT"><code>PING_BODY_LIMIT</code></h2>
|
||||||
<p>Default: <code>10000</code></p>
|
<p>Default: <code>10000</code></p>
|
||||||
<p>The upper size limit in bytes for logged ping request bodies.
|
<p>The upper size limit in bytes for logged ping request bodies.
|
||||||
|
@ -248,12 +248,17 @@ Default: `True`
|
|||||||
|
|
||||||
A boolean that turns on/off the Opsgenie integration. Enabled by default.
|
A boolean that turns on/off the Opsgenie integration. Enabled by default.
|
||||||
|
|
||||||
|
## `PD_ENABLED` {: #PD_ENABLED }
|
||||||
|
|
||||||
|
Default: `True`
|
||||||
|
|
||||||
|
A boolean that turns on/off the PagerDuty integration. Enabled by default.
|
||||||
|
|
||||||
## `PD_VENDOR_KEY` {: #PD_VENDOR_KEY }
|
## `PD_VENDOR_KEY` {: #PD_VENDOR_KEY }
|
||||||
|
|
||||||
Default: `None`
|
Default: `None`
|
||||||
|
|
||||||
[PagerDuty](https://www.pagerduty.com/) vendor key,
|
[PagerDuty](https://www.pagerduty.com/) vendor key, used by the PagerDuty integration.
|
||||||
required by the PagerDuty integration.
|
|
||||||
|
|
||||||
## `PING_BODY_LIMIT` {: #PING_BODY_LIMIT }
|
## `PING_BODY_LIMIT` {: #PING_BODY_LIMIT }
|
||||||
|
|
||||||
|
@ -298,6 +298,7 @@
|
|||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if enable_pd %}
|
||||||
<li>
|
<li>
|
||||||
<img src="{% static 'img/integrations/pd.png' %}"
|
<img src="{% static 'img/integrations/pd.png' %}"
|
||||||
class="icon" alt="PagerDuty icon" />
|
class="icon" alt="PagerDuty icon" />
|
||||||
@ -311,6 +312,7 @@
|
|||||||
<a href="{% url 'hc-add-pd' project.code %}" class="btn btn-primary">Add Integration</a>
|
<a href="{% url 'hc-add-pd' project.code %}" class="btn btn-primary">Add Integration</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</li>
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<li>
|
<li>
|
||||||
<img src="{% static 'img/integrations/pagertree.png' %}"
|
<img src="{% static 'img/integrations/pagertree.png' %}"
|
||||||
|
@ -496,6 +496,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if enable_pd %}
|
||||||
<div class="col-lg-2 col-md-3 col-sm-4 col-xs-6">
|
<div class="col-lg-2 col-md-3 col-sm-4 col-xs-6">
|
||||||
{% if enable_pdc %}
|
{% if enable_pdc %}
|
||||||
<a href="{% url 'hc-pdc-help' %}" class="integration">
|
<a href="{% url 'hc-pdc-help' %}" class="integration">
|
||||||
@ -515,6 +516,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
<div class="col-lg-2 col-md-3 col-sm-4 col-xs-6">
|
<div class="col-lg-2 col-md-3 col-sm-4 col-xs-6">
|
||||||
<div class="integration">
|
<div class="integration">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user