diff --git a/api/tacticalrmm/tacticalrmm/utils.py b/api/tacticalrmm/tacticalrmm/utils.py index 0adf0520..14f3d6cd 100644 --- a/api/tacticalrmm/tacticalrmm/utils.py +++ b/api/tacticalrmm/tacticalrmm/utils.py @@ -1,7 +1,7 @@ import json import os import subprocess -import tldextract +from loguru import logger from django.conf import settings from rest_framework import status @@ -9,6 +9,8 @@ from rest_framework.response import Response from agents.models import Agent +logger.configure(**settings.LOG_CONFIG) + notify_error = lambda msg: Response(msg, status=status.HTTP_400_BAD_REQUEST) @@ -16,11 +18,17 @@ def reload_nats(): users = [{"user": "tacticalrmm", "password": settings.SECRET_KEY}] agents = Agent.objects.prefetch_related("user").only("pk", "agent_id") for agent in agents: - users.append({"user": agent.agent_id, "password": agent.user.auth_token.key}) + try: + users.append( + {"user": agent.agent_id, "password": agent.user.auth_token.key} + ) + except: + logger.critical( + f"{agent.hostname} does not have a user account, NATS will not work" + ) if not settings.DOCKER_BUILD: - tld = tldextract.extract(settings.ALLOWED_HOSTS[0]) - domain = tld.domain + "." + tld.suffix + domain = settings.ALLOWED_HOSTS[0].split(".", 1)[1] cert_path = f"/etc/letsencrypt/live/{domain}" else: cert_path = "/opt/tactical/certs"