Browse Source

Add the SPIKE_ENABLED setting

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

+ 1
- 0
CHANGELOG.md View File

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


+ 1
- 0
docker/.env View File

@ -52,6 +52,7 @@ SITE_ROOT=http://localhost:8000
SLACK_CLIENT_ID=
SLACK_CLIENT_SECRET=
SLACK_ENABLED=True
SPIKE_ENABLED=True
TELEGRAM_BOT_NAME=ExampleBot
TELEGRAM_TOKEN=
TRELLO_APP_KEY=


+ 44
- 0
hc/api/tests/test_notify_spike.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(self):
super().setUp()
self.check = Check(project=self.project)
self.check.name = "Foo"
self.check.status = "down"
self.check.last_ping = now() - td(minutes=61)
self.check.save()
self.channel = Channel(project=self.project)
self.channel.kind = "spike"
self.channel.value = "https://spike.example.org"
self.channel.save()
self.channel.checks.add(self.check)
@patch("hc.api.transports.requests.request")
def test_it_works(self, mock_post):
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["check_id"], str(self.check.code))
self.assertEqual(payload["title"], "Foo is DOWN")
@override_settings(SPIKE_ENABLED=False)
def test_it_requires_spike_enabled(self):
self.channel.notify(self.check)
n = Notification.objects.get()
self.assertEqual(n.error, "Spike notifications are not enabled.")

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

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


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

@ -309,6 +309,7 @@ def index(request):
"enable_slack": settings.SLACK_ENABLED is True,
"enable_slack_btn": settings.SLACK_CLIENT_ID is not None,
"enable_sms": settings.TWILIO_AUTH is not None,
"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_webhooks": settings.WEBHOOKS_ENABLED is True,
@ -783,6 +784,7 @@ def channels(request, code):
"enable_slack": settings.SLACK_ENABLED is True,
"enable_slack_btn": settings.SLACK_CLIENT_ID is not None,
"enable_sms": settings.TWILIO_AUTH is not None,
"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_webhooks": settings.WEBHOOKS_ENABLED is True,
@ -1875,6 +1877,7 @@ def metrics(request, code, key):
return HttpResponse(output(checks), content_type="text/plain")
@require_setting("SPIKE_ENABLED")
@login_required
def add_spike(request, code):
project = _get_rw_project_for_user(request, code)


+ 3
- 0
hc/settings.py View File

@ -239,6 +239,9 @@ SLACK_CLIENT_ID = os.getenv("SLACK_CLIENT_ID")
SLACK_CLIENT_SECRET = os.getenv("SLACK_CLIENT_SECRET")
SLACK_ENABLED = envbool("SLACK_ENABLED", "True")
# Spike.sh
SPIKE_ENABLED = envbool("SPIKE_ENABLED", "True")
# Telegram integration -- override in local_settings.py
TELEGRAM_BOT_NAME = os.getenv("TELEGRAM_BOT_NAME", "ExampleBot")
TELEGRAM_TOKEN = os.getenv("TELEGRAM_TOKEN")


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

@ -306,6 +306,9 @@ Look it up at <a href="https://api.slack.com/apps/">https://api.slack.com/apps/<
<h2 id="SLACK_ENABLED"><code>SLACK_ENABLED</code></h2>
<p>Default: <code>True</code></p>
<p>A boolean that turns on/off the Slack integration. Enabled by default.</p>
<h2 id="SPIKE_ENABLED"><code>SPIKE_ENABLED</code></h2>
<p>Default: <code>True</code></p>
<p>A boolean that turns on/off the Spike.sh integration. Enabled by default.</p>
<h2 id="TELEGRAM_BOT_NAME"><code>TELEGRAM_BOT_NAME</code></h2>
<p>Default: <code>ExampleBot</code></p>
<p>The <a href="https://telegram.org/">Telegram</a> bot name, required by the Telegram integration.</p>


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

@ -492,6 +492,12 @@ Default: `True`
A boolean that turns on/off the Slack integration. Enabled by default.
## `SPIKE_ENABLED` {: #SPIKE_ENABLED }
Default: `True`
A boolean that turns on/off the Spike.sh integration. Enabled by default.
## `TELEGRAM_BOT_NAME` {: #TELEGRAM_BOT_NAME }
Default: `ExampleBot`


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

@ -402,6 +402,7 @@
</li>
{% endif %}
{% if enable_spike %}
<li>
<img src="{% static 'img/integrations/spike.png' %}" class="icon" alt="Spike.sh icon" />
@ -410,6 +411,7 @@
<a href="{% url 'hc-add-spike' project.code %}" class="btn btn-primary">Add Integration</a>
</li>
{% endif %}
{% if enable_telegram %}
<li>


+ 3
- 1
templates/front/welcome.html View File

@ -614,7 +614,8 @@
</div>
{% endif %}
<div class="col-md-2 col-sm-4 col-xs-6">
{% if enable_spike %}
<div class="col-md-2 col-sm-4 col-xs-6">
<div class="integration">
<img src="{% static 'img/integrations/spike.png' %}" class="icon" alt="Spike.sh icon" />
<h3>
@ -623,6 +624,7 @@
</h3>
</div>
</div>
{% endif %}
{% if enable_telegram %}
<div class="col-lg-2 col-md-3 col-sm-4 col-xs-6">


Loading…
Cancel
Save