Exemple #1
0
 def handle(self, *args, **options):
     check = options['check']
     notify_user = options['notify_user']
     with transaction.atomic():
         for d in Domain.objects.all():
             if check and d.available:
                 domain = d.name
                 comment = d.comment
                 creator = d.created_by
                 available = check_dns(domain)
                 if not available:
                     d.available = False  # see comment in check_dns()
                     d.public = False
                     if notify_user:
                         subject, msg = translate_for_user(
                             creator,
                             _("issue with your domain %(domain)s"),
                             MSG
                         )
                         subject = subject % dict(domain=domain)
                         msg = msg % dict(domain=domain, comment=comment)
                         send_mail_to_user(creator, subject, msg)
                     msg = "setting unavailable flag for domain %s (created by %s)\n" % (domain, creator, )
                     self.stdout.write(msg)
                 d.save()
Exemple #2
0
 def handle(self, *args, **options):
     check = options['check']
     notify_user = options['notify_user']
     with transaction.atomic():
         for d in Domain.objects.all():
             if check and d.available:
                 domain = d.name
                 comment = d.comment
                 creator = d.created_by
                 available = check_dns(domain)
                 if not available:
                     d.available = False  # see comment in check_dns()
                     d.public = False
                     if notify_user:
                         subject, msg = translate_for_user(
                             creator,
                             _("issue with your domain %(domain)s"), MSG)
                         subject = subject % dict(domain=domain)
                         msg = msg % dict(domain=domain, comment=comment)
                         send_mail_to_user(creator, subject, msg)
                     msg = "setting unavailable flag for domain %s (created by %s)\n" % (
                         domain,
                         creator,
                     )
                     self.stdout.write(msg)
                 d.save()
Exemple #3
0
 def handle(self, *args, **options):
     stale_check = options['stale_check']
     notify_user = options['notify_user']
     with transaction.atomic():
         for h in Host.objects.all():
             if stale_check:
                 host = h.name + "." + h.domain.name
                 comment = h.comment
                 creator = h.created_by
                 staleness, email_msg, log_msg = check_staleness(h)
                 if email_msg and notify_user:
                     subject, msg = translate_for_user(
                         creator,
                         _("issue with your host %(host)s"),
                         email_msg
                     )
                     subject = subject % dict(host=host)
                     email_msg = email_msg % dict(host=host, staleness=staleness, comment=comment)
                     send_mail_to_user(creator, subject, email_msg)
                 if log_msg:
                     log_msg = log_msg % dict(host=host, staleness=staleness, creator=creator)
                     self.stdout.write(log_msg)
Exemple #4
0
 def handle(self, *args, **options):
     stale_check = options['stale_check']
     notify_user = options['notify_user']
     with transaction.atomic():
         for h in Host.objects.all():
             if stale_check:
                 host = h.name + "." + h.domain.name
                 comment = h.comment
                 creator = h.created_by
                 staleness, email_msg, log_msg = check_staleness(h)
                 if email_msg and notify_user:
                     subject, msg = translate_for_user(
                         creator, _("issue with your host %(host)s"),
                         email_msg)
                     subject = subject % dict(host=host)
                     email_msg = email_msg % dict(
                         host=host, staleness=staleness, comment=comment)
                     send_mail_to_user(creator, subject, email_msg)
                 if log_msg:
                     log_msg = log_msg % dict(
                         host=host, staleness=staleness, creator=creator)
                     self.stdout.write(log_msg)
 def handle(self, *args, **options):
     show_client = options['show_client']
     show_server = options['show_server']
     show_api_auth = options['show_api_auth']
     reset_client = options['reset_client']
     reset_server = options['reset_server']
     reset_api_auth = options['reset_api_auth']
     reset_available = options['reset_available']
     reset_abuse = options['reset_abuse']
     reset_abuse_blocked = options['reset_abuse_blocked']
     flag_abuse = options['flag_abuse']
     notify_user = options['notify_user']
     for h in Host.objects.all():
         try:
             with transaction.atomic():
                 if show_client or show_server:
                     output = u""
                     if show_client:
                         output += u"%-6d " % h.client_faults
                     if show_server:
                         output += u"%-6d " % h.server_faults
                     if show_api_auth:
                         output += u"%-6d " % h.api_auth_faults
                     output += u"%s %s\n" % (h.created_by.username, h.get_fqdn(),)
                     self.stdout.write(output)
                 if (flag_abuse is not None or reset_client or reset_server or reset_api_auth or
                     reset_available or reset_abuse or reset_abuse_blocked):
                     if flag_abuse is not None:
                         if h.client_faults > flag_abuse:
                             h.abuse = True
                             faults_count = h.client_faults
                             h.client_faults = 0
                             fqdn = h.get_fqdn()
                             comment = h.comment
                             creator = h.created_by
                             self.stdout.write(
                                 "setting abuse flag for host %s (created by %s, client faults: %d)\n" % (
                                     fqdn, creator, faults_count))
                             if notify_user:
                                 subject, msg = translate_for_user(
                                     creator,
                                     _("issue with your host %(fqdn)s"),
                                     ABUSE_MSG
                                 )
                                 subject = subject % dict(fqdn=fqdn)
                                 msg = msg % dict(fqdn=fqdn, comment=comment, faults_count=faults_count)
                                 send_mail_to_user(creator, subject, msg)
                     if reset_client:
                         h.client_faults = 0
                     if reset_server:
                         h.server_faults = 0
                     if reset_api_auth:
                         h.api_auth_faults = 0
                     if reset_available:
                         h.available = True
                     if reset_abuse:
                         h.abuse = False
                     if reset_abuse_blocked:
                         h.abuse_blocked = False
                     h.save()
         except Exception:
             try:
                 msg = u"The following Exception occurred when processing host %s!\n" % (h.get_fqdn(),)
                 self.stderr.write(msg)
             except Exception:
                 pass
             traceback.print_exc()
Exemple #6
0
 def handle(self, *args, **options):
     show_client = options['show_client']
     show_server = options['show_server']
     show_api_auth = options['show_api_auth']
     reset_client = options['reset_client']
     reset_server = options['reset_server']
     reset_api_auth = options['reset_api_auth']
     reset_available = options['reset_available']
     reset_abuse = options['reset_abuse']
     reset_abuse_blocked = options['reset_abuse_blocked']
     flag_abuse = options['flag_abuse']
     notify_user = options['notify_user']
     for h in Host.objects.all():
         try:
             with transaction.atomic():
                 if show_client or show_server:
                     output = u""
                     if show_client:
                         output += u"%-6d " % h.client_faults
                     if show_server:
                         output += u"%-6d " % h.server_faults
                     if show_api_auth:
                         output += u"%-6d " % h.api_auth_faults
                     output += u"%s %s\n" % (
                         h.created_by.username,
                         h.get_fqdn(),
                     )
                     self.stdout.write(output)
                 if (flag_abuse is not None or reset_client or reset_server
                         or reset_api_auth or reset_available or reset_abuse
                         or reset_abuse_blocked):
                     if flag_abuse is not None:
                         if h.client_faults > flag_abuse:
                             h.abuse = True
                             faults_count = h.client_faults
                             h.client_faults = 0
                             fqdn = h.get_fqdn()
                             comment = h.comment
                             creator = h.created_by
                             self.stdout.write(
                                 "setting abuse flag for host %s (created by %s, client faults: %d)\n"
                                 % (fqdn, creator, faults_count))
                             if notify_user:
                                 subject, msg = translate_for_user(
                                     creator,
                                     _("issue with your host %(fqdn)s"),
                                     ABUSE_MSG)
                                 subject = subject % dict(fqdn=fqdn)
                                 msg = msg % dict(fqdn=fqdn,
                                                  comment=comment,
                                                  faults_count=faults_count)
                                 send_mail_to_user(creator, subject, msg)
                     if reset_client:
                         h.client_faults = 0
                     if reset_server:
                         h.server_faults = 0
                     if reset_api_auth:
                         h.api_auth_faults = 0
                     if reset_available:
                         h.available = True
                     if reset_abuse:
                         h.abuse = False
                     if reset_abuse_blocked:
                         h.abuse_blocked = False
                     h.save()
         except Exception:
             try:
                 msg = u"The following Exception occurred when processing host %s!\n" % (
                     h.get_fqdn(), )
                 self.stderr.write(msg)
             except Exception:
                 pass
             traceback.print_exc()