From 3b13c7f9ce16cd69f306e48231b47d562f7e7fe0 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Mon, 23 Nov 2020 02:19:54 +0000 Subject: [PATCH] move agent uninstall to nats wh1te909/rmmagent@502cc0d3dec6d286cd135cc9ab94d23fc26e5840 --- api/tacticalrmm/agents/views.py | 23 +++++++++++------------ web/src/components/AgentTable.vue | 2 +- 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/api/tacticalrmm/agents/views.py b/api/tacticalrmm/agents/views.py index dcc965c2..bb35263d 100644 --- a/api/tacticalrmm/agents/views.py +++ b/api/tacticalrmm/agents/views.py @@ -2,9 +2,6 @@ import asyncio from loguru import logger import os import subprocess -import zlib -import json -import base64 import pytz import datetime as dt from packaging import version as pyver @@ -19,9 +16,6 @@ from rest_framework.response import Response from rest_framework import status, generics from .models import Agent, AgentOutage, RecoveryAction, Note -from winupdate.models import WinUpdatePolicy -from clients.models import Client, Site -from accounts.models import User from core.models import CoreSettings from scripts.models import Script from logs.models import AuditLog @@ -67,20 +61,25 @@ def update_agents(request): @api_view() def ping(request, pk): agent = get_object_or_404(Agent, pk=pk) - r = agent.salt_api_cmd(timeout=5, func="test.ping") + if not agent.has_nats: + return notify_error("Requires agent version 1.1.0 or greater") + r = asyncio.run(agent.nats_cmd({"func": "ping"}, timeout=10)) - if r == "timeout" or r == "error": + if r == "timeout" or r == "natsdown": return Response({"name": agent.hostname, "status": "offline"}) - - if isinstance(r, bool) and r: + elif r == "pong": return Response({"name": agent.hostname, "status": "online"}) - else: - return Response({"name": agent.hostname, "status": "offline"}) + + return Response({"name": agent.hostname, "status": "offline"}) @api_view(["DELETE"]) def uninstall(request): agent = get_object_or_404(Agent, pk=request.data["pk"]) + if not agent.has_nats: + return notify_error("Requires agent version 1.1.0 or greater") + + asyncio.run(agent.nats_cmd({"func": "uninstall"}, wait=False)) salt_id = agent.salt_id name = agent.hostname diff --git a/web/src/components/AgentTable.vue b/web/src/components/AgentTable.vue index 45ebb1b6..54df1307 100644 --- a/web/src/components/AgentTable.vue +++ b/web/src/components/AgentTable.vue @@ -536,7 +536,7 @@ export default { }) .catch(e => { this.$q.loading.hide(); - this.notifyError("Something went wrong"); + this.notifyError(e.response.data); }); }, rebootNow(pk, hostname) {