forked from GithubBackups/healthchecks
Add the ZULIP_ENABLED setting
This commit is contained in:
parent
e2c90c05b8
commit
65ace8238a
11
CHANGELOG.md
11
CHANGELOG.md
@ -13,16 +13,7 @@ All notable changes to this project will be documented in this file.
|
||||
- Add a section in Docs about running self-hosted instances
|
||||
- Add experimental Dockerfile and docker-compose.yml
|
||||
- Add rate limiting for Pushover notifications (6 notifications / user / minute)
|
||||
- Add the WEBHOOKS_ENABLED setting (#471)
|
||||
- Add the SLACK_ENABLED setting (#471)
|
||||
- Add the MATTERMOST_ENABLED setting (#471)
|
||||
- Add the MSTEAMS_ENABLED setting (#471)
|
||||
- Add the OPSGENIE_ENABLED setting (#471)
|
||||
- Add the PD_ENABLED setting (#471)
|
||||
- Add the PAGERTREE_ENABLED setting (#471)
|
||||
- Add the PROMETHEUS_ENABLED setting (#471)
|
||||
- Add the SPIKE_ENABLED setting (#471)
|
||||
- Add the VICTOROPS_ENABLED setting (#471)
|
||||
- Add support for disabling specific integration types (#471)
|
||||
|
||||
## Bug Fixes
|
||||
- Fix unwanted HTML escaping in SMS and WhatsApp notifications
|
||||
|
@ -62,4 +62,5 @@ TWILIO_FROM=
|
||||
TWILIO_USE_WHATSAPP=False
|
||||
USE_PAYMENTS=False
|
||||
VICTOROPS_ENABLED=True
|
||||
WEBHOOKS_ENABLED=True
|
||||
WEBHOOKS_ENABLED=True
|
||||
ZULIP_ENABLED=True
|
@ -4,20 +4,21 @@ from datetime import timedelta as td
|
||||
import json
|
||||
from unittest.mock import patch
|
||||
|
||||
from django.test.utils import override_settings
|
||||
from django.utils.timezone import now
|
||||
from hc.api.models import Channel, Check, Notification
|
||||
from hc.test import BaseTestCase
|
||||
|
||||
|
||||
class NotifyTestCase(BaseTestCase):
|
||||
def _setup_data(self, kind, value, status="down", email_verified=True):
|
||||
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 = kind
|
||||
self.channel.kind = "zulip"
|
||||
self.channel.value = value
|
||||
self.channel.email_verified = email_verified
|
||||
self.channel.save()
|
||||
@ -31,7 +32,7 @@ class NotifyTestCase(BaseTestCase):
|
||||
"mtype": "stream",
|
||||
"to": "general",
|
||||
}
|
||||
self._setup_data("zulip", json.dumps(definition))
|
||||
self._setup_data(json.dumps(definition))
|
||||
mock_post.return_value.status_code = 200
|
||||
|
||||
self.channel.notify(self.check)
|
||||
@ -53,7 +54,7 @@ class NotifyTestCase(BaseTestCase):
|
||||
"mtype": "stream",
|
||||
"to": "general",
|
||||
}
|
||||
self._setup_data("zulip", json.dumps(definition))
|
||||
self._setup_data(json.dumps(definition))
|
||||
mock_post.return_value.status_code = 403
|
||||
mock_post.return_value.json.return_value = {"msg": "Nice try"}
|
||||
|
||||
@ -71,7 +72,7 @@ class NotifyTestCase(BaseTestCase):
|
||||
"mtype": "stream",
|
||||
"to": "general",
|
||||
}
|
||||
self._setup_data("zulip", json.dumps(definition))
|
||||
self._setup_data(json.dumps(definition))
|
||||
mock_post.return_value.status_code = 200
|
||||
|
||||
self.channel.notify(self.check)
|
||||
@ -84,3 +85,18 @@ class NotifyTestCase(BaseTestCase):
|
||||
|
||||
payload = kwargs["data"]
|
||||
self.assertIn("DOWN", payload["topic"])
|
||||
|
||||
@override_settings(ZULIP_ENABLED=False)
|
||||
def test_it_requires_zulip_enabled(self):
|
||||
definition = {
|
||||
"bot_email": "bot@example.org",
|
||||
"api_key": "fake-key",
|
||||
"mtype": "stream",
|
||||
"to": "general",
|
||||
}
|
||||
self._setup_data(json.dumps(definition))
|
||||
|
||||
self.channel.notify(self.check)
|
||||
|
||||
n = Notification.objects.get()
|
||||
self.assertEqual(n.error, "Zulip notifications are not enabled.")
|
||||
|
@ -657,6 +657,9 @@ class Zulip(HttpTransport):
|
||||
pass
|
||||
|
||||
def notify(self, check):
|
||||
if not settings.ZULIP_ENABLED:
|
||||
return "Zulip notifications are not enabled."
|
||||
|
||||
url = self.channel.zulip_site + "/api/v1/messages"
|
||||
auth = (self.channel.zulip_bot_email, self.channel.zulip_api_key)
|
||||
data = {
|
||||
|
@ -1,3 +1,4 @@
|
||||
from django.test.utils import override_settings
|
||||
from hc.api.models import Channel
|
||||
from hc.test import BaseTestCase
|
||||
|
||||
@ -80,3 +81,9 @@ class AddZulipTestCase(BaseTestCase):
|
||||
self.client.login(username="bob@example.org", password="password")
|
||||
r = self.client.get(self.url)
|
||||
self.assertEqual(r.status_code, 403)
|
||||
|
||||
@override_settings(ZULIP_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)
|
||||
|
@ -315,6 +315,7 @@ def index(request):
|
||||
"enable_victorops": settings.VICTOROPS_ENABLED is True,
|
||||
"enable_webhooks": settings.WEBHOOKS_ENABLED is True,
|
||||
"enable_whatsapp": settings.TWILIO_USE_WHATSAPP,
|
||||
"enable_zulip": settings.ZULIP_ENABLED is True,
|
||||
"registration_open": settings.REGISTRATION_OPEN,
|
||||
}
|
||||
|
||||
@ -791,6 +792,7 @@ def channels(request, code):
|
||||
"enable_victorops": settings.VICTOROPS_ENABLED is True,
|
||||
"enable_webhooks": settings.WEBHOOKS_ENABLED is True,
|
||||
"enable_whatsapp": settings.TWILIO_USE_WHATSAPP,
|
||||
"enable_zulip": settings.ZULIP_ENABLED is True,
|
||||
"use_payments": settings.USE_PAYMENTS,
|
||||
}
|
||||
|
||||
@ -1492,6 +1494,7 @@ def add_victorops(request, code):
|
||||
return render(request, "integrations/add_victorops.html", ctx)
|
||||
|
||||
|
||||
@require_setting("ZULIP_ENABLED")
|
||||
@login_required
|
||||
def add_zulip(request, code):
|
||||
project = _get_rw_project_for_user(request, code)
|
||||
|
@ -261,6 +261,9 @@ VICTOROPS_ENABLED = envbool("VICTOROPS_ENABLED", "True")
|
||||
# Webhooks
|
||||
WEBHOOKS_ENABLED = envbool("WEBHOOKS_ENABLED", "True")
|
||||
|
||||
# Zulip
|
||||
ZULIP_ENABLED = envbool("ZULIP_ENABLED", "True")
|
||||
|
||||
# Read additional configuration from hc/local_settings.py if it exists
|
||||
if os.path.exists(os.path.join(BASE_DIR, "hc/local_settings.py")):
|
||||
from .local_settings import *
|
||||
|
@ -355,4 +355,7 @@ scheme.</p>
|
||||
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>
|
||||
<p>A boolean that turns on/off the Webhooks integration. Enabled by default.</p>
|
||||
<h2 id="ZULIP_ENABLED"><code>ZULIP_ENABLED</code></h2>
|
||||
<p>Default: <code>True</code></p>
|
||||
<p>A boolean that turns on/off the Zulip integration. Enabled by default.</p>
|
@ -573,3 +573,9 @@ Enabled by default.
|
||||
Default: `True`
|
||||
|
||||
A boolean that turns on/off the Webhooks integration. Enabled by default.
|
||||
|
||||
## `ZULIP_ENABLED` {: #ZULIP_ENABLED }
|
||||
|
||||
Default: `True`
|
||||
|
||||
A boolean that turns on/off the Zulip integration. Enabled by default.
|
@ -457,6 +457,7 @@
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
{% if enable_zulip %}
|
||||
<li>
|
||||
<img src="{% static 'img/integrations/zulip.png' %}"
|
||||
class="icon" alt="Zulip icon" />
|
||||
@ -465,6 +466,7 @@
|
||||
<p>Open-source group chat.</p>
|
||||
<a href="{% url 'hc-add-zulip' project.code %}" class="btn btn-primary">Add Integration</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
|
||||
<li class="link-to-github">
|
||||
<img src="{% static 'img/integrations/missing.png' %}"
|
||||
|
@ -674,6 +674,7 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if enable_zulip %}
|
||||
<div class="col-lg-2 col-md-3 col-sm-4 col-xs-6">
|
||||
<div class="integration">
|
||||
<img src="{% static 'img/integrations/zulip.png' %}" class="icon" alt="" />
|
||||
@ -683,6 +684,7 @@
|
||||
</h3>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="row tour-section">
|
||||
|
Loading…
x
Reference in New Issue
Block a user