forked from GithubBackups/healthchecks
Apprise Notifications are now a controlled via settings
This commit is contained in:
parent
c2b1d00422
commit
b5a03369b6
@ -3,12 +3,17 @@ from django.template.loader import render_to_string
|
||||
from django.utils import timezone
|
||||
import json
|
||||
import requests
|
||||
import apprise
|
||||
from urllib.parse import quote, urlencode
|
||||
|
||||
from hc.accounts.models import Profile
|
||||
from hc.lib import emails
|
||||
|
||||
try:
|
||||
import apprise
|
||||
except ImportError:
|
||||
# Enforce
|
||||
settings.APPRISE_ENABLED = False
|
||||
|
||||
|
||||
def tmpl(template_name, **ctx):
|
||||
template_path = "integrations/%s" % template_name
|
||||
@ -465,6 +470,11 @@ class Trello(HttpTransport):
|
||||
|
||||
class Apprise(HttpTransport):
|
||||
def notify(self, check):
|
||||
|
||||
if not settings.APPRISE_ENABLED:
|
||||
# Not supported and/or enabled
|
||||
return "Apprise is disabled and/or not installed."
|
||||
|
||||
a = apprise.Apprise()
|
||||
title = tmpl("apprise_title.html", check=check)
|
||||
body = tmpl("apprise_description.html", check=check)
|
||||
|
@ -1,8 +1,10 @@
|
||||
from hc.api.models import Channel
|
||||
from hc.test import BaseTestCase
|
||||
from django.test.utils import override_settings
|
||||
|
||||
|
||||
class AddSlackTestCase(BaseTestCase):
|
||||
@override_settings(APPRISE_ENABLED=True)
|
||||
class AddAppriseTestCase(BaseTestCase):
|
||||
def test_instructions_work(self):
|
||||
self.client.login(username="alice@example.org", password="password")
|
||||
r = self.client.get("/integrations/add_apprise/")
|
||||
@ -19,3 +21,9 @@ class AddSlackTestCase(BaseTestCase):
|
||||
self.assertEqual(c.kind, "apprise")
|
||||
self.assertEqual(c.value, "json://example.org")
|
||||
self.assertEqual(c.project, self.project)
|
||||
|
||||
@override_settings(APPRISE_ENABLED=False)
|
||||
def test_it_requires_client_id(self):
|
||||
self.client.login(username="alice@example.org", password="password")
|
||||
r = self.client.get("/integrations/add_apprise/")
|
||||
self.assertEqual(r.status_code, 404)
|
||||
|
@ -237,6 +237,7 @@ def index(request):
|
||||
"enable_pd": settings.PD_VENDOR_KEY is not None,
|
||||
"enable_trello": settings.TRELLO_APP_KEY is not None,
|
||||
"enable_matrix": settings.MATRIX_ACCESS_TOKEN is not None,
|
||||
"enable_apprise": settings.APPRISE_ENABLED is True,
|
||||
"registration_open": settings.REGISTRATION_OPEN,
|
||||
}
|
||||
|
||||
@ -611,6 +612,7 @@ def channels(request):
|
||||
"enable_pd": settings.PD_VENDOR_KEY is not None,
|
||||
"enable_trello": settings.TRELLO_APP_KEY is not None,
|
||||
"enable_matrix": settings.MATRIX_ACCESS_TOKEN is not None,
|
||||
"enable_apprise": settings.APPRISE_ENABLED is True,
|
||||
"use_payments": settings.USE_PAYMENTS,
|
||||
}
|
||||
|
||||
@ -1328,6 +1330,9 @@ def add_matrix(request):
|
||||
|
||||
@login_required
|
||||
def add_apprise(request):
|
||||
if not settings.APPRISE_ENABLED:
|
||||
raise Http404("apprise integration is not available")
|
||||
|
||||
if request.method == "POST":
|
||||
form = AddAppriseForm(request.POST)
|
||||
if form.is_valid():
|
||||
|
@ -204,6 +204,9 @@ MATRIX_HOMESERVER = os.getenv("MATRIX_HOMESERVER")
|
||||
MATRIX_USER_ID = os.getenv("MATRIX_USER_ID")
|
||||
MATRIX_ACCESS_TOKEN = os.getenv("MATRIX_ACCESS_TOKEN")
|
||||
|
||||
# Apprise
|
||||
APPRISE_ENABLED = envbool("APPRISE_ENABLED", "False")
|
||||
|
||||
|
||||
if os.path.exists(os.path.join(BASE_DIR, "hc/local_settings.py")):
|
||||
from .local_settings import *
|
||||
|
@ -4,4 +4,3 @@ django_compressor==2.2
|
||||
psycopg2==2.7.5
|
||||
pytz==2019.1
|
||||
requests==2.22.0
|
||||
apprise==0.7.9
|
||||
|
@ -213,6 +213,7 @@
|
||||
|
||||
<a href="{% url 'hc-add-webhook' %}" class="btn btn-primary">Add Integration</a>
|
||||
</li>
|
||||
{% if enable_apprise %}
|
||||
<li>
|
||||
<img src="{% static 'img/integrations/apprise.png' %}"
|
||||
class="icon" alt="Pushover icon" />
|
||||
@ -222,6 +223,7 @@
|
||||
|
||||
<a href="{% url 'hc-add-apprise' %}" class="btn btn-primary">Add Integration</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% if enable_pushover %}
|
||||
<li>
|
||||
<img src="{% static 'img/integrations/po.png' %}"
|
||||
|
@ -432,12 +432,14 @@
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
{% if enable_apprise %}
|
||||
<div class="col-md-2 col-sm-4 col-xs-6">
|
||||
<div class="integration">
|
||||
<img src="{% static 'img/integrations/apprise.png' %}" class="icon" alt="Apprise icon" />
|
||||
<h3>WhatsApp<br><small>Chat</small></h3>
|
||||
<h3>Apprise<br><small>>Push Notifications</small></h3>
|
||||
</div>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="row tour-section">
|
||||
|
Loading…
x
Reference in New Issue
Block a user