Browse Source

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

pull/7/head
Pēteris Caune 9 years ago
parent
commit
8628be8584
4 changed files with 19 additions and 7 deletions
  1. +1
    -1
      hc/accounts/views.py
  2. +13
    -3
      hc/api/management/commands/sendalerts.py
  3. +2
    -1
      hc/lib/emails.py
  4. +3
    -2
      hc/settings.py

+ 1
- 1
hc/accounts/views.py 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, '[email protected]', [email],
send_mail('Log In', body, settings.DEFAULT_FROM_EMAIL, [email],
fail_silently=False)
return redirect("hc-login-link-sent")


+ 13
- 3
hc/api/management/commands/sendalerts.py 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 ""))

+ 2
- 1
hc/lib/emails.py 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, '[email protected]', [check.user.email],
send_mail(subject, body, settings.DEFAULT_FROM_EMAIL, [check.user.email],
fail_silently=False)

+ 3
- 2
hc/settings.py View File

@ -19,6 +19,7 @@ HOST = "localhost"
SECRET_KEY = "---"
DEBUG = True
ALLOWED_HOSTS = []
DEFAULT_FROM_EMAIL = '[email protected]'
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:


Loading…
Cancel
Save