add check to remove salt

This commit is contained in:
wh1te909
2021-01-21 23:58:31 +00:00
parent 6a7f17b2b0
commit cadab160ff
8 changed files with 60 additions and 16 deletions

View File

@@ -2,7 +2,6 @@ import asyncio
from loguru import logger
from time import sleep
import random
import requests
from packaging import version as pyver
from typing import List
@@ -301,3 +300,18 @@ def run_script_email_results_task(
server.quit()
except Exception as e:
logger.error(e)
@app.task
def remove_salt_task() -> None:
if hasattr(settings, "KEEP_SALT") and settings.KEEP_SALT:
return
q = Agent.objects.all()
agents = [i for i in q if pyver.parse(i.version) >= pyver.parse("1.3.0")]
chunks = (agents[i : i + 50] for i in range(0, len(agents), 50))
for chunk in chunks:
for agent in chunk:
asyncio.run(agent.nats_cmd({"func": "removesalt"}, wait=False))
sleep(0.1)
sleep(4)

View File

@@ -663,12 +663,12 @@ def recover(request):
return notify_error("Only available in agent version greater than 0.9.5")
if not agent.has_nats:
if mode == "tacagent" or mode == "checkrunner" or mode == "rpc":
if mode == "tacagent" or mode == "rpc":
return notify_error("Requires agent version 1.1.0 or greater")
# attempt a realtime recovery if supported, otherwise fall back to old recovery method
if agent.has_nats:
if mode == "tacagent" or mode == "checkrunner" or mode == "mesh":
if mode == "tacagent" or mode == "mesh":
data = {"func": "recover", "payload": {"mode": mode}}
r = asyncio.run(agent.nats_cmd(data, timeout=10))
if r == "ok":

View File

@@ -1343,10 +1343,5 @@
"name": "tacticalagent",
"description": "Tactical RMM Monitoring Agent",
"display_name": "Tactical RMM Agent"
},
{
"name": "checkrunner",
"description": "Tactical Agent Background Check Runner",
"display_name": "Tactical Agent Check Runner"
}
]

View File

@@ -49,6 +49,10 @@ app.conf.beat_schedule = {
"task": "agents.tasks.monitor_agents_task",
"schedule": crontab(minute="*/15"),
},
"remove-salt": {
"task": "agents.tasks.remove_salt_task",
"schedule": crontab(minute=14, hour="*/2"),
},
}

View File

@@ -356,6 +356,7 @@ if not DEBUG:
MESH_USERNAME = "${meshusername}"
MESH_SITE = "https://${meshdomain}"
REDIS_HOST = "localhost"
KEEP_SALT = False
EOF
)"
echo "${localvars}" > /rmm/api/tacticalrmm/tacticalrmm/local_settings.py

View File

@@ -190,6 +190,37 @@ sudo chown -R $USER:$GROUP /home/${USER}/.cache
sudo chown ${USER}:${USER} -R /etc/letsencrypt
sudo chmod 775 -R /etc/letsencrypt
CHECK_REMOVE_SALT=$(grep KEEP_SALT /rmm/api/tacticalrmm/tacticalrmm/local_settings.py)
if ! [[ $CHECK_REMOVE_SALT ]]; then
printf >&2 "${YELLOW}This update removes salt from the rmm${NC}\n"
printf >&2 "${YELLOW}You may continue to use salt on existing agents, but there will not be any more integration with tacticalrmm, and new agents will not install the salt-minion${NC}\n"
until [[ $rmsalt =~ (y|n) ]]; do
echo -ne "${YELLOW}Would you like to remove salt? (recommended) [y/n]${NC}: "
read rmsalt
done
if [[ $rmsalt == "y" ]]; then
keepsalt="$(cat << EOF
KEEP_SALT = False
EOF
)"
else
keepsalt="$(cat << EOF
KEEP_SALT = True
EOF
)"
fi
echo "${keepsalt}" | tee --append /rmm/api/tacticalrmm/tacticalrmm/local_settings.py > /dev/null
if [[ $rmsalt == "y" ]]; then
printf >&2 "${Green}Removing salt-master and salt-api${NC}\n"
for i in salt-api salt-master; do sudo systemctl stop $i; sudo systemctl disable $i; done
sudo apt remove -y salt-master salt-api
else
sudo systemctl stop salt-api
sudo systemctl disable salt-api
fi
fi
/usr/local/rmmgo/go/bin/go get github.com/josephspurrier/goversioninfo/cmd/goversioninfo
sudo cp /rmm/api/tacticalrmm/core/goinstaller/bin/goversioninfo /usr/local/bin/
sudo chown ${USER}:${USER} /usr/local/bin/goversioninfo

View File

@@ -500,9 +500,12 @@ export default {
});
},
runPatchStatusScan(pk, hostname) {
axios.get(`/winupdate/${pk}/runupdatescan/`).then(r => {
this.$axios
.get(`/winupdate/${pk}/runupdatescan/`)
.then(r => {
this.notifySuccess(`Scan will be run shortly on ${hostname}`);
});
})
.catch(e => this.notifyError(e.response.data));
},
installPatches(pk) {
this.$q.loading.show();

View File

@@ -12,7 +12,6 @@
<q-radio dense v-model="mode" val="mesh" label="Mesh Agent" />
<q-radio dense v-model="mode" val="rpc" label="Tactical RPC" />
<q-radio dense v-model="mode" val="tacagent" label="Tactical Agent" />
<q-radio dense v-model="mode" val="checkrunner" label="Tactical Checkrunner" />
<q-radio dense v-model="mode" val="command" label="Shell Command" />
</div>
</q-card-section>
@@ -20,10 +19,7 @@
<p>Fix issues with the Mesh Agent which handles take control, live terminal and file browser.</p>
</q-card-section>
<q-card-section v-show="mode === 'tacagent'">
<p>Fix issues with the TacticalAgent windows service which handles agent check-in and os info.</p>
</q-card-section>
<q-card-section v-show="mode === 'checkrunner'">
<p>Fix issues with the Tactical Checkrunner windows service which handles running all checks.</p>
<p>Fix issues with the TacticalAgent windows service which handles agent check-in.</p>
</q-card-section>
<q-card-section v-show="mode === 'rpc'">
<p>