From fe0ddec0f98052298d77ce99207b3bfa75da4e87 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Tue, 24 Nov 2020 05:49:42 +0000 Subject: [PATCH] move runchecks to nats --- api/tacticalrmm/checks/tasks.py | 7 ------- api/tacticalrmm/checks/views.py | 8 ++++++-- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/api/tacticalrmm/checks/tasks.py b/api/tacticalrmm/checks/tasks.py index 6befb6eb..2f01aa2f 100644 --- a/api/tacticalrmm/checks/tasks.py +++ b/api/tacticalrmm/checks/tasks.py @@ -56,10 +56,3 @@ def handle_check_sms_alert_task(pk): check.save(update_fields=["text_sent"]) return "ok" - - -@app.task -def run_checks_task(pk): - agent = Agent.objects.get(pk=pk) - agent.salt_api_async(func="win_agent.run_manual_checks") - return "ok" diff --git a/api/tacticalrmm/checks/views.py b/api/tacticalrmm/checks/views.py index 9d015e37..aa4950ce 100644 --- a/api/tacticalrmm/checks/views.py +++ b/api/tacticalrmm/checks/views.py @@ -1,3 +1,5 @@ +import asyncio + from django.shortcuts import get_object_or_404 from rest_framework.views import APIView @@ -13,7 +15,6 @@ from scripts.models import Script from .serializers import CheckSerializer -from .tasks import run_checks_task from automation.tasks import ( generate_agent_checks_from_policies_task, @@ -178,7 +179,10 @@ class GetUpdateDeleteCheck(APIView): @api_view() def run_checks(request, pk): agent = get_object_or_404(Agent, pk=pk) - run_checks_task.delay(agent.pk) + if not agent.has_nats: + return notify_error("Requires agent version 1.1.0 or greater") + + asyncio.run(agent.nats_cmd({"func": "runchecks"}, wait=False)) return Response(agent.hostname)