You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
876 B

  1. import sys
  2. from django.core.management.base import BaseCommand
  3. from django.contrib.auth.models import User
  4. from hc.api.models import Channel, Check
  5. def _log(message):
  6. sys.stdout.write(message)
  7. sys.stdout.flush()
  8. class Command(BaseCommand):
  9. help = 'Sends UP/DOWN email alerts'
  10. def handle(self, *args, **options):
  11. for user in User.objects.all():
  12. q = Channel.objects.filter(user=user)
  13. q = q.filter(kind="email", email_verified=True, value=user.email)
  14. if q.count() > 0:
  15. continue
  16. print("Creating default channel for %s" % user.email)
  17. channel = Channel(user=user)
  18. channel.kind = "email"
  19. channel.value = user.email
  20. channel.email_verified = True
  21. channel.save()
  22. channel.checks.add(*Check.objects.filter(user=user))