From a06b58b33b6e0c1295574cd7863563272cb33793 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ses=C3=B3stris=20Vieira?= Date: Tue, 28 Feb 2023 10:42:54 -0300 Subject: [PATCH] Verificador de validade de registros DNS --- .../servicos/jobs/daily/verifica_dominios.py | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 sigi/apps/servicos/jobs/daily/verifica_dominios.py diff --git a/sigi/apps/servicos/jobs/daily/verifica_dominios.py b/sigi/apps/servicos/jobs/daily/verifica_dominios.py new file mode 100644 index 0000000..4229527 --- /dev/null +++ b/sigi/apps/servicos/jobs/daily/verifica_dominios.py @@ -0,0 +1,44 @@ +import dns.resolver +from django.utils import timezone +from django.utils.translation import gettext as _ +from django_extensions.management.jobs import DailyJob +from sigi.apps.servicos.models import Servico +from sigi.apps.utils.mixins import JobReportMixin + + +class Job(JobReportMixin, DailyJob): + help = "Verifica domínios registrados no Interlegis" + report_data = [] + + def do_job(self): + servicos = Servico.objects.filter( + tipo_servico__modo="R", data_desativacao=None + ).exclude(url="") + total = servicos.count() + erros = 0 + for s in servicos: + s.data_verificacao = timezone.localtime() + try: + dns.resolver.resolve(s.url, "SOA") + s.resultado_verificacao = "F" + s.erro_atualizacao = "" + except Exception as e: + erros += 1 + s.resultado_verificacao = "O" + s.erro_atualizacao = str(e) + self.report_data.append( + f" * {s.url} {s.get_resultado_verificacao_display()}: " + f"{s.erro_atualizacao}" + ) + s.save() + + self.report_data = [ + "", + "RESUMO", + "======", + "", + f" * Total de registros verificados: {total}", + f" * Registros com erros: {erros}", + "", + "", + ] + self.report_data