workaround for broken salt bg scripts

This commit is contained in:
wh1te909 2020-10-29 08:04:15 +00:00
parent a5182aa48b
commit 8d33b4b099
2 changed files with 29 additions and 16 deletions

View File

@ -37,6 +37,7 @@ from winupdate.serializers import WinUpdatePolicySerializer
from .tasks import uninstall_agent_task, send_agent_update_task
from winupdate.tasks import bulk_check_for_updates_task
from scripts.tasks import run_script_bg_task
from tacticalrmm.utils import notify_error
@ -709,22 +710,14 @@ def run_script(request):
return notify_error(str(r))
else:
r = agent.salt_api_async(
func="win_agent.run_script",
kwargs={
"filepath": script.filepath,
"filename": script.filename,
"shell": script.shell,
"timeout": request.data["timeout"],
"args": args,
"bg": True,
},
)
if r != "timeout":
return Response(f"{script.name} will now be run on {agent.hostname}")
else:
return notify_error("Something went wrong")
data = {
"agentpk": agent.pk,
"scriptpk": script.pk,
"timeout": request.data["timeout"],
"args": args,
}
run_script_bg_task.delay(data)
return Response(f"{script.name} will now be run on {agent.hostname}")
@api_view()

View File

@ -0,0 +1,20 @@
from tacticalrmm.celery import app
from agents.models import Agent
from .models import Script
@app.task
def run_script_bg_task(data):
agent = Agent.objects.get(pk=data["agentpk"])
script = Script.objects.get(pk=data["scriptpk"])
agent.salt_api_async(
func="win_agent.run_script",
kwargs={
"filepath": script.filepath,
"filename": script.filename,
"shell": script.shell,
"timeout": data["timeout"],
"args": data["args"],
},
)