Browse Source

Add the VICTOROPS_ENABLED setting

pull/476/head
Pēteris Caune 4 years ago
parent
commit
e2c90c05b8
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
12 changed files with 77 additions and 12 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_victorops.py
  5. +3
    -0
      hc/api/transports.py
  6. +7
    -0
      hc/front/tests/test_add_victorops.py
  7. +3
    -0
      hc/front/views.py
  8. +3
    -0
      hc/settings.py
  9. +4
    -0
      templates/docs/self_hosted_configuration.html
  10. +7
    -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

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


+ 1
- 0
docker/.env View File

@ -61,4 +61,5 @@ TWILIO_AUTH=
TWILIO_FROM=
TWILIO_USE_WHATSAPP=False
USE_PAYMENTS=False
VICTOROPS_ENABLED=True
WEBHOOKS_ENABLED=True

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

@ -41,18 +41,6 @@ class NotifyTestCase(BaseTestCase):
self.assertFalse(mock_post.called)
self.assertEqual(Notification.objects.count(), 0)
@patch("hc.api.transports.requests.request")
def test_victorops(self, mock_post):
self._setup_data("victorops", "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["message_type"], "CRITICAL")
@patch("hc.api.transports.requests.request")
def test_discord(self, mock_post):
v = json.dumps({"webhook": {"url": "123"}})


+ 44
- 0
hc/api/tests/test_notify_victorops.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 = "victorops"
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_victorops(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["message_type"], "CRITICAL")
@override_settings(VICTOROPS_ENABLED=False)
def test_it_requires_victorops_enabled(self):
self._setup_data("123")
self.channel.notify(self.check)
n = Notification.objects.get()
self.assertEqual(n.error, "VictorOps notifications are not enabled.")

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

@ -413,6 +413,9 @@ class Pushover(HttpTransport):
class VictorOps(HttpTransport):
def notify(self, check):
if not settings.VICTOROPS_ENABLED:
return "VictorOps notifications are not enabled."
description = tmpl("victorops_description.html", check=check)
mtype = "CRITICAL" if check.status == "down" else "RECOVERY"
payload = {


+ 7
- 0
hc/front/tests/test_add_victorops.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 AddVictorOpsTestCase(BaseTestCase):
self.client.login(username="[email protected]", password="password")
r = self.client.get(self.url)
self.assertEqual(r.status_code, 403)
@override_settings(VICTOROPS_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

@ -312,6 +312,7 @@ def index(request):
"enable_spike": settings.SPIKE_ENABLED is True,
"enable_telegram": settings.TELEGRAM_TOKEN is not None,
"enable_trello": settings.TRELLO_APP_KEY is not None,
"enable_victorops": settings.VICTOROPS_ENABLED is True,
"enable_webhooks": settings.WEBHOOKS_ENABLED is True,
"enable_whatsapp": settings.TWILIO_USE_WHATSAPP,
"registration_open": settings.REGISTRATION_OPEN,
@ -787,6 +788,7 @@ def channels(request, code):
"enable_spike": settings.SPIKE_ENABLED is True,
"enable_telegram": settings.TELEGRAM_TOKEN is not None,
"enable_trello": settings.TRELLO_APP_KEY is not None,
"enable_victorops": settings.VICTOROPS_ENABLED is True,
"enable_webhooks": settings.WEBHOOKS_ENABLED is True,
"enable_whatsapp": settings.TWILIO_USE_WHATSAPP,
"use_payments": settings.USE_PAYMENTS,
@ -1469,6 +1471,7 @@ def add_opsgenie(request, code):
return render(request, "integrations/add_opsgenie.html", ctx)
@require_setting("VICTOROPS_ENABLED")
@login_required
def add_victorops(request, code):
project = _get_rw_project_for_user(request, code)


+ 3
- 0
hc/settings.py View File

@ -255,6 +255,9 @@ TWILIO_USE_WHATSAPP = envbool("TWILIO_USE_WHATSAPP", "False")
# Trello
TRELLO_APP_KEY = os.getenv("TRELLO_APP_KEY")
# VictorOps
VICTOROPS_ENABLED = envbool("VICTOROPS_ENABLED", "True")
# Webhooks
WEBHOOKS_ENABLED = envbool("WEBHOOKS_ENABLED", "True")


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

@ -349,6 +349,10 @@ scheme.</p>
<h2 id="USE_PAYMENTS"><code>USE_PAYMENTS</code></h2>
<p>Default: <code>False</code></p>
<p>A boolean that turns on/off billing features.</p>
<h2 id="VICTOROPS_ENABLED"><code>VICTOROPS_ENABLED</code></h2>
<p>Default: <code>True</code></p>
<p>A boolean that turns on/off the Splunk On-Call (VictorOps) integration.
Enabled by default.</p>
<h2 id="WEBHOOKS_ENABLED"><code>WEBHOOKS_ENABLED</code></h2>
<p>Default: <code>True</code></p>
<p>A boolean that turns on/off the Webhooks integration. Enabled by default.</p>

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

@ -561,6 +561,13 @@ Default: `False`
A boolean that turns on/off billing features.
## `VICTOROPS_ENABLED` {: #VICTOROPS_ENABLED }
Default: `True`
A boolean that turns on/off the Splunk On-Call (VictorOps) integration.
Enabled by default.
## `WEBHOOKS_ENABLED` {: #WEBHOOKS_ENABLED }
Default: `True`


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

@ -435,6 +435,7 @@
</li>
{% endif %}
{% if enable_victorops %}
<li>
<img src="{% static 'img/integrations/victorops.png' %}"
class="icon" alt="VictorOps icon" />
@ -443,6 +444,7 @@
<p>On-call scheduling, alerting, and incident tracking.</p>
<a href="{% url 'hc-add-victorops' project.code %}" class="btn btn-primary">Add Integration</a>
</li>
{% endif %}
{% if enable_whatsapp %}
<li>


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

@ -650,6 +650,7 @@
</div>
{% endif %}
{% if enable_victorops %}
<div class="col-lg-2 col-md-3 col-sm-4 col-xs-6">
<div class="integration">
<img src="{% static 'img/integrations/victorops.png' %}" class="icon" alt="" />
@ -659,6 +660,7 @@
</h3>
</div>
</div>
{% endif %}
{% if enable_whatsapp %}
<div class="col-lg-2 col-md-3 col-sm-4 col-xs-6">


Loading…
Cancel
Save