simplify remote agent uninstall
This commit is contained in:
parent
e9394b4510
commit
8ba56b0c67
|
@ -16,3 +16,9 @@ def run_python_script(filename, timeout):
|
|||
return __salt__["cmd.run_all"](
|
||||
"{0} {1}".format(python_bin, file_path), timeout=timeout
|
||||
)
|
||||
|
||||
|
||||
def uninstall_agent():
|
||||
remove_exe = os.path.join("C:\\Program Files\\TacticalAgent", "unins000.exe")
|
||||
__salt__["cmd.run_bg"]([remove_exe, "/VERYSILENT", "/SUPPRESSMSGBOXES"])
|
||||
return "ok"
|
||||
|
|
|
@ -44,6 +44,7 @@ def sync_salt_modules_task(pk):
|
|||
@app.task
|
||||
def uninstall_agent_task(pk, wait=True):
|
||||
agent = Agent.objects.get(pk=pk)
|
||||
salt_id = agent.salt_id
|
||||
agent.uninstall_inprogress = True
|
||||
agent.save(update_fields=["uninstall_inprogress"])
|
||||
logger.info(f"{agent.hostname} uninstall task is running")
|
||||
|
@ -52,26 +53,29 @@ def uninstall_agent_task(pk, wait=True):
|
|||
logger.info(f"{agent.hostname} waiting 90 seconds before uninstalling")
|
||||
sleep(90) # need to give salt time to startup on the minion
|
||||
|
||||
resp2 = agent.salt_api_cmd(
|
||||
hostname=agent.salt_id,
|
||||
timeout=60,
|
||||
func="cp.get_file",
|
||||
arg=["salt://scripts/removeagent.exe", "C:\\Windows\\Temp\\"],
|
||||
)
|
||||
data2 = resp2.json()
|
||||
if not data2["return"][0][agent.salt_id]:
|
||||
logger.error(f"{agent.hostname} unable to copy file")
|
||||
return f"{agent.hostname} unable to copy file"
|
||||
attempts = 0
|
||||
error = False
|
||||
|
||||
agent.salt_api_cmd(
|
||||
hostname=agent.salt_id,
|
||||
timeout=500,
|
||||
func="cmd.script",
|
||||
arg="salt://scripts/uninstall.bat",
|
||||
)
|
||||
while 1:
|
||||
attempts += 1
|
||||
r = agent.salt_api_cmd(
|
||||
hostname=salt_id, timeout=60, func="win_agent.uninstall_agent"
|
||||
)
|
||||
if r.json()["return"][0][salt_id] != "ok":
|
||||
if attempts >= 10:
|
||||
error = True
|
||||
break
|
||||
else:
|
||||
continue
|
||||
else:
|
||||
break
|
||||
|
||||
logger.info(f"{agent.hostname} was successfully uninstalled")
|
||||
return f"{agent.hostname} was successfully uninstalled"
|
||||
if error:
|
||||
logger.error(f"{salt_id} uninstall failed")
|
||||
else:
|
||||
logger.info(f"{salt_id} was successfully uninstalled")
|
||||
|
||||
return "agent uninstall"
|
||||
|
||||
|
||||
def service_action(hostname, action, service):
|
||||
|
|
Binary file not shown.
|
@ -1,23 +0,0 @@
|
|||
package main
|
||||
|
||||
import(
|
||||
"os/exec"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main(){
|
||||
unins_file := "C:\\Program Files\\TacticalAgent\\unins000.exe"
|
||||
|
||||
if fileExists(unins_file) {
|
||||
c := exec.Command("cmd", "/C", unins_file, "/VERYSILENT", "/SUPPRESSMSGBOXES")
|
||||
c.Run()
|
||||
}
|
||||
}
|
||||
|
||||
func fileExists(filename string) bool {
|
||||
info, err := os.Stat(filename)
|
||||
if os.IsNotExist(err) {
|
||||
return false
|
||||
}
|
||||
return !info.IsDir()
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
start "" "C:\Windows\Temp\removeagent.exe"
|
Loading…
Reference in New Issue