Browse Source

Fix feature togging to use existing settings

pull/471/head
msansen1 4 years ago
parent
commit
a45dc6071e
4 changed files with 30 additions and 28 deletions
  1. +12
    -12
      hc/api/transports.py
  2. +2
    -2
      hc/front/views.py
  3. +14
    -12
      hc/settings.py
  4. +2
    -2
      templates/front/channels.html

+ 12
- 12
hc/api/transports.py View File

@ -262,7 +262,7 @@ class Webhook(HttpTransport):
class Slack(HttpTransport):
def notify(self, check):
if not settings.SLACK_ENABLED:
if settings.SLACK_CLIENT_ID is None:
return "Slack is not enabled"
text = tmpl("slack_message.json", check=check)
payload = json.loads(text)
@ -312,7 +312,7 @@ class PagerDuty(HttpTransport):
URL = "https://events.pagerduty.com/generic/2010-04-15/create_event.json"
def notify(self, check):
if not settings.PAGERDUTY_ENABLED:
if settings.PUSHBULLET_CLIENT_ID is not None:
return "PagerDuty is not enabled"
description = tmpl("pd_description.html", check=check)
payload = {
@ -353,7 +353,7 @@ class PagerTeam(HttpTransport):
class Pushbullet(HttpTransport):
def notify(self, check):
if not settings.PUSHBULLET_ENABLED:
if settings.PUSHBULLET_CLIENT_ID is None:
return "Pushbullet is not enabled"
text = tmpl("pushbullet_message.html", check=check)
url = "https://api.pushbullet.com/v2/pushes"
@ -370,7 +370,7 @@ class Pushover(HttpTransport):
URL = "https://api.pushover.net/1/messages.json"
def notify(self, check):
if not settings.PUSHOVER_ENABLED:
if settings.PUSHOVER_API_TOKEN is None:
return "Pushover is not enabled"
others = self.checks().filter(status="down").exclude(code=check.code)
@ -430,7 +430,7 @@ class Matrix(HttpTransport):
return url
def notify(self, check):
if not settings.MATRIX_ENABLED:
if settings.MATRIX_ACCESS_TOKEN is None:
return "Matrix Chat is not enabled"
plain = tmpl("matrix_description.html", check=check)
formatted = tmpl("matrix_description_formatted.html", check=check)
@ -446,7 +446,7 @@ class Matrix(HttpTransport):
class Discord(HttpTransport):
def notify(self, check):
if not settings.DISCORD_ENABLED:
if settings.DISCORD_CLIENT_ID is None:
return "Discord Chat is not enabled"
text = tmpl("slack_message.json", check=check)
payload = json.loads(text)
@ -473,7 +473,7 @@ class Telegram(HttpTransport):
)
def notify(self, check):
if not settings.TELEGRAM_ENABLED:
if settings.TELEGRAM_TOKEN is None:
return "Telegram Chat is not enabled"
from hc.api.models import TokenBucket
@ -491,7 +491,7 @@ class Sms(HttpTransport):
return check.status != "down"
def notify(self, check):
if not settings.SMS_ENABLED:
if settings.TWILIO_AUTH is None:
return "Sms is not enabled"
profile = Profile.objects.for_user(self.channel.project.owner)
if not profile.authorize_sms():
@ -519,7 +519,7 @@ class Call(HttpTransport):
return check.status != "down"
def notify(self, check):
if not settings.CALL_ENABLED:
if not settings.TWILIO_AUTH is None:
return "Call is not enabled"
profile = Profile.objects.for_user(self.channel.project.owner)
if not profile.authorize_call():
@ -550,7 +550,7 @@ class WhatsApp(HttpTransport):
return not self.channel.whatsapp_notify_up
def notify(self, check):
if not settings.WHATSAPP_ENABLED:
if not settings.TWILIO_USE_WHATSAPP:
return "WhatsApp is not enabled"
profile = Profile.objects.for_user(self.channel.project.owner)
if not profile.authorize_sms():
@ -578,7 +578,7 @@ class Trello(HttpTransport):
return check.status != "down"
def notify(self, check):
if not settings.TRELLO_ENABLED:
if settings.TRELLO_APP_KEY is None:
return "Trello is not enabled"
params = {
"idList": self.channel.trello_list_id,
@ -695,7 +695,7 @@ class LineNotify(HttpTransport):
URL = "https://notify-api.line.me/api/notify"
def notify(self, check):
if not settings.LINENOTIFY_ENABLED:
if settings.LINENOTIFY_CLIENT_ID is None:
return "LineNotify is not enabled"
headers = {
"Content-Type": "application/x-www-form-urlencoded",


+ 2
- 2
hc/front/views.py View File

@ -749,6 +749,7 @@ def channels(request, code):
channels = Channel.objects.filter(project=project)
channels = channels.order_by("created")
channels = channels.annotate(n_checks=Count("checks"))
ctx = {
"page": "channels",
"rw": rw,
@ -770,7 +771,7 @@ def channels(request, code):
"enable_telegram": settings.TELEGRAM_TOKEN is not None,
"enable_trello": settings.TRELLO_APP_KEY is not None,
"enable_whatsapp": settings.TWILIO_USE_WHATSAPP,
"enable_pagertree": settings.PAGERTREE_ENABLED is True,
"enable_mattermost": settings.MATTERMOST_ENABLED is True,
"enable_msteams": settings.MSTEAMS_ENABLED is True,
"enable_prometheus": settings.PROMETHEUS_ENABLED is True,
@ -779,7 +780,6 @@ def channels(request, code):
"enable_opsgenie": settings.OPSGENIE_ENABLED is True,
"enable_victorops": settings.VICTOROPS_ENABLED is True,
"enable_webhook": settings.WEBHOOK_ENABLED is True,
"use_payments": settings.USE_PAYMENTS,
}


+ 14
- 12
hc/settings.py View File

@ -172,7 +172,7 @@ COMPRESS_CSS_HASHING_METHOD = "content"
# WebAuthn
RP_ID = os.getenv("RP_ID")
#Integrations are enabled is settings are not empty
#Integrations are enabled if settings are not empty
# Discord integration
DISCORD_CLIENT_ID = os.getenv("DISCORD_CLIENT_ID")
@ -202,7 +202,7 @@ PUSHBULLET_CLIENT_ID = os.getenv("PUSHBULLET_CLIENT_ID")
PUSHBULLET_CLIENT_SECRET = os.getenv("PUSHBULLET_CLIENT_SECRET")
# Telegram integration -- override in local_settings.py
TELEGRAM_BOT_NAME = os.getenv("TELEGRAM_BOT_NAME")
TELEGRAM_BOT_NAME = os.getenv("TELEGRAM_BOT_NAME", "ExampleBot")
TELEGRAM_TOKEN = os.getenv("TELEGRAM_TOKEN")
# SMS and WhatsApp (Twilio) integration
@ -229,16 +229,6 @@ APPRISE_ENABLED = envbool("APPRISE_ENABLED", "False")
# Local shell commands
SHELL_ENABLED = envbool("SHELL_ENABLED", "False")
#Intégration Feature Toggle
MATTERMOST_ENABLED = envbool("MATTERMOST_ENABLED", "False")
OPSGENIE_ENABLED = envbool("OPSGENIE_ENABLED", "False")
VICTOROPS_ENABLED = envbool("VICTOROPS_ENABLED", "False")
WEBHOOK_ENABLED = envbool("WEBHOOK_ENABLED", "True")
MSTEAMS_ENABLED = envbool("MSTEAMS_ENABLED", "True")
ZULIP_ENABLED = envbool("ZULIP_ENABLED", "False")
SPIKE_ENABLED = envbool("SPIKE_ENABLED", "False")
PROMETHEUS_ENABLED = envbool("PROMETHEUS_ENABLED", "False")
# LINE Notify
LINENOTIFY_CLIENT_ID = os.getenv("LINENOTIFY_CLIENT_ID")
LINENOTIFY_CLIENT_SECRET = os.getenv("LINENOTIFY_CLIENT_SECRET")
@ -246,5 +236,17 @@ LINENOTIFY_CLIENT_SECRET = os.getenv("LINENOTIFY_CLIENT_SECRET")
# Signal
SIGNAL_CLI_ENABLED = envbool("SIGNAL_CLI_ENABLED", "False")
#Intégration Feature Toggle for integrations that need no parms
MATTERMOST_ENABLED = envbool("MATTERMOST_ENABLED", "True")
OPSGENIE_ENABLED = envbool("OPSGENIE_ENABLED", "True")
VICTOROPS_ENABLED = envbool("VICTOROPS_ENABLED", "True")
WEBHOOK_ENABLED = envbool("WEBHOOK_ENABLED", "True")
MSTEAMS_ENABLED = envbool("MSTEAMS_ENABLED", "True")
ZULIP_ENABLED = envbool("ZULIP_ENABLED", "True")
SPIKE_ENABLED = envbool("SPIKE_ENABLED", "True")
PROMETHEUS_ENABLED = envbool("PROMETHEUS_ENABLED", "True")
PAGERTREE_ENABLED = envbool("PAGERTREE_ENABLED", "True")
if os.path.exists(os.path.join(BASE_DIR, "hc/local_settings.py")):
from .local_settings import *

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

@ -187,7 +187,7 @@
<h1 class="ai-title">Add More</h1>
<ul class="add-integration">
{% if enable_slack %}
{% if enable_slack_btn %}
<li>
<img src="{% static 'img/integrations/slack.png' %}"
class="icon" alt="Slack icon" />
@ -301,7 +301,7 @@
</li>
{% endif %}
{% if enable_pagerduty %}
{% if enable_pdc %}
<li>
<img src="{% static 'img/integrations/pd.png' %}"
class="icon" alt="PagerDuty icon" />


Loading…
Cancel
Save