Browse Source

feat(api): add debug output for healthcheck timestamp update

Peter Thomassen 5 years ago
parent
commit
4435ca1c1e
1 changed files with 6 additions and 3 deletions
  1. 6 3
      api/desecapi/management/commands/chores.py

+ 6 - 3
api/desecapi/management/commands/chores.py

@@ -23,25 +23,28 @@ class Command(BaseCommand):
 
 
     @staticmethod
     @staticmethod
     def update_healthcheck_timestamp():
     def update_healthcheck_timestamp():
+        name = 'internal-timestamp.desec.test'
         try:
         try:
-            domain = models.Domain.objects.get(name='internal-timestamp.desec.test')
+            domain = models.Domain.objects.get(name=name)
         except models.Domain.DoesNotExist:
         except models.Domain.DoesNotExist:
             # Fail silently. If external alerting is configured, it will catch the problem; otherwise, we don't need it.
             # Fail silently. If external alerting is configured, it will catch the problem; otherwise, we don't need it.
+            print(f'{name} zone is not configured; skipping TXT record update')
             return
             return
 
 
         instances = domain.rrset_set.filter(subname='', type='TXT').all()
         instances = domain.rrset_set.filter(subname='', type='TXT').all()
         timestamp = int(time.time())
         timestamp = int(time.time())
+        content = f'"{timestamp}"'
         data = [{
         data = [{
             'subname': '',
             'subname': '',
             'type': 'TXT',
             'type': 'TXT',
             'ttl': '3600',
             'ttl': '3600',
-            'records': [f'"{timestamp}"']
+            'records': [content]
         }]
         }]
         serializer = serializers.RRsetSerializer(instances, domain=domain, data=data, many=True, partial=True)
         serializer = serializers.RRsetSerializer(instances, domain=domain, data=data, many=True, partial=True)
         serializer.is_valid(raise_exception=True)
         serializer.is_valid(raise_exception=True)
         with PDNSChangeTracker():
         with PDNSChangeTracker():
             serializer.save()
             serializer.save()
-
+        print(f'TXT {name} updated to {content}')
 
 
     def handle(self, *args, **kwargs):
     def handle(self, *args, **kwargs):
         self.delete_expired_captchas()
         self.delete_expired_captchas()