forked from GithubBackups/healthchecks
Add the PAGERTREE_ENABLED setting
This commit is contained in:
parent
28150e85fa
commit
419d96da7a
@ -19,6 +19,7 @@ All notable changes to this project will be documented in this file.
|
|||||||
- 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)
|
- Add the PD_ENABLED setting (#471)
|
||||||
|
- Add the PAGERTREE_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
|
||||||
|
PAGERTREE_ENABLED=True
|
||||||
PD_ENABLED=True
|
PD_ENABLED=True
|
||||||
PD_VENDOR_KEY=
|
PD_VENDOR_KEY=
|
||||||
PING_BODY_LIMIT=10000
|
PING_BODY_LIMIT=10000
|
||||||
|
@ -25,18 +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_pagertree(self, mock_post):
|
|
||||||
self._setup_data("pagertree", "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")
|
@patch("hc.api.transports.requests.request")
|
||||||
def test_pagerteam(self, mock_post):
|
def test_pagerteam(self, mock_post):
|
||||||
self._setup_data("pagerteam", "123")
|
self._setup_data("pagerteam", "123")
|
||||||
|
44
hc/api/tests/test_notify_pagertree.py
Normal file
44
hc/api/tests/test_notify_pagertree.py
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
# coding: utf-8
|
||||||
|
|
||||||
|
from datetime import timedelta as td
|
||||||
|
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 = "pagertree"
|
||||||
|
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_pagertree(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")
|
||||||
|
|
||||||
|
@override_settings(PAGERTREE_ENABLED=False)
|
||||||
|
def test_it_requires_pagertree_enabled(self):
|
||||||
|
self._setup_data("123")
|
||||||
|
self.channel.notify(self.check)
|
||||||
|
|
||||||
|
n = Notification.objects.get()
|
||||||
|
self.assertEqual(n.error, "PagerTree notifications are not enabled.")
|
@ -336,6 +336,9 @@ class PagerDuty(HttpTransport):
|
|||||||
|
|
||||||
class PagerTree(HttpTransport):
|
class PagerTree(HttpTransport):
|
||||||
def notify(self, check):
|
def notify(self, check):
|
||||||
|
if not settings.PAGERTREE_ENABLED:
|
||||||
|
return "PagerTree notifications are not enabled."
|
||||||
|
|
||||||
url = self.channel.value
|
url = self.channel.value
|
||||||
headers = {"Conent-Type": "application/json"}
|
headers = {"Conent-Type": "application/json"}
|
||||||
payload = {
|
payload = {
|
||||||
|
@ -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
|
||||||
|
|
||||||
@ -38,3 +39,9 @@ class AddPagerTreeTestCase(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(PAGERTREE_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)
|
||||||
|
@ -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_pagertree": settings.PAGERTREE_ENABLED is True,
|
||||||
"enable_pd": settings.PD_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,
|
||||||
@ -770,6 +771,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_pagertree": settings.PAGERTREE_ENABLED is True,
|
||||||
"enable_pd": settings.PD_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,
|
||||||
@ -1106,6 +1108,7 @@ def add_pdc_complete(request, code, state):
|
|||||||
return redirect("hc-channels", project.code)
|
return redirect("hc-channels", project.code)
|
||||||
|
|
||||||
|
|
||||||
|
@require_setting("PAGERTREE_ENABLED")
|
||||||
@login_required
|
@login_required
|
||||||
def add_pagertree(request, code):
|
def add_pagertree(request, code):
|
||||||
project = _get_rw_project_for_user(request, code)
|
project = _get_rw_project_for_user(request, code)
|
||||||
|
@ -208,6 +208,9 @@ MSTEAMS_ENABLED = envbool("MSTEAMS_ENABLED", "True")
|
|||||||
# Opsgenie
|
# Opsgenie
|
||||||
OPSGENIE_ENABLED = envbool("OPSGENIE_ENABLED", "True")
|
OPSGENIE_ENABLED = envbool("OPSGENIE_ENABLED", "True")
|
||||||
|
|
||||||
|
# PagerTree
|
||||||
|
PAGERTREE_ENABLED = envbool("PAGERTREE_ENABLED", "True")
|
||||||
|
|
||||||
# PagerDuty
|
# PagerDuty
|
||||||
PD_ENABLED = envbool("PD_ENABLED", "True")
|
PD_ENABLED = envbool("PD_ENABLED", "True")
|
||||||
PD_VENDOR_KEY = os.getenv("PD_VENDOR_KEY")
|
PD_VENDOR_KEY = os.getenv("PD_VENDOR_KEY")
|
||||||
|
@ -149,9 +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="PAGERTREE_ENABLED"><code>PAGERTREE_ENABLED</code></h2>
|
||||||
|
<p>Default: <code>True</code></p>
|
||||||
|
<p>A boolean that turns on/off the PagerTree integration. Enabled by default.</p>
|
||||||
<h2 id="PD_ENABLED"><code>PD_ENABLED</code></h2>
|
<h2 id="PD_ENABLED"><code>PD_ENABLED</code></h2>
|
||||||
<p>Default: <code>True</code></p>
|
<p>Default: <code>True</code></p>
|
||||||
<p>A boolean that turns on/off the Pagerduty integration. Enabled by default.</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, used by the PagerDuty integration.</p>
|
<p><a href="https://www.pagerduty.com/">PagerDuty</a> vendor key, used by the PagerDuty integration.</p>
|
||||||
|
@ -248,6 +248,12 @@ 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.
|
||||||
|
|
||||||
|
## `PAGERTREE_ENABLED` {: #PAGERTREE_ENABLED }
|
||||||
|
|
||||||
|
Default: `True`
|
||||||
|
|
||||||
|
A boolean that turns on/off the PagerTree integration. Enabled by default.
|
||||||
|
|
||||||
## `PD_ENABLED` {: #PD_ENABLED }
|
## `PD_ENABLED` {: #PD_ENABLED }
|
||||||
|
|
||||||
Default: `True`
|
Default: `True`
|
||||||
|
@ -314,6 +314,7 @@
|
|||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if enable_pagertree %}
|
||||||
<li>
|
<li>
|
||||||
<img src="{% static 'img/integrations/pagertree.png' %}"
|
<img src="{% static 'img/integrations/pagertree.png' %}"
|
||||||
class="icon" alt="PagerTree icon" />
|
class="icon" alt="PagerTree icon" />
|
||||||
@ -322,6 +323,7 @@
|
|||||||
<p>DevOps Incident Management - On-Call Schedules, Alerts, & Notifications.</p>
|
<p>DevOps Incident Management - On-Call Schedules, Alerts, & Notifications.</p>
|
||||||
<a href="{% url 'hc-add-pagertree' project.code %}" class="btn btn-primary">Add Integration</a>
|
<a href="{% url 'hc-add-pagertree' project.code %}" class="btn btn-primary">Add Integration</a>
|
||||||
</li>
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if enable_call %}
|
{% if enable_call %}
|
||||||
<li>
|
<li>
|
||||||
|
@ -518,6 +518,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if enable_pagertree %}
|
||||||
<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">
|
||||||
<img src="{% static 'img/integrations/pagertree.png' %}" class="icon" alt="" />
|
<img src="{% static 'img/integrations/pagertree.png' %}" class="icon" alt="" />
|
||||||
@ -527,6 +528,7 @@
|
|||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if enable_call %}
|
{% if enable_call %}
|
||||||
<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">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user