From 335e571485d90052f02da4daf17d3eadd5f67496 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Sat, 20 Feb 2021 10:33:21 +0000 Subject: [PATCH 1/4] add optional --force flag to update.sh --- update.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/update.sh b/update.sh index 61eeb5bbba..a07b6c20f4 100644 --- a/update.sh +++ b/update.sh @@ -1,6 +1,6 @@ #!/bin/bash -SCRIPT_VERSION="108" +SCRIPT_VERSION="109" SCRIPT_URL='https://raw.githubusercontent.com/wh1te909/tacticalrmm/master/update.sh' LATEST_SETTINGS_URL='https://raw.githubusercontent.com/wh1te909/tacticalrmm/master/api/tacticalrmm/tacticalrmm/settings.py' YELLOW='\033[1;33m' @@ -114,10 +114,12 @@ SETTINGS_FILE="/rmm/api/tacticalrmm/tacticalrmm/settings.py" LATEST_TRMM_VER=$(grep "^TRMM_VERSION" "$TMP_SETTINGS" | awk -F'[= "]' '{print $5}') CURRENT_TRMM_VER=$(grep "^TRMM_VERSION" "$SETTINGS_FILE" | awk -F'[= "]' '{print $5}') -if [[ "${CURRENT_TRMM_VER}" == "${LATEST_TRMM_VER}" ]]; then - printf >&2 "${GREEN}Already on latest version. Current version: ${CURRENT_TRMM_VER} Latest version: ${LATEST_TRMM_VER}${NC}\n" - rm -f $TMP_SETTINGS - exit 0 +if [[ $* != *--force* ]]; then + if [[ "${CURRENT_TRMM_VER}" == "${LATEST_TRMM_VER}" ]]; then + printf >&2 "${GREEN}Already on latest version. Current version: ${CURRENT_TRMM_VER} Latest version: ${LATEST_TRMM_VER}${NC}\n" + rm -f $TMP_SETTINGS + exit 0 + fi fi LATEST_MESH_VER=$(grep "^MESH_VER" "$TMP_SETTINGS" | awk -F'[= "]' '{print $5}') From f274c8e8373906c3c6f89cec1555365576ad34b6 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Sat, 20 Feb 2021 11:01:04 +0000 Subject: [PATCH 2/4] add prune alerts to server maintenance tool --- api/tacticalrmm/accounts/views.py | 1 - api/tacticalrmm/core/tests.py | 2 +- api/tacticalrmm/core/views.py | 7 +++++++ web/src/components/modals/core/ServerMaintenance.vue | 3 +++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/api/tacticalrmm/accounts/views.py b/api/tacticalrmm/accounts/views.py index c47e89e20a..9ff457704a 100644 --- a/api/tacticalrmm/accounts/views.py +++ b/api/tacticalrmm/accounts/views.py @@ -10,7 +10,6 @@ from rest_framework.response import Response from rest_framework.views import APIView -from agents.models import Agent from logs.models import AuditLog from tacticalrmm.utils import notify_error diff --git a/api/tacticalrmm/core/tests.py b/api/tacticalrmm/core/tests.py index e0edcbf955..0e234c27c3 100644 --- a/api/tacticalrmm/core/tests.py +++ b/api/tacticalrmm/core/tests.py @@ -116,7 +116,7 @@ def test_ui_maintenance_actions(self, remove_orphaned_win_tasks, reload_nats): # test prune db with tables data = { "action": "prune_db", - "prune_tables": ["audit_logs", "agent_outages", "pending_actions"], + "prune_tables": ["audit_logs", "alerts", "pending_actions"], } r = self.client.post(url, data) self.assertEqual(r.status_code, 200) diff --git a/api/tacticalrmm/core/views.py b/api/tacticalrmm/core/views.py index 39b48b3935..6f17ffa1f6 100644 --- a/api/tacticalrmm/core/views.py +++ b/api/tacticalrmm/core/views.py @@ -122,6 +122,13 @@ def server_maintenance(request): records_count += pendingactions.count() pendingactions.delete() + if "alerts" in tables: + from alerts.models import Alert + + alerts = Alert.objects.all() + records_count += alerts.count() + alerts.delete() + return Response(f"{records_count} records were pruned from the database") return notify_error("The data is incorrect") diff --git a/web/src/components/modals/core/ServerMaintenance.vue b/web/src/components/modals/core/ServerMaintenance.vue index 3b03194a66..82d2437d97 100644 --- a/web/src/components/modals/core/ServerMaintenance.vue +++ b/web/src/components/modals/core/ServerMaintenance.vue @@ -32,6 +32,9 @@ Removes completed pending actions + + Removes all alerts + From 6ea4e97eca42fdd7a50037e26fbcd0b0acea7ace Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Sat, 20 Feb 2021 22:33:10 +0000 Subject: [PATCH 3/4] fix script args --- api/tacticalrmm/agents/tasks.py | 10 ++++++++-- api/tacticalrmm/agents/views.py | 8 ++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/api/tacticalrmm/agents/tasks.py b/api/tacticalrmm/agents/tasks.py index 1894a273d6..e5e2ffa477 100644 --- a/api/tacticalrmm/agents/tasks.py +++ b/api/tacticalrmm/agents/tasks.py @@ -214,11 +214,17 @@ def handle_agent_recovery_task(pk: int) -> None: @app.task def run_script_email_results_task( - agentpk: int, scriptpk: int, nats_timeout: int, emails: List[str] + agentpk: int, + scriptpk: int, + nats_timeout: int, + emails: List[str], + args: List[str] = [], ): agent = Agent.objects.get(pk=agentpk) script = Script.objects.get(pk=scriptpk) - r = agent.run_script(scriptpk=script.pk, full=True, timeout=nats_timeout, wait=True) + r = agent.run_script( + scriptpk=script.pk, args=args, full=True, timeout=nats_timeout, wait=True + ) if r == "timeout": logger.error(f"{agent.hostname} timed out running script.") return diff --git a/api/tacticalrmm/agents/views.py b/api/tacticalrmm/agents/views.py index 93a90f9454..54ae751c78 100644 --- a/api/tacticalrmm/agents/views.py +++ b/api/tacticalrmm/agents/views.py @@ -685,6 +685,7 @@ def run_script(request): return notify_error("Requires agent version 1.1.0 or greater") script = get_object_or_404(Script, pk=request.data["scriptPK"]) output = request.data["output"] + args = request.data["args"] req_timeout = int(request.data["timeout"]) + 3 AuditLog.audit_script_run( @@ -694,7 +695,9 @@ def run_script(request): ) if output == "wait": - r = agent.run_script(scriptpk=script.pk, timeout=req_timeout, wait=True) + r = agent.run_script( + scriptpk=script.pk, args=args, timeout=req_timeout, wait=True + ) return Response(r) elif output == "email": @@ -709,9 +712,10 @@ def run_script(request): scriptpk=script.pk, nats_timeout=req_timeout, emails=emails, + args=args, ) else: - agent.run_script(scriptpk=script.pk, timeout=req_timeout) + agent.run_script(scriptpk=script.pk, args=args, timeout=req_timeout) return Response(f"{script.name} will now be run on {agent.hostname}") From f45938bdd5ae7c0e4a5d63739229fd708e5b3ff5 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Sat, 20 Feb 2021 22:35:14 +0000 Subject: [PATCH 4/4] bump version --- api/tacticalrmm/tacticalrmm/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/tacticalrmm/tacticalrmm/settings.py b/api/tacticalrmm/tacticalrmm/settings.py index febe2571ed..d2270869cc 100644 --- a/api/tacticalrmm/tacticalrmm/settings.py +++ b/api/tacticalrmm/tacticalrmm/settings.py @@ -15,7 +15,7 @@ AUTH_USER_MODEL = "accounts.User" # latest release -TRMM_VERSION = "0.4.13" +TRMM_VERSION = "0.4.14" # bump this version everytime vue code is changed # to alert user they need to manually refresh their browser