mesh nats

This commit is contained in:
wh1te909 2020-11-22 11:29:47 +00:00
parent e4b1f39fdc
commit f03c28c906
4 changed files with 10 additions and 46 deletions

View File

@ -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/"

View File

@ -25,7 +25,6 @@ urlpatterns = [
path("<int:pk>/ping/", views.ping),
path("recover/", views.recover),
path("runscript/", views.run_script),
path("<int:pk>/restartmesh/", views.restart_mesh),
path("<int:pk>/recovermesh/", views.recover_mesh),
path("<int:pk>/notes/", views.GetAddNotes.as_view()),
path("<int:pk>/note/", views.GetEditDeleteNote.as_view()),

View File

@ -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}")

View File

@ -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 => {