forked from GithubBackups/healthchecks
Add the SPIKE_ENABLED setting
This commit is contained in:
parent
725be65bdd
commit
8811640d45
@ -21,6 +21,7 @@ All notable changes to this project will be documented in this file.
|
|||||||
- Add the PD_ENABLED setting (#471)
|
- Add the PD_ENABLED setting (#471)
|
||||||
- Add the PAGERTREE_ENABLED setting (#471)
|
- Add the PAGERTREE_ENABLED setting (#471)
|
||||||
- Add the PROMETHEUS_ENABLED setting (#471)
|
- Add the PROMETHEUS_ENABLED setting (#471)
|
||||||
|
- Add the SPIKE_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
|
||||||
|
@ -52,6 +52,7 @@ SITE_ROOT=http://localhost:8000
|
|||||||
SLACK_CLIENT_ID=
|
SLACK_CLIENT_ID=
|
||||||
SLACK_CLIENT_SECRET=
|
SLACK_CLIENT_SECRET=
|
||||||
SLACK_ENABLED=True
|
SLACK_ENABLED=True
|
||||||
|
SPIKE_ENABLED=True
|
||||||
TELEGRAM_BOT_NAME=ExampleBot
|
TELEGRAM_BOT_NAME=ExampleBot
|
||||||
TELEGRAM_TOKEN=
|
TELEGRAM_TOKEN=
|
||||||
TRELLO_APP_KEY=
|
TRELLO_APP_KEY=
|
||||||
|
44
hc/api/tests/test_notify_spike.py
Normal file
44
hc/api/tests/test_notify_spike.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(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.")
|
@ -668,6 +668,9 @@ class Zulip(HttpTransport):
|
|||||||
|
|
||||||
class Spike(HttpTransport):
|
class Spike(HttpTransport):
|
||||||
def notify(self, check):
|
def notify(self, check):
|
||||||
|
if not settings.SPIKE_ENABLED:
|
||||||
|
return "Spike 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 AddSpikeTestCase(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(SPIKE_ENABLED=False)
|
||||||
|
def test_it_requires_spike_enabled(self):
|
||||||
|
self.client.login(username="alice@example.org", password="password")
|
||||||
|
r = self.client.get(self.url)
|
||||||
|
self.assertEqual(r.status_code, 404)
|
||||||
|
@ -309,6 +309,7 @@ def index(request):
|
|||||||
"enable_slack": settings.SLACK_ENABLED is True,
|
"enable_slack": settings.SLACK_ENABLED is True,
|
||||||
"enable_slack_btn": settings.SLACK_CLIENT_ID is not None,
|
"enable_slack_btn": settings.SLACK_CLIENT_ID is not None,
|
||||||
"enable_sms": settings.TWILIO_AUTH 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_telegram": settings.TELEGRAM_TOKEN is not None,
|
||||||
"enable_trello": settings.TRELLO_APP_KEY is not None,
|
"enable_trello": settings.TRELLO_APP_KEY is not None,
|
||||||
"enable_webhooks": settings.WEBHOOKS_ENABLED is True,
|
"enable_webhooks": settings.WEBHOOKS_ENABLED is True,
|
||||||
@ -783,6 +784,7 @@ def channels(request, code):
|
|||||||
"enable_slack": settings.SLACK_ENABLED is True,
|
"enable_slack": settings.SLACK_ENABLED is True,
|
||||||
"enable_slack_btn": settings.SLACK_CLIENT_ID is not None,
|
"enable_slack_btn": settings.SLACK_CLIENT_ID is not None,
|
||||||
"enable_sms": settings.TWILIO_AUTH 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_telegram": settings.TELEGRAM_TOKEN is not None,
|
||||||
"enable_trello": settings.TRELLO_APP_KEY is not None,
|
"enable_trello": settings.TRELLO_APP_KEY is not None,
|
||||||
"enable_webhooks": settings.WEBHOOKS_ENABLED is True,
|
"enable_webhooks": settings.WEBHOOKS_ENABLED is True,
|
||||||
@ -1875,6 +1877,7 @@ def metrics(request, code, key):
|
|||||||
return HttpResponse(output(checks), content_type="text/plain")
|
return HttpResponse(output(checks), content_type="text/plain")
|
||||||
|
|
||||||
|
|
||||||
|
@require_setting("SPIKE_ENABLED")
|
||||||
@login_required
|
@login_required
|
||||||
def add_spike(request, code):
|
def add_spike(request, code):
|
||||||
project = _get_rw_project_for_user(request, code)
|
project = _get_rw_project_for_user(request, code)
|
||||||
|
@ -239,6 +239,9 @@ SLACK_CLIENT_ID = os.getenv("SLACK_CLIENT_ID")
|
|||||||
SLACK_CLIENT_SECRET = os.getenv("SLACK_CLIENT_SECRET")
|
SLACK_CLIENT_SECRET = os.getenv("SLACK_CLIENT_SECRET")
|
||||||
SLACK_ENABLED = envbool("SLACK_ENABLED", "True")
|
SLACK_ENABLED = envbool("SLACK_ENABLED", "True")
|
||||||
|
|
||||||
|
# Spike.sh
|
||||||
|
SPIKE_ENABLED = envbool("SPIKE_ENABLED", "True")
|
||||||
|
|
||||||
# Telegram integration -- override in local_settings.py
|
# Telegram integration -- override in local_settings.py
|
||||||
TELEGRAM_BOT_NAME = os.getenv("TELEGRAM_BOT_NAME", "ExampleBot")
|
TELEGRAM_BOT_NAME = os.getenv("TELEGRAM_BOT_NAME", "ExampleBot")
|
||||||
TELEGRAM_TOKEN = os.getenv("TELEGRAM_TOKEN")
|
TELEGRAM_TOKEN = os.getenv("TELEGRAM_TOKEN")
|
||||||
|
@ -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>
|
<h2 id="SLACK_ENABLED"><code>SLACK_ENABLED</code></h2>
|
||||||
<p>Default: <code>True</code></p>
|
<p>Default: <code>True</code></p>
|
||||||
<p>A boolean that turns on/off the Slack integration. Enabled by default.</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>
|
<h2 id="TELEGRAM_BOT_NAME"><code>TELEGRAM_BOT_NAME</code></h2>
|
||||||
<p>Default: <code>ExampleBot</code></p>
|
<p>Default: <code>ExampleBot</code></p>
|
||||||
<p>The <a href="https://telegram.org/">Telegram</a> bot name, required by the Telegram integration.</p>
|
<p>The <a href="https://telegram.org/">Telegram</a> bot name, required by the Telegram integration.</p>
|
||||||
|
@ -492,6 +492,12 @@ Default: `True`
|
|||||||
|
|
||||||
A boolean that turns on/off the Slack integration. Enabled by default.
|
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 }
|
## `TELEGRAM_BOT_NAME` {: #TELEGRAM_BOT_NAME }
|
||||||
|
|
||||||
Default: `ExampleBot`
|
Default: `ExampleBot`
|
||||||
|
@ -402,6 +402,7 @@
|
|||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if enable_spike %}
|
||||||
<li>
|
<li>
|
||||||
<img src="{% static 'img/integrations/spike.png' %}" class="icon" alt="Spike.sh icon" />
|
<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>
|
<a href="{% url 'hc-add-spike' project.code %}" class="btn btn-primary">Add Integration</a>
|
||||||
</li>
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if enable_telegram %}
|
{% if enable_telegram %}
|
||||||
<li>
|
<li>
|
||||||
|
@ -614,7 +614,8 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% 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">
|
<div class="integration">
|
||||||
<img src="{% static 'img/integrations/spike.png' %}" class="icon" alt="Spike.sh icon" />
|
<img src="{% static 'img/integrations/spike.png' %}" class="icon" alt="Spike.sh icon" />
|
||||||
<h3>
|
<h3>
|
||||||
@ -623,6 +624,7 @@
|
|||||||
</h3>
|
</h3>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if enable_telegram %}
|
{% if enable_telegram %}
|
||||||
<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