forked from GithubBackups/healthchecks
Add the PROMETHEUS_ENABLED setting
This commit is contained in:
parent
419d96da7a
commit
725be65bdd
@ -20,6 +20,7 @@ All notable changes to this project will be documented in this file.
|
|||||||
- Add the OPSGENIE_ENABLED setting (#471)
|
- Add the OPSGENIE_ENABLED setting (#471)
|
||||||
- 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)
|
||||||
|
|
||||||
## Bug Fixes
|
## Bug Fixes
|
||||||
- Fix unwanted HTML escaping in SMS and WhatsApp notifications
|
- Fix unwanted HTML escaping in SMS and WhatsApp notifications
|
||||||
|
@ -34,6 +34,7 @@ PD_VENDOR_KEY=
|
|||||||
PING_BODY_LIMIT=10000
|
PING_BODY_LIMIT=10000
|
||||||
PING_EMAIL_DOMAIN=localhost
|
PING_EMAIL_DOMAIN=localhost
|
||||||
PING_ENDPOINT=http://localhost:8000/ping/
|
PING_ENDPOINT=http://localhost:8000/ping/
|
||||||
|
PROMETHEUS_ENABLED=True
|
||||||
PUSHBULLET_CLIENT_ID=
|
PUSHBULLET_CLIENT_ID=
|
||||||
PUSHBULLET_CLIENT_SECRET=
|
PUSHBULLET_CLIENT_SECRET=
|
||||||
PUSHOVER_API_TOKEN=
|
PUSHOVER_API_TOKEN=
|
||||||
|
@ -35,6 +35,7 @@ class ProjectTestCase(BaseTestCase):
|
|||||||
|
|
||||||
self.assertContains(r, "X" * 32)
|
self.assertContains(r, "X" * 32)
|
||||||
self.assertContains(r, "R" * 32)
|
self.assertContains(r, "R" * 32)
|
||||||
|
self.assertContains(r, "Prometheus metrics endpoint")
|
||||||
|
|
||||||
def test_it_creates_api_key(self):
|
def test_it_creates_api_key(self):
|
||||||
self.client.login(username="alice@example.org", password="password")
|
self.client.login(username="alice@example.org", password="password")
|
||||||
@ -246,3 +247,16 @@ class ProjectTestCase(BaseTestCase):
|
|||||||
r = self.client.get(self.url)
|
r = self.client.get(self.url)
|
||||||
self.assertNotContains(r, "#set-project-name-modal", status_code=200)
|
self.assertNotContains(r, "#set-project-name-modal", status_code=200)
|
||||||
self.assertNotContains(r, "Show API Keys")
|
self.assertNotContains(r, "Show API Keys")
|
||||||
|
|
||||||
|
@override_settings(PROMETHEUS_ENABLED=False)
|
||||||
|
def test_it_hides_prometheus_link_if_prometheus_not_enabled(self):
|
||||||
|
self.project.api_key_readonly = "R" * 32
|
||||||
|
self.project.save()
|
||||||
|
|
||||||
|
self.client.login(username="alice@example.org", password="password")
|
||||||
|
|
||||||
|
form = {"show_api_keys": "1"}
|
||||||
|
r = self.client.post(self.url, form)
|
||||||
|
self.assertEqual(r.status_code, 200)
|
||||||
|
|
||||||
|
self.assertNotContains(r, "Prometheus metrics endpoint")
|
||||||
|
@ -291,6 +291,7 @@ def project(request, code):
|
|||||||
"project": project,
|
"project": project,
|
||||||
"is_owner": is_owner,
|
"is_owner": is_owner,
|
||||||
"show_api_keys": "show_api_keys" in request.GET,
|
"show_api_keys": "show_api_keys" in request.GET,
|
||||||
|
"enable_prometheus": settings.PROMETHEUS_ENABLED is True,
|
||||||
}
|
}
|
||||||
|
|
||||||
if request.method == "POST":
|
if request.method == "POST":
|
||||||
|
20
hc/front/tests/test_add_prometheus.py
Normal file
20
hc/front/tests/test_add_prometheus.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
from django.test.utils import override_settings
|
||||||
|
from hc.test import BaseTestCase
|
||||||
|
|
||||||
|
|
||||||
|
class AddPrometheusTestCase(BaseTestCase):
|
||||||
|
def setUp(self):
|
||||||
|
super().setUp()
|
||||||
|
self.url = "/projects/%s/add_prometheus/" % self.project.code
|
||||||
|
|
||||||
|
def test_instructions_work(self):
|
||||||
|
self.client.login(username="alice@example.org", password="password")
|
||||||
|
r = self.client.get(self.url)
|
||||||
|
self.assertContains(r, "Prometheus")
|
||||||
|
self.assertContains(r, f"{self.project.code}/metrics/")
|
||||||
|
|
||||||
|
@override_settings(PROMETHEUS_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)
|
@ -1,3 +1,4 @@
|
|||||||
|
from django.test.utils import override_settings
|
||||||
from hc.api.models import Check
|
from hc.api.models import Check
|
||||||
from hc.test import BaseTestCase
|
from hc.test import BaseTestCase
|
||||||
|
|
||||||
@ -41,3 +42,8 @@ class MetricsTestCase(BaseTestCase):
|
|||||||
url = "/projects/%s/checks/metrics/%s" % (self.project.code, "X" * 32)
|
url = "/projects/%s/checks/metrics/%s" % (self.project.code, "X" * 32)
|
||||||
r = self.client.get(url)
|
r = self.client.get(url)
|
||||||
self.assertEqual(r.status_code, 403)
|
self.assertEqual(r.status_code, 403)
|
||||||
|
|
||||||
|
@override_settings(PROMETHEUS_ENABLED=False)
|
||||||
|
def test_it_requires_prometheus_enabled(self):
|
||||||
|
r = self.client.get(self.url)
|
||||||
|
self.assertEqual(r.status_code, 404)
|
||||||
|
@ -301,6 +301,7 @@ def index(request):
|
|||||||
"enable_pagertree": settings.PAGERTREE_ENABLED is True,
|
"enable_pagertree": settings.PAGERTREE_ENABLED is True,
|
||||||
"enable_pd": settings.PD_ENABLED is True,
|
"enable_pd": settings.PD_ENABLED is True,
|
||||||
"enable_pdc": settings.PD_VENDOR_KEY is not None,
|
"enable_pdc": settings.PD_VENDOR_KEY is not None,
|
||||||
|
"enable_prometheus": settings.PROMETHEUS_ENABLED is True,
|
||||||
"enable_pushbullet": settings.PUSHBULLET_CLIENT_ID is not None,
|
"enable_pushbullet": settings.PUSHBULLET_CLIENT_ID is not None,
|
||||||
"enable_pushover": settings.PUSHOVER_API_TOKEN is not None,
|
"enable_pushover": settings.PUSHOVER_API_TOKEN is not None,
|
||||||
"enable_shell": settings.SHELL_ENABLED is True,
|
"enable_shell": settings.SHELL_ENABLED is True,
|
||||||
@ -774,6 +775,7 @@ def channels(request, code):
|
|||||||
"enable_pagertree": settings.PAGERTREE_ENABLED is True,
|
"enable_pagertree": settings.PAGERTREE_ENABLED is True,
|
||||||
"enable_pd": settings.PD_ENABLED is True,
|
"enable_pd": settings.PD_ENABLED is True,
|
||||||
"enable_pdc": settings.PD_VENDOR_KEY is not None,
|
"enable_pdc": settings.PD_VENDOR_KEY is not None,
|
||||||
|
"enable_prometheus": settings.PROMETHEUS_ENABLED is True,
|
||||||
"enable_pushbullet": settings.PUSHBULLET_CLIENT_ID is not None,
|
"enable_pushbullet": settings.PUSHBULLET_CLIENT_ID is not None,
|
||||||
"enable_pushover": settings.PUSHOVER_API_TOKEN is not None,
|
"enable_pushover": settings.PUSHOVER_API_TOKEN is not None,
|
||||||
"enable_shell": settings.SHELL_ENABLED is True,
|
"enable_shell": settings.SHELL_ENABLED is True,
|
||||||
@ -1818,6 +1820,7 @@ def add_msteams(request, code):
|
|||||||
return render(request, "integrations/add_msteams.html", ctx)
|
return render(request, "integrations/add_msteams.html", ctx)
|
||||||
|
|
||||||
|
|
||||||
|
@require_setting("PROMETHEUS_ENABLED")
|
||||||
@login_required
|
@login_required
|
||||||
def add_prometheus(request, code):
|
def add_prometheus(request, code):
|
||||||
project, rw = _get_project_for_user(request, code)
|
project, rw = _get_project_for_user(request, code)
|
||||||
@ -1825,6 +1828,7 @@ def add_prometheus(request, code):
|
|||||||
return render(request, "integrations/add_prometheus.html", ctx)
|
return render(request, "integrations/add_prometheus.html", ctx)
|
||||||
|
|
||||||
|
|
||||||
|
@require_setting("PROMETHEUS_ENABLED")
|
||||||
def metrics(request, code, key):
|
def metrics(request, code, key):
|
||||||
if len(key) != 32:
|
if len(key) != 32:
|
||||||
return HttpResponseBadRequest()
|
return HttpResponseBadRequest()
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
Django settings for healthchecks project.
|
Django settings for healthchecks project.
|
||||||
|
|
||||||
For the full list of settings and their values, see
|
For the full list of settings and their values, see
|
||||||
https://docs.djangoproject.com/en/2.1/ref/settings
|
https://docs.djangoproject.com/en/3.1/ref/settings/
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
@ -215,6 +215,9 @@ PAGERTREE_ENABLED = envbool("PAGERTREE_ENABLED", "True")
|
|||||||
PD_ENABLED = envbool("PD_ENABLED", "True")
|
PD_ENABLED = envbool("PD_ENABLED", "True")
|
||||||
PD_VENDOR_KEY = os.getenv("PD_VENDOR_KEY")
|
PD_VENDOR_KEY = os.getenv("PD_VENDOR_KEY")
|
||||||
|
|
||||||
|
# Prometheus
|
||||||
|
PROMETHEUS_ENABLED = envbool("PROMETHEUS_ENABLED", "True")
|
||||||
|
|
||||||
# Pushover integration
|
# Pushover integration
|
||||||
PUSHOVER_API_TOKEN = os.getenv("PUSHOVER_API_TOKEN")
|
PUSHOVER_API_TOKEN = os.getenv("PUSHOVER_API_TOKEN")
|
||||||
PUSHOVER_SUBSCRIPTION_URL = os.getenv("PUSHOVER_SUBSCRIPTION_URL")
|
PUSHOVER_SUBSCRIPTION_URL = os.getenv("PUSHOVER_SUBSCRIPTION_URL")
|
||||||
|
@ -92,9 +92,11 @@
|
|||||||
<p>Related links:</p>
|
<p>Related links:</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="{% url 'hc-serve-doc' 'api' %}">API documentation</a></li>
|
<li><a href="{% url 'hc-serve-doc' 'api' %}">API documentation</a></li>
|
||||||
|
{% if enable_prometheus %}
|
||||||
<li>
|
<li>
|
||||||
<a href="{% url 'hc-metrics' project.code project.api_key_readonly %}">Prometheus metrics endpoint</a>
|
<a href="{% url 'hc-metrics' project.code project.api_key_readonly %}">Prometheus metrics endpoint</a>
|
||||||
</li>
|
</li>
|
||||||
|
{% endif %}
|
||||||
<li>
|
<li>
|
||||||
<a href="{{ project.dashboard_url }}">Read-only dashboard</a>
|
<a href="{{ project.dashboard_url }}">Read-only dashboard</a>
|
||||||
(<a href="https://github.com/healthchecks/dashboard/#security">security considerations</a>)
|
(<a href="https://github.com/healthchecks/dashboard/#security">security considerations</a>)
|
||||||
|
@ -179,6 +179,9 @@ to <code>3f1a7317-8e96-437c-a17d-b0d550b51e86@ping.my-hc.example.org</code>.</p>
|
|||||||
|
|
||||||
<p>In this example, Healthchecks would generate ping URLs similar
|
<p>In this example, Healthchecks would generate ping URLs similar
|
||||||
to <code>https://ping.my-hc.example.org/3f1a7317-8e96-437c-a17d-b0d550b51e86</code>.</p>
|
to <code>https://ping.my-hc.example.org/3f1a7317-8e96-437c-a17d-b0d550b51e86</code>.</p>
|
||||||
|
<h2 id="PROMETHEUS_ENABLED"><code>PROMETHEUS_ENABLED</code></h2>
|
||||||
|
<p>Default: <code>True</code></p>
|
||||||
|
<p>A boolean that turns on/off the Prometheus integration. Enabled by default.</p>
|
||||||
<h2 id="PUSHBULLET_CLIENT_ID"><code>PUSHBULLET_CLIENT_ID</code></h2>
|
<h2 id="PUSHBULLET_CLIENT_ID"><code>PUSHBULLET_CLIENT_ID</code></h2>
|
||||||
<p>Default: <code>None</code></p>
|
<p>Default: <code>None</code></p>
|
||||||
<h2 id="PUSHBULLET_CLIENT_SECRET"><code>PUSHBULLET_CLIENT_SECRET</code></h2>
|
<h2 id="PUSHBULLET_CLIENT_SECRET"><code>PUSHBULLET_CLIENT_SECRET</code></h2>
|
||||||
|
@ -300,6 +300,12 @@ PING_ENDPOINT=https://ping.my-hc.example.org
|
|||||||
In this example, Healthchecks would generate ping URLs similar
|
In this example, Healthchecks would generate ping URLs similar
|
||||||
to `https://ping.my-hc.example.org/3f1a7317-8e96-437c-a17d-b0d550b51e86`.
|
to `https://ping.my-hc.example.org/3f1a7317-8e96-437c-a17d-b0d550b51e86`.
|
||||||
|
|
||||||
|
## `PROMETHEUS_ENABLED` {: #PROMETHEUS_ENABLED }
|
||||||
|
|
||||||
|
Default: `True`
|
||||||
|
|
||||||
|
A boolean that turns on/off the Prometheus integration. Enabled by default.
|
||||||
|
|
||||||
## `PUSHBULLET_CLIENT_ID` {: #PUSHBULLET_CLIENT_ID }
|
## `PUSHBULLET_CLIENT_ID` {: #PUSHBULLET_CLIENT_ID }
|
||||||
|
|
||||||
Default: `None`
|
Default: `None`
|
||||||
|
@ -336,6 +336,7 @@
|
|||||||
</li>
|
</li>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if enable_prometheus %}
|
||||||
<li>
|
<li>
|
||||||
<img src="{% static 'img/integrations/prometheus.png' %}"
|
<img src="{% static 'img/integrations/prometheus.png' %}"
|
||||||
class="icon" alt="Prometheus icon" />
|
class="icon" alt="Prometheus icon" />
|
||||||
@ -344,6 +345,7 @@
|
|||||||
<p>Export check and tag status values to Prometheus.</p>
|
<p>Export check and tag status values to Prometheus.</p>
|
||||||
<a href="{% url 'hc-add-prometheus' project.code %}" class="btn btn-primary">Add Integration</a>
|
<a href="{% url 'hc-add-prometheus' project.code %}" class="btn btn-primary">Add Integration</a>
|
||||||
</li>
|
</li>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if enable_pushbullet %}
|
{% if enable_pushbullet %}
|
||||||
<li>
|
<li>
|
||||||
|
@ -542,6 +542,7 @@
|
|||||||
</div>
|
</div>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
{% if enable_prometheus %}
|
||||||
<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">
|
||||||
<a href="{% url 'hc-serve-doc' 'configuring_prometheus' %}" class="integration">
|
<a href="{% url 'hc-serve-doc' 'configuring_prometheus' %}" class="integration">
|
||||||
<img src="{% static 'img/integrations/prometheus.png' %}" class="icon" alt="" />
|
<img src="{% static 'img/integrations/prometheus.png' %}" class="icon" alt="" />
|
||||||
@ -551,6 +552,7 @@
|
|||||||
</h3>
|
</h3>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
{% if enable_pushbullet %}
|
{% if enable_pushbullet %}
|
||||||
<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