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
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)
return redirect("hc-login-link-sent")

View File

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

View File

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