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): class Slack(HttpTransport):
def notify(self, check): def notify(self, check):
if not settings.SLACK_ENABLED:
if settings.SLACK_CLIENT_ID is None:
return "Slack is not enabled" return "Slack is not enabled"
text = tmpl("slack_message.json", check=check) text = tmpl("slack_message.json", check=check)
payload = json.loads(text) payload = json.loads(text)
@ -312,7 +312,7 @@ class PagerDuty(HttpTransport):
URL = "https://events.pagerduty.com/generic/2010-04-15/create_event.json" URL = "https://events.pagerduty.com/generic/2010-04-15/create_event.json"
def notify(self, check): def notify(self, check):
if not settings.PAGERDUTY_ENABLED:
if settings.PUSHBULLET_CLIENT_ID is not None:
return "PagerDuty is not enabled" return "PagerDuty is not enabled"
description = tmpl("pd_description.html", check=check) description = tmpl("pd_description.html", check=check)
payload = { payload = {
@ -353,7 +353,7 @@ class PagerTeam(HttpTransport):
class Pushbullet(HttpTransport): class Pushbullet(HttpTransport):
def notify(self, check): def notify(self, check):
if not settings.PUSHBULLET_ENABLED:
if settings.PUSHBULLET_CLIENT_ID is None:
return "Pushbullet is not enabled" return "Pushbullet is not enabled"
text = tmpl("pushbullet_message.html", check=check) text = tmpl("pushbullet_message.html", check=check)
url = "https://api.pushbullet.com/v2/pushes" url = "https://api.pushbullet.com/v2/pushes"
@ -370,7 +370,7 @@ class Pushover(HttpTransport):
URL = "https://api.pushover.net/1/messages.json" URL = "https://api.pushover.net/1/messages.json"
def notify(self, check): def notify(self, check):
if not settings.PUSHOVER_ENABLED:
if settings.PUSHOVER_API_TOKEN is None:
return "Pushover is not enabled" return "Pushover is not enabled"
others = self.checks().filter(status="down").exclude(code=check.code) others = self.checks().filter(status="down").exclude(code=check.code)
@ -430,7 +430,7 @@ class Matrix(HttpTransport):
return url return url
def notify(self, check): def notify(self, check):
if not settings.MATRIX_ENABLED:
if settings.MATRIX_ACCESS_TOKEN is None:
return "Matrix Chat is not enabled" return "Matrix Chat is not enabled"
plain = tmpl("matrix_description.html", check=check) plain = tmpl("matrix_description.html", check=check)
formatted = tmpl("matrix_description_formatted.html", check=check) formatted = tmpl("matrix_description_formatted.html", check=check)
@ -446,7 +446,7 @@ class Matrix(HttpTransport):
class Discord(HttpTransport): class Discord(HttpTransport):
def notify(self, check): def notify(self, check):
if not settings.DISCORD_ENABLED:
if settings.DISCORD_CLIENT_ID is None:
return "Discord Chat is not enabled" return "Discord Chat is not enabled"
text = tmpl("slack_message.json", check=check) text = tmpl("slack_message.json", check=check)
payload = json.loads(text) payload = json.loads(text)
@ -473,7 +473,7 @@ class Telegram(HttpTransport):
) )
def notify(self, check): def notify(self, check):
if not settings.TELEGRAM_ENABLED:
if settings.TELEGRAM_TOKEN is None:
return "Telegram Chat is not enabled" return "Telegram Chat is not enabled"
from hc.api.models import TokenBucket from hc.api.models import TokenBucket
@ -491,7 +491,7 @@ class Sms(HttpTransport):
return check.status != "down" return check.status != "down"
def notify(self, check): def notify(self, check):
if not settings.SMS_ENABLED:
if settings.TWILIO_AUTH is None:
return "Sms is not enabled" return "Sms is not enabled"
profile = Profile.objects.for_user(self.channel.project.owner) profile = Profile.objects.for_user(self.channel.project.owner)
if not profile.authorize_sms(): if not profile.authorize_sms():
@ -519,7 +519,7 @@ class Call(HttpTransport):
return check.status != "down" return check.status != "down"
def notify(self, check): def notify(self, check):
if not settings.CALL_ENABLED:
if not settings.TWILIO_AUTH is None:
return "Call is not enabled" return "Call is not enabled"
profile = Profile.objects.for_user(self.channel.project.owner) profile = Profile.objects.for_user(self.channel.project.owner)
if not profile.authorize_call(): if not profile.authorize_call():
@ -550,7 +550,7 @@ class WhatsApp(HttpTransport):
return not self.channel.whatsapp_notify_up return not self.channel.whatsapp_notify_up
def notify(self, check): def notify(self, check):
if not settings.WHATSAPP_ENABLED:
if not settings.TWILIO_USE_WHATSAPP:
return "WhatsApp is not enabled" return "WhatsApp is not enabled"
profile = Profile.objects.for_user(self.channel.project.owner) profile = Profile.objects.for_user(self.channel.project.owner)
if not profile.authorize_sms(): if not profile.authorize_sms():
@ -578,7 +578,7 @@ class Trello(HttpTransport):
return check.status != "down" return check.status != "down"
def notify(self, check): def notify(self, check):
if not settings.TRELLO_ENABLED:
if settings.TRELLO_APP_KEY is None:
return "Trello is not enabled" return "Trello is not enabled"
params = { params = {
"idList": self.channel.trello_list_id, "idList": self.channel.trello_list_id,
@ -695,7 +695,7 @@ class LineNotify(HttpTransport):
URL = "https://notify-api.line.me/api/notify" URL = "https://notify-api.line.me/api/notify"
def notify(self, check): def notify(self, check):
if not settings.LINENOTIFY_ENABLED:
if settings.LINENOTIFY_CLIENT_ID is None:
return "LineNotify is not enabled" return "LineNotify is not enabled"
headers = { headers = {
"Content-Type": "application/x-www-form-urlencoded", "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 = Channel.objects.filter(project=project)
channels = channels.order_by("created") channels = channels.order_by("created")
channels = channels.annotate(n_checks=Count("checks")) channels = channels.annotate(n_checks=Count("checks"))
ctx = { ctx = {
"page": "channels", "page": "channels",
"rw": rw, "rw": rw,
@ -770,7 +771,7 @@ def channels(request, code):
"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_whatsapp": settings.TWILIO_USE_WHATSAPP, "enable_whatsapp": settings.TWILIO_USE_WHATSAPP,
"enable_pagertree": settings.PAGERTREE_ENABLED is True,
"enable_mattermost": settings.MATTERMOST_ENABLED is True, "enable_mattermost": settings.MATTERMOST_ENABLED is True,
"enable_msteams": settings.MSTEAMS_ENABLED is True, "enable_msteams": settings.MSTEAMS_ENABLED is True,
"enable_prometheus": settings.PROMETHEUS_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_opsgenie": settings.OPSGENIE_ENABLED is True,
"enable_victorops": settings.VICTOROPS_ENABLED is True, "enable_victorops": settings.VICTOROPS_ENABLED is True,
"enable_webhook": settings.WEBHOOK_ENABLED is True, "enable_webhook": settings.WEBHOOK_ENABLED is True,
"use_payments": settings.USE_PAYMENTS, "use_payments": settings.USE_PAYMENTS,
} }


+ 14
- 12
hc/settings.py View File

@ -172,7 +172,7 @@ COMPRESS_CSS_HASHING_METHOD = "content"
# WebAuthn # WebAuthn
RP_ID = os.getenv("RP_ID") 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 integration
DISCORD_CLIENT_ID = os.getenv("DISCORD_CLIENT_ID") 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") PUSHBULLET_CLIENT_SECRET = os.getenv("PUSHBULLET_CLIENT_SECRET")
# Telegram integration -- override in local_settings.py # 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") TELEGRAM_TOKEN = os.getenv("TELEGRAM_TOKEN")
# SMS and WhatsApp (Twilio) integration # SMS and WhatsApp (Twilio) integration
@ -229,16 +229,6 @@ APPRISE_ENABLED = envbool("APPRISE_ENABLED", "False")
# Local shell commands # Local shell commands
SHELL_ENABLED = envbool("SHELL_ENABLED", "False") 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 # LINE Notify
LINENOTIFY_CLIENT_ID = os.getenv("LINENOTIFY_CLIENT_ID") LINENOTIFY_CLIENT_ID = os.getenv("LINENOTIFY_CLIENT_ID")
LINENOTIFY_CLIENT_SECRET = os.getenv("LINENOTIFY_CLIENT_SECRET") LINENOTIFY_CLIENT_SECRET = os.getenv("LINENOTIFY_CLIENT_SECRET")
@ -246,5 +236,17 @@ LINENOTIFY_CLIENT_SECRET = os.getenv("LINENOTIFY_CLIENT_SECRET")
# Signal # Signal
SIGNAL_CLI_ENABLED = envbool("SIGNAL_CLI_ENABLED", "False") 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")): if os.path.exists(os.path.join(BASE_DIR, "hc/local_settings.py")):
from .local_settings import * from .local_settings import *

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

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


Loading…
Cancel
Save