Browse Source

Add the PAGERTREE_ENABLED setting

pull/474/head
Pēteris Caune 4 years ago
parent
commit
419d96da7a
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
12 changed files with 76 additions and 13 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +1
    -0
      docker/.env
  3. +0
    -12
      hc/api/tests/test_notify.py
  4. +44
    -0
      hc/api/tests/test_notify_pagertree.py
  5. +3
    -0
      hc/api/transports.py
  6. +7
    -0
      hc/front/tests/test_add_pagertree.py
  7. +3
    -0
      hc/front/views.py
  8. +3
    -0
      hc/settings.py
  9. +4
    -1
      templates/docs/self_hosted_configuration.html
  10. +6
    -0
      templates/docs/self_hosted_configuration.md
  11. +2
    -0
      templates/front/channels.html
  12. +2
    -0
      templates/front/welcome.html

+ 1
- 0
CHANGELOG.md View File

@ -19,6 +19,7 @@ All notable changes to this project will be documented in this file.
- Add the MSTEAMS_ENABLED setting (#471)
- Add the OPSGENIE_ENABLED setting (#471)
- Add the PD_ENABLED setting (#471)
- Add the PAGERTREE_ENABLED setting (#471)
## Bug Fixes
- Fix unwanted HTML escaping in SMS and WhatsApp notifications


+ 1
- 0
docker/.env View File

@ -28,6 +28,7 @@ MATRIX_USER_ID=
MATTERMOST_ENABLED=True
MSTEAMS_ENABLED=True
OPSGENIE_ENABLED=True
PAGERTREE_ENABLED=True
PD_ENABLED=True
PD_VENDOR_KEY=
PING_BODY_LIMIT=10000


+ 0
- 12
hc/api/tests/test_notify.py View File

@ -25,18 +25,6 @@ class NotifyTestCase(BaseTestCase):
self.channel.save()
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")
def test_pagerteam(self, mock_post):
self._setup_data("pagerteam", "123")


+ 44
- 0
hc/api/tests/test_notify_pagertree.py View 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.")

+ 3
- 0
hc/api/transports.py View File

@ -336,6 +336,9 @@ class PagerDuty(HttpTransport):
class PagerTree(HttpTransport):
def notify(self, check):
if not settings.PAGERTREE_ENABLED:
return "PagerTree notifications are not enabled."
url = self.channel.value
headers = {"Conent-Type": "application/json"}
payload = {


+ 7
- 0
hc/front/tests/test_add_pagertree.py View File

@ -1,3 +1,4 @@
from django.test.utils import override_settings
from hc.api.models import Channel
from hc.test import BaseTestCase
@ -38,3 +39,9 @@ class AddPagerTreeTestCase(BaseTestCase):
self.client.login(username="[email protected]", password="password")
r = self.client.get(self.url)
self.assertEqual(r.status_code, 403)
@override_settings(PAGERTREE_ENABLED=False)
def test_it_handles_disabled_integration(self):
self.client.login(username="[email protected]", password="password")
r = self.client.get(self.url)
self.assertEqual(r.status_code, 404)

+ 3
- 0
hc/front/views.py View File

@ -298,6 +298,7 @@ def index(request):
"enable_mattermost": settings.MATTERMOST_ENABLED is True,
"enable_msteams": settings.MSTEAMS_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_pdc": settings.PD_VENDOR_KEY 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_msteams": settings.MSTEAMS_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_pdc": settings.PD_VENDOR_KEY 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)
@require_setting("PAGERTREE_ENABLED")
@login_required
def add_pagertree(request, code):
project = _get_rw_project_for_user(request, code)


+ 3
- 0
hc/settings.py View File

@ -208,6 +208,9 @@ MSTEAMS_ENABLED = envbool("MSTEAMS_ENABLED", "True")
# Opsgenie
OPSGENIE_ENABLED = envbool("OPSGENIE_ENABLED", "True")
# PagerTree
PAGERTREE_ENABLED = envbool("PAGERTREE_ENABLED", "True")
# PagerDuty
PD_ENABLED = envbool("PD_ENABLED", "True")
PD_VENDOR_KEY = os.getenv("PD_VENDOR_KEY")


+ 4
- 1
templates/docs/self_hosted_configuration.html View File

@ -149,9 +149,12 @@ integration.</p>
<h2 id="OPSGENIE_ENABLED"><code>OPSGENIE_ENABLED</code></h2>
<p>Default: <code>True</code></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>
<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>
<p>Default: <code>None</code></p>
<p><a href="https://www.pagerduty.com/">PagerDuty</a> vendor key, used by the PagerDuty integration.</p>


+ 6
- 0
templates/docs/self_hosted_configuration.md View File

@ -248,6 +248,12 @@ Default: `True`
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 }
Default: `True`


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

@ -314,6 +314,7 @@
</li>
{% endif %}
{% if enable_pagertree %}
<li>
<img src="{% static 'img/integrations/pagertree.png' %}"
class="icon" alt="PagerTree icon" />
@ -322,6 +323,7 @@
<p>DevOps Incident Management - On-Call Schedules, Alerts, &amp; Notifications.</p>
<a href="{% url 'hc-add-pagertree' project.code %}" class="btn btn-primary">Add Integration</a>
</li>
{% endif %}
{% if enable_call %}
<li>


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

@ -518,6 +518,7 @@
</div>
{% endif %}
{% if enable_pagertree %}
<div class="col-lg-2 col-md-3 col-sm-4 col-xs-6">
<div class="integration">
<img src="{% static 'img/integrations/pagertree.png' %}" class="icon" alt="" />
@ -527,6 +528,7 @@
</h3>
</div>
</div>
{% endif %}
{% if enable_call %}
<div class="col-lg-2 col-md-3 col-sm-4 col-xs-6">


Loading…
Cancel
Save