diff --git a/api/tacticalrmm/agents/tests.py b/api/tacticalrmm/agents/tests.py index d1e0fb24..f4fa810c 100644 --- a/api/tacticalrmm/agents/tests.py +++ b/api/tacticalrmm/agents/tests.py @@ -681,28 +681,6 @@ class TestAgentViews(TacticalTestCase): self.check_not_authenticated("post", url) - @patch("agents.models.Agent.salt_api_cmd") - def test_restart_mesh(self, mock_ret): - url = f"/agents/{self.agent.pk}/restartmesh/" - - mock_ret.return_value = "timeout" - r = self.client.get(url) - self.assertEqual(r.status_code, 400) - - mock_ret.return_value = "error" - r = self.client.get(url) - self.assertEqual(r.status_code, 400) - - mock_ret.return_value = False - r = self.client.get(url) - self.assertEqual(r.status_code, 400) - - mock_ret.return_value = True - r = self.client.get(url) - self.assertEqual(r.status_code, 200) - - self.check_not_authenticated("get", url) - @patch("agents.models.Agent.salt_api_cmd") def test_recover_mesh(self, mock_ret): url = f"/agents/{self.agent.pk}/recovermesh/" diff --git a/api/tacticalrmm/agents/urls.py b/api/tacticalrmm/agents/urls.py index 62945e87..bd6da60b 100644 --- a/api/tacticalrmm/agents/urls.py +++ b/api/tacticalrmm/agents/urls.py @@ -25,7 +25,6 @@ urlpatterns = [ path("/ping/", views.ping), path("recover/", views.recover), path("runscript/", views.run_script), - path("/restartmesh/", views.restart_mesh), path("/recovermesh/", views.recover_mesh), path("/notes/", views.GetAddNotes.as_view()), path("/note/", views.GetEditDeleteNote.as_view()), diff --git a/api/tacticalrmm/agents/views.py b/api/tacticalrmm/agents/views.py index 24d636ff..14e351df 100644 --- a/api/tacticalrmm/agents/views.py +++ b/api/tacticalrmm/agents/views.py @@ -687,30 +687,11 @@ def run_script(request): return Response(f"{script.name} will now be run on {agent.hostname}") -@api_view() -def restart_mesh(request, pk): - agent = get_object_or_404(Agent, pk=pk) - r = agent.salt_api_cmd(func="service.restart", arg="mesh agent", timeout=30) - if r == "timeout" or r == "error": - return notify_error("Unable to contact the agent") - elif isinstance(r, bool) and r: - return Response(f"Restarted Mesh Agent on {agent.hostname}") - else: - return notify_error(f"Failed to restart the Mesh Agent on {agent.hostname}") - - @api_view() def recover_mesh(request, pk): agent = get_object_or_404(Agent, pk=pk) - r = agent.salt_api_cmd( - timeout=60, - func="cmd.run", - kwargs={ - "cmd": r'"C:\\Program Files\\TacticalAgent\\tacticalrmm.exe" -m recovermesh', - "timeout": 55, - }, - ) - if r == "timeout" or r == "error": + r = asyncio.run(agent.nats_cmd({"func": "recovermesh"}, timeout=45)) + if r == "timeout": return notify_error("Unable to contact the agent") return Response(f"Repaired mesh agent on {agent.hostname}") diff --git a/web/src/views/TakeControl.vue b/web/src/views/TakeControl.vue index 8c850779..02e1281c 100644 --- a/web/src/views/TakeControl.vue +++ b/web/src/views/TakeControl.vue @@ -75,13 +75,19 @@ export default { restart() { this.visible = false; this.$q.loading.show({ message: "Restarting Mesh Agent" }); + const data = { + pk: this.$route.params.pk, + sv_name: "mesh agent", + sv_action: "restart", + }; + this.$axios - .get(`/agents/${this.$route.params.pk}/restartmesh/`) + .post("/services/serviceaction/", data) .then(r => { setTimeout(() => { this.visible = true; this.$q.loading.hide(); - this.notifySuccess(r.data); + this.notifySuccess("Mesh agent service was restarted"); }, 500); }) .catch(e => {