diff --git a/app/cabot_config.py b/app/cabot_config.py index 0561766..61f009c 100644 --- a/app/cabot_config.py +++ b/app/cabot_config.py @@ -15,4 +15,6 @@ TWILIO_ACCOUNT_SID = os.environ.get('TWILIO_ACCOUNT_SID') TWILIO_AUTH_TOKEN = os.environ.get('TWILIO_AUTH_TOKEN') TWILIO_OUTGOING_NUMBER = os.environ.get('TWILIO_OUTGOING_NUMBER') CALENDAR_ICAL_URL = os.environ.get('CALENDAR_ICAL_URL') -WWW_HTTP_HOST = os.environ.get('WWW_HTTP_HOST') \ No newline at end of file +WWW_HTTP_HOST = os.environ.get('WWW_HTTP_HOST') +ALERT_INTERVAL = os.environ.get('ALERT_INTERVAL', 10) +NOTIFICATION_INTERVAL = os.environ.get('NOTIFICATION_INTERVAL', 120) diff --git a/app/cabotapp/models.py b/app/cabotapp/models.py index 5e7e33e..42a87a5 100644 --- a/app/cabotapp/models.py +++ b/app/cabotapp/models.py @@ -1,4 +1,5 @@ from django.db import models +from django.conf import settings from polymorphic import PolymorphicModel from django.db.models import F from django.contrib.admin.models import User @@ -165,12 +166,12 @@ class Service(models.Model): if not self.alerts_enabled: return if self.overall_status != self.PASSING_STATUS: - # Don't alert every time - only every 10 mins for errors and critical, and 120 mins for warnings + # Don't alert every time if self.overall_status == self.WARNING_STATUS: - if self.last_alert_sent and (timezone.now() - timedelta(minutes=120)) < self.last_alert_sent: + if self.last_alert_sent and (timezone.now() - timedelta(minutes=settings.NOTIFICATION_INTERVAL)) < self.last_alert_sent: return elif self.overall_status in (self.CRITICAL_STATUS, self.ERROR_STATUS): - if self.last_alert_sent and (timezone.now() - timedelta(minutes=10)) < self.last_alert_sent: + if self.last_alert_sent and (timezone.now() - timedelta(minutes=settings.ALERT_INTERVAL)) < self.last_alert_sent: return self.last_alert_sent = timezone.now() else: