From c762d12a402961d0c49dd8aab1395e9b534a2a9a Mon Sep 17 00:00:00 2001 From: conlan0 <87742085+conlan0@users.noreply.github.com> Date: Wed, 21 Feb 2024 21:29:29 -0500 Subject: [PATCH 1/2] Add shutdown class --- api/tacticalrmm/agents/views.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/api/tacticalrmm/agents/views.py b/api/tacticalrmm/agents/views.py index 48e3f352..e4046f8e 100644 --- a/api/tacticalrmm/agents/views.py +++ b/api/tacticalrmm/agents/views.py @@ -491,6 +491,19 @@ def send_raw_cmd(request, agent_id): return Response(r) +class Shutdown(APIView): + permission_classes = [IsAuthenticated, RebootAgentPerms] + + # shutdown + def post(self, request, agent_id): + agent = get_object_or_404(Agent, agent_id=agent_id) + r = asyncio.run(agent.nats_cmd({"func": "shutdown"}, timeout=10)) + if r != "ok": + return notify_error("Unable to contact the agent") + + return Response("ok") + + class Reboot(APIView): permission_classes = [IsAuthenticated, RebootAgentPerms] From 8f34865dab56326562e85a9d2dbb96cef15b35f2 Mon Sep 17 00:00:00 2001 From: conlan0 <87742085+conlan0@users.noreply.github.com> Date: Wed, 21 Feb 2024 21:29:53 -0500 Subject: [PATCH 2/2] Add shutdown url --- api/tacticalrmm/agents/urls.py | 1 + 1 file changed, 1 insertion(+) diff --git a/api/tacticalrmm/agents/urls.py b/api/tacticalrmm/agents/urls.py index 1127be84..f99086e7 100644 --- a/api/tacticalrmm/agents/urls.py +++ b/api/tacticalrmm/agents/urls.py @@ -15,6 +15,7 @@ urlpatterns = [ path("/wmi/", views.WMI.as_view()), path("/recover/", views.recover), path("/reboot/", views.Reboot.as_view()), + path("/shutdown/", views.Shutdown.as_view()), path("/ping/", views.ping), # alias for checks get view path("/checks/", GetAddChecks.as_view()),