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()), 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]