email_from setting, don't send alerts about checks without associated user

This commit is contained in:
Pēteris Caune 2015-07-08 09:40:58 +03:00
parent e0b26921d6
commit 8628be8584
4 changed files with 19 additions and 7 deletions

View File

@ -51,7 +51,7 @@ def login(request):
login_link = settings.SITE_ROOT + login_link login_link = settings.SITE_ROOT + login_link
body = "login link: %s" % login_link body = "login link: %s" % login_link
send_mail('Log In', body, 'cuu508@gmail.com', [email], send_mail('Log In', body, settings.DEFAULT_FROM_EMAIL, [email],
fail_silently=False) fail_silently=False)
return redirect("hc-login-link-sent") return redirect("hc-login-link-sent")

View File

@ -18,28 +18,38 @@ class Command(BaseCommand):
def handle(self, *args, **options): def handle(self, *args, **options):
ticks = 0
while True: while True:
# Gone down? # Gone down?
query = Check.objects query = Check.objects
query = query.filter(alert_after__lt=timezone.now()) query = query.filter(alert_after__lt=timezone.now())
query = query.filter(user__isnull=False)
query = query.filter(status="up") query = query.filter(status="up")
for check in query: for check in query:
check.status = "down" check.status = "down"
check.save()
_log("\nSending email about going down for %s\n" % check.code) _log("\nSending email about going down for %s\n" % check.code)
send_status_notification(check) send_status_notification(check)
ticks = 0
# Save status after the notification is sent
check.save()
# Gone up? # Gone up?
query = Check.objects query = Check.objects
query = query.filter(alert_after__gt=timezone.now()) query = query.filter(alert_after__gt=timezone.now())
query = query.filter(user__isnull=False)
query = query.filter(status="down") query = query.filter(status="down")
for check in query: for check in query:
check.status = "up" check.status = "up"
check.save()
_log("\nSending email about going up for %s\n" % check.code) _log("\nSending email about going up for %s\n" % check.code)
send_status_notification(check) send_status_notification(check)
ticks = 0
# Save status after the notification is sent
check.save()
time.sleep(1) time.sleep(1)
_log(".") ticks = (ticks + 1) % 80
_log("." + ("\n" if ticks == 0 else ""))

View File

@ -1,3 +1,4 @@
from django.conf import settings
from django.core.mail import send_mail from django.core.mail import send_mail
@ -11,5 +12,5 @@ def send_status_notification(check):
else: else:
raise NotImplemented("Unexpected status: %s" % check.status) raise NotImplemented("Unexpected status: %s" % check.status)
send_mail(subject, body, 'cuu508@gmail.com', [check.user.email], send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [check.user.email],
fail_silently=False) fail_silently=False)

View File

@ -19,6 +19,7 @@ HOST = "localhost"
SECRET_KEY = "---" SECRET_KEY = "---"
DEBUG = True DEBUG = True
ALLOWED_HOSTS = [] ALLOWED_HOSTS = []
DEFAULT_FROM_EMAIL = 'healthchecks@example.org'
INSTALLED_APPS = ( INSTALLED_APPS = (
@ -95,8 +96,8 @@ STATIC_ROOT = os.path.join(BASE_DIR, 'static-collected')
EMAIL_BACKEND = 'django_ses_backend.SESBackend' EMAIL_BACKEND = 'django_ses_backend.SESBackend'
AWS_SES_ACCESS_KEY_ID = "---" AWS_SES_ACCESS_KEY_ID = "---"
AWS_SES_SECRET_ACCESS_KEY = "---" AWS_SES_SECRET_ACCESS_KEY = "---"
AWS_SES_REGION_NAME = 'eu-west-1' AWS_SES_REGION_NAME = 'us-east-1'
AWS_SES_REGION_ENDPOINT = 'email.eu-west-1.amazonaws.com' AWS_SES_REGION_ENDPOINT = 'email.us-east-1.amazonaws.com'
try: try: