From 653c482ff791a867beefdff1b8dfec5cc3aba970 Mon Sep 17 00:00:00 2001 From: dinger1986 Date: Sat, 23 Apr 2022 15:03:58 +0100 Subject: [PATCH 01/12] Update troubleshoot_server.sh add in output of afew log log files --- troubleshoot_server.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/troubleshoot_server.sh b/troubleshoot_server.sh index 688a166795..5fd0190c5f 100644 --- a/troubleshoot_server.sh +++ b/troubleshoot_server.sh @@ -328,7 +328,12 @@ else echo -ne ${RED} SSL Certificate has expired or doesnt exist for $domain | tee -a checklog.log printf >&2 "\n\n" fi + echo -ne ${YELLOW} Getting summary output of logs | tee -a checklog.log +tail /rmm/api/tacticalrmm/tacticalrmm/private/log/django_debug.log | tee -a checklog.log + printf >&2 "\n\n" +tail /rmm/api/tacticalrmm/tacticalrmm/private/log/error.log | tee -a checklog.log + printf >&2 "\n\n" printf >&2 "\n\n" echo -ne ${YELLOW} From 7a5f03d672df9e4b0a70aefc56c921e7d44f47a3 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Sat, 23 Apr 2022 23:24:36 +0000 Subject: [PATCH 02/12] fix slow query --- api/tacticalrmm/agents/views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/api/tacticalrmm/agents/views.py b/api/tacticalrmm/agents/views.py index 11e07fd3db..66bc527d34 100644 --- a/api/tacticalrmm/agents/views.py +++ b/api/tacticalrmm/agents/views.py @@ -297,9 +297,9 @@ def post(self, request, agent_id): @permission_classes([IsAuthenticated, AgentPerms]) def get_agent_versions(request): agents = ( - Agent.objects.filter_by_role(request.user) # type: ignore - .prefetch_related("site") - .only("pk", "hostname") + Agent.objects.defer(*AGENT_DEFER) + .filter_by_role(request.user) # type: ignore + .prefetch_related("site", "site__client") ) return Response( { From 1d70c1502710481968d8ac47f77a907aabf5cdb7 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Sun, 24 Apr 2022 01:45:03 +0000 Subject: [PATCH 03/12] wrong related --- api/tacticalrmm/agents/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/tacticalrmm/agents/views.py b/api/tacticalrmm/agents/views.py index 66bc527d34..9336d0077f 100644 --- a/api/tacticalrmm/agents/views.py +++ b/api/tacticalrmm/agents/views.py @@ -299,7 +299,7 @@ def get_agent_versions(request): agents = ( Agent.objects.defer(*AGENT_DEFER) .filter_by_role(request.user) # type: ignore - .prefetch_related("site", "site__client") + .select_related("site", "site__client") ) return Response( { From 638603ac6be31ea23d306ca7f6e8a58d0767dfc9 Mon Sep 17 00:00:00 2001 From: sadnub Date: Sun, 24 Apr 2022 16:35:18 -0400 Subject: [PATCH 04/12] fix variable substitution when running policy tasks --- api/tacticalrmm/apiv3/views.py | 4 ++-- api/tacticalrmm/autotasks/serializers.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/api/tacticalrmm/apiv3/views.py b/api/tacticalrmm/apiv3/views.py index 680a6acb64..5e90634a3d 100644 --- a/api/tacticalrmm/apiv3/views.py +++ b/api/tacticalrmm/apiv3/views.py @@ -266,9 +266,9 @@ class TaskRunner(APIView): permission_classes = [IsAuthenticated] def get(self, request, pk, agentid): - _ = get_object_or_404(Agent, agent_id=agentid) + agent = get_object_or_404(Agent, agent_id=agentid) task = get_object_or_404(AutomatedTask, pk=pk) - return Response(TaskGOGetSerializer(task).data) + return Response(TaskGOGetSerializer(task, context={"agent": agent}).data) def patch(self, request, pk, agentid): from alerts.models import Alert diff --git a/api/tacticalrmm/autotasks/serializers.py b/api/tacticalrmm/autotasks/serializers.py index ab5341c119..dda6cbb4f6 100644 --- a/api/tacticalrmm/autotasks/serializers.py +++ b/api/tacticalrmm/autotasks/serializers.py @@ -198,13 +198,14 @@ class TaskGOGetSerializer(serializers.ModelSerializer): def get_task_actions(self, obj): tmp = [] actions_to_remove = [] + agent = self.context["agent"] if "agent" in self.context.keys() else obj.agent for action in obj.actions: if action["type"] == "cmd": tmp.append( { "type": "cmd", "command": Script.parse_script_args( - agent=obj.agent, + agent=agent, shell=action["shell"], args=[action["command"]], )[0], @@ -225,7 +226,7 @@ def get_task_actions(self, obj): "script_name": script.name, "code": script.code, "script_args": Script.parse_script_args( - agent=obj.agent, + agent=agent, shell=script.shell, args=action["script_args"], ), From a7a71b4a4634c78257b8df1d06cf06fc89a4600c Mon Sep 17 00:00:00 2001 From: sadnub Date: Sun, 24 Apr 2022 16:35:42 -0400 Subject: [PATCH 05/12] fix default tab not working if 'servers' is selected --- web/src/store/index.js | 2 +- web/src/views/Dashboard.vue | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/web/src/store/index.js b/web/src/store/index.js index c12d32fc4c..e7877c0aae 100644 --- a/web/src/store/index.js +++ b/web/src/store/index.js @@ -23,7 +23,7 @@ export default function () { showCommunityScripts: false, agentDblClickAction: "", agentUrlAction: null, - defaultAgentTblTab: "server", + defaultAgentTblTab: null, clientTreeSort: "alphafail", clientTreeSplitter: 20, noCodeSign: false, diff --git a/web/src/views/Dashboard.vue b/web/src/views/Dashboard.vue index 2fdc45813e..530afdce90 100644 --- a/web/src/views/Dashboard.vue +++ b/web/src/views/Dashboard.vue @@ -490,10 +490,12 @@ export default { selectedTree(newVal, oldVal) { if (this.clearSearchWhenSwitching) this.clearFilter(); }, + tab(newVal, oldVal) { + this.$store.dispatch("loadAgents"); + }, }, methods: { getTree() { - this.$store.dispatch("loadAgents"); this.$store.dispatch("loadTree"); }, clearTreeSelected() { @@ -707,7 +709,6 @@ export default { }, set(newVal) { this.$store.commit("SET_DEFAULT_AGENT_TBL_TAB", newVal); - this.$store.dispatch("loadAgents"); this.$store.commit("destroySubTable"); }, }, From 5ca9d30d5f2ee785e75dcbab9aeaa3be988efcf4 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Sun, 24 Apr 2022 21:23:33 +0000 Subject: [PATCH 06/12] add a test and optimize some queries --- api/tacticalrmm/agents/views.py | 2 +- api/tacticalrmm/core/tests.py | 28 ++++++++++++++++++++++++++- api/tacticalrmm/logs/baker_recipes.py | 4 ++++ api/tacticalrmm/logs/views.py | 9 +++++++-- 4 files changed, 39 insertions(+), 4 deletions(-) diff --git a/api/tacticalrmm/agents/views.py b/api/tacticalrmm/agents/views.py index 9336d0077f..051cbf37b8 100644 --- a/api/tacticalrmm/agents/views.py +++ b/api/tacticalrmm/agents/views.py @@ -299,7 +299,7 @@ def get_agent_versions(request): agents = ( Agent.objects.defer(*AGENT_DEFER) .filter_by_role(request.user) # type: ignore - .select_related("site", "site__client") + .select_related("site__client") ) return Response( { diff --git a/api/tacticalrmm/core/tests.py b/api/tacticalrmm/core/tests.py index 65bbf7fe27..cebedef9a8 100644 --- a/api/tacticalrmm/core/tests.py +++ b/api/tacticalrmm/core/tests.py @@ -1,6 +1,7 @@ from unittest.mock import patch import requests +from django.conf import settings from channels.db import database_sync_to_async from channels.testing import WebsocketCommunicator from model_bakery import baker @@ -11,7 +12,9 @@ from .consumers import DashInfo from .models import CustomField, GlobalKVStore, URLAction from .serializers import CustomFieldSerializer, KeyStoreSerializer, URLActionSerializer -from .tasks import core_maintenance_tasks +from .tasks import core_maintenance_tasks, handle_resolved_stuff +from logs.models import PendingAction +from agents.models import Agent class TestCodeSign(TacticalTestCase): @@ -393,6 +396,29 @@ def test_clear_cache(self): self.check_not_authenticated("get", url) + def test_resolved_pending_agentupdate_task(self): + online = baker.make_recipe("agents.online_agent", version="2.0.0", _quantity=20) + offline = baker.make_recipe( + "agents.offline_agent", version="2.0.0", _quantity=20 + ) + agents = online + offline + for agent in agents: + baker.make_recipe("logs.pending_agentupdate_action", agent=agent) + + Agent.objects.update(version=settings.LATEST_AGENT_VER) + + handle_resolved_stuff() + + complete = PendingAction.objects.filter( + action_type="agentupdate", status="completed" + ).count() + old = PendingAction.objects.filter( + action_type="agentupdate", status="pending" + ).count() + + self.assertEqual(complete, 20) + self.assertEqual(old, 20) + class TestCorePermissions(TacticalTestCase): def setUp(self): diff --git a/api/tacticalrmm/logs/baker_recipes.py b/api/tacticalrmm/logs/baker_recipes.py index 06a55f9d08..9093c55a07 100644 --- a/api/tacticalrmm/logs/baker_recipes.py +++ b/api/tacticalrmm/logs/baker_recipes.py @@ -26,3 +26,7 @@ ) login_logs = Recipe("logs.AuditLog", action=cycle(login_actions), object_type="user") + +pending_agentupdate_action = Recipe( + "logs.PendingAction", action_type="agentupdate", status="pending" +) diff --git a/api/tacticalrmm/logs/views.py b/api/tacticalrmm/logs/views.py index e83c7628be..c58f6454be 100644 --- a/api/tacticalrmm/logs/views.py +++ b/api/tacticalrmm/logs/views.py @@ -96,9 +96,14 @@ class PendingActions(APIView): def get(self, request, agent_id=None): if agent_id: agent = get_object_or_404( - Agent.objects.defer(*AGENT_DEFER), agent_id=agent_id + Agent.objects.defer(*AGENT_DEFER).prefetch_related("pendingactions"), + agent_id=agent_id, + ) + actions = ( + PendingAction.objects.filter(agent=agent) + .select_related("agent__site", "agent__site__client") + .defer("agent__services", "agent__wmi_detail") ) - actions = PendingAction.objects.filter(agent=agent) else: actions = ( PendingAction.objects.filter_by_role(request.user) # type: ignore From d8caf12fdcfb085f2d0d630a7f4035edf7848c07 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Sun, 24 Apr 2022 22:07:24 +0000 Subject: [PATCH 07/12] optimize policy query --- api/tacticalrmm/automation/views.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api/tacticalrmm/automation/views.py b/api/tacticalrmm/automation/views.py index 43209f9f96..63bd0b438f 100644 --- a/api/tacticalrmm/automation/views.py +++ b/api/tacticalrmm/automation/views.py @@ -28,7 +28,9 @@ class GetAddPolicies(APIView): permission_classes = [IsAuthenticated, AutomationPolicyPerms] def get(self, request): - policies = Policy.objects.all() + policies = Policy.objects.select_related("alert_template").prefetch_related( + "excluded_agents", "excluded_sites", "excluded_clients" + ) return Response( PolicyTableSerializer( From a04ed5c3cae55ac48b9cadf6f3d1259662830aaa Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Sun, 24 Apr 2022 23:09:44 +0000 Subject: [PATCH 08/12] remove duplicate settings --- api/tacticalrmm/tacticalrmm/settings.py | 21 +-------------------- 1 file changed, 1 insertion(+), 20 deletions(-) diff --git a/api/tacticalrmm/tacticalrmm/settings.py b/api/tacticalrmm/tacticalrmm/settings.py index c03e3d8fc0..3a0adb136c 100644 --- a/api/tacticalrmm/tacticalrmm/settings.py +++ b/api/tacticalrmm/tacticalrmm/settings.py @@ -95,23 +95,6 @@ {"DEFAULT_RENDERER_CLASSES": ("rest_framework.renderers.JSONRenderer",)} ) -MIDDLEWARE = [ - "django.middleware.security.SecurityMiddleware", - "django.contrib.sessions.middleware.SessionMiddleware", - "corsheaders.middleware.CorsMiddleware", ## - "tacticalrmm.middleware.LogIPMiddleware", - "django.middleware.common.CommonMiddleware", - "django.middleware.csrf.CsrfViewMiddleware", - "django.contrib.auth.middleware.AuthenticationMiddleware", - "tacticalrmm.middleware.AuditMiddleware", - "tacticalrmm.middleware.LinuxMiddleware", - "django.middleware.clickjacking.XFrameOptionsMiddleware", -] - -if DEMO: - MIDDLEWARE += ("tacticalrmm.middleware.DemoMiddleware",) - - INSTALLED_APPS = [ "django.contrib.auth", "django.contrib.contenttypes", @@ -256,11 +239,9 @@ }, } -if "AZPIPELINE" in os.environ: - ADMIN_ENABLED = False if "GHACTIONS" in os.environ: - print("-----------------------PIPELINE----------------------------") + print("-----------------------GHACTIONS----------------------------") DATABASES = { "default": { "ENGINE": "django.db.backends.postgresql", From b57fc8a29c84417794071376aab779a764abedd9 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Sun, 24 Apr 2022 23:14:37 +0000 Subject: [PATCH 09/12] testing num queries --- api/tacticalrmm/agents/tests.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/api/tacticalrmm/agents/tests.py b/api/tacticalrmm/agents/tests.py index 0dca310759..415d535ac5 100644 --- a/api/tacticalrmm/agents/tests.py +++ b/api/tacticalrmm/agents/tests.py @@ -245,7 +245,10 @@ def test_get_patch_policy(self): def test_get_agent_versions(self): url = "/agents/versions/" - r = self.client.get(url) + + with self.assertNumQueries(1): + r = self.client.get(url) + self.assertEqual(r.status_code, 200) assert any(i["hostname"] == self.agent.hostname for i in r.json()["agents"]) From c03cd538537065c213b99624ae04cef858059da7 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Sun, 24 Apr 2022 23:20:39 +0000 Subject: [PATCH 10/12] fix deprecated function --- api/tacticalrmm/accounts/tests.py | 2 +- api/tacticalrmm/alerts/tests.py | 76 ++++++++++++++--------------- api/tacticalrmm/apiv3/tests.py | 2 +- api/tacticalrmm/automation/tests.py | 20 ++++---- api/tacticalrmm/checks/tests.py | 12 ++--- api/tacticalrmm/scripts/tests.py | 4 +- api/tacticalrmm/services/tests.py | 4 +- api/tacticalrmm/software/tests.py | 4 +- 8 files changed, 62 insertions(+), 62 deletions(-) diff --git a/api/tacticalrmm/accounts/tests.py b/api/tacticalrmm/accounts/tests.py index e06c9f29c4..7cc30455b4 100644 --- a/api/tacticalrmm/accounts/tests.py +++ b/api/tacticalrmm/accounts/tests.py @@ -338,7 +338,7 @@ def test_modify_api_key(self): resp = self.client.put(url, data, format="json") self.assertEqual(resp.status_code, 200) apikey = APIKey.objects.get(pk=apikey.pk) - self.assertEquals(apikey.name, "New Name") + self.assertEqual(apikey.name, "New Name") self.check_not_authenticated("put", url) diff --git a/api/tacticalrmm/alerts/tests.py b/api/tacticalrmm/alerts/tests.py index 91dc82f357..900f52e64f 100644 --- a/api/tacticalrmm/alerts/tests.py +++ b/api/tacticalrmm/alerts/tests.py @@ -70,8 +70,8 @@ def test_get_alerts(self): data = {"top": 3} resp = self.client.patch(url, data, format="json") self.assertEqual(resp.status_code, 200) - self.assertEquals(resp.data["alerts"], AlertSerializer(alerts, many=True).data) - self.assertEquals(resp.data["alerts_count"], 10) + self.assertEqual(resp.data["alerts"], AlertSerializer(alerts, many=True).data) + self.assertEqual(resp.data["alerts_count"], 10) # test filter data # test data and result counts @@ -409,15 +409,15 @@ def test_agent_gets_correct_alert_template(self): core.server_policy = policy core.save() - self.assertEquals(server.set_alert_template().pk, alert_templates[0].pk) - self.assertEquals(workstation.set_alert_template().pk, alert_templates[0].pk) + self.assertEqual(server.set_alert_template().pk, alert_templates[0].pk) + self.assertEqual(workstation.set_alert_template().pk, alert_templates[0].pk) # assign second Alert Template to as default alert template core.alert_template = alert_templates[1] core.save() - self.assertEquals(workstation.set_alert_template().pk, alert_templates[1].pk) - self.assertEquals(server.set_alert_template().pk, alert_templates[1].pk) + self.assertEqual(workstation.set_alert_template().pk, alert_templates[1].pk) + self.assertEqual(server.set_alert_template().pk, alert_templates[1].pk) # assign third Alert Template to client workstation.client.alert_template = alert_templates[2] @@ -425,8 +425,8 @@ def test_agent_gets_correct_alert_template(self): workstation.client.save() server.client.save() - self.assertEquals(workstation.set_alert_template().pk, alert_templates[2].pk) - self.assertEquals(server.set_alert_template().pk, alert_templates[2].pk) + self.assertEqual(workstation.set_alert_template().pk, alert_templates[2].pk) + self.assertEqual(server.set_alert_template().pk, alert_templates[2].pk) # apply policy to client and should override workstation.client.workstation_policy = policy @@ -434,8 +434,8 @@ def test_agent_gets_correct_alert_template(self): workstation.client.save() server.client.save() - self.assertEquals(workstation.set_alert_template().pk, alert_templates[0].pk) - self.assertEquals(server.set_alert_template().pk, alert_templates[0].pk) + self.assertEqual(workstation.set_alert_template().pk, alert_templates[0].pk) + self.assertEqual(server.set_alert_template().pk, alert_templates[0].pk) # assign fouth Alert Template to site workstation.site.alert_template = alert_templates[3] @@ -443,8 +443,8 @@ def test_agent_gets_correct_alert_template(self): workstation.site.save() server.site.save() - self.assertEquals(workstation.set_alert_template().pk, alert_templates[3].pk) - self.assertEquals(server.set_alert_template().pk, alert_templates[3].pk) + self.assertEqual(workstation.set_alert_template().pk, alert_templates[3].pk) + self.assertEqual(server.set_alert_template().pk, alert_templates[3].pk) # apply policy to site workstation.site.workstation_policy = policy @@ -452,8 +452,8 @@ def test_agent_gets_correct_alert_template(self): workstation.site.save() server.site.save() - self.assertEquals(workstation.set_alert_template().pk, alert_templates[0].pk) - self.assertEquals(server.set_alert_template().pk, alert_templates[0].pk) + self.assertEqual(workstation.set_alert_template().pk, alert_templates[0].pk) + self.assertEqual(server.set_alert_template().pk, alert_templates[0].pk) # apply policy to agents workstation.policy = policy @@ -461,35 +461,35 @@ def test_agent_gets_correct_alert_template(self): workstation.save() server.save() - self.assertEquals(workstation.set_alert_template().pk, alert_templates[0].pk) - self.assertEquals(server.set_alert_template().pk, alert_templates[0].pk) + self.assertEqual(workstation.set_alert_template().pk, alert_templates[0].pk) + self.assertEqual(server.set_alert_template().pk, alert_templates[0].pk) # test disabling alert template alert_templates[0].is_active = False alert_templates[0].save() - self.assertEquals(workstation.set_alert_template().pk, alert_templates[3].pk) - self.assertEquals(server.set_alert_template().pk, alert_templates[3].pk) + self.assertEqual(workstation.set_alert_template().pk, alert_templates[3].pk) + self.assertEqual(server.set_alert_template().pk, alert_templates[3].pk) # test policy exclusions alert_templates[3].excluded_agents.set([workstation.pk]) - self.assertEquals(workstation.set_alert_template().pk, alert_templates[2].pk) - self.assertEquals(server.set_alert_template().pk, alert_templates[3].pk) + self.assertEqual(workstation.set_alert_template().pk, alert_templates[2].pk) + self.assertEqual(server.set_alert_template().pk, alert_templates[3].pk) # test workstation exclusions alert_templates[2].exclude_workstations = True alert_templates[2].save() - self.assertEquals(workstation.set_alert_template().pk, alert_templates[1].pk) - self.assertEquals(server.set_alert_template().pk, alert_templates[3].pk) + self.assertEqual(workstation.set_alert_template().pk, alert_templates[1].pk) + self.assertEqual(server.set_alert_template().pk, alert_templates[3].pk) # test server exclusions alert_templates[3].exclude_servers = True alert_templates[3].save() - self.assertEquals(workstation.set_alert_template().pk, alert_templates[1].pk) - self.assertEquals(server.set_alert_template().pk, alert_templates[2].pk) + self.assertEqual(workstation.set_alert_template().pk, alert_templates[1].pk) + self.assertEqual(server.set_alert_template().pk, alert_templates[2].pk) @patch("agents.tasks.sleep") @patch("core.models.CoreSettings.send_mail") @@ -523,7 +523,7 @@ def test_handle_agent_alerts( # call outages task and no alert should be created agent_outages_task() - self.assertEquals(Alert.objects.count(), 0) + self.assertEqual(Alert.objects.count(), 0) # set overdue_dashboard_alert and alert should be created agent_dashboard_alert.overdue_dashboard_alert = True @@ -574,22 +574,22 @@ def test_handle_agent_alerts( agent_outages_task() # should have created 6 alerts - self.assertEquals(Alert.objects.count(), 6) + self.assertEqual(Alert.objects.count(), 6) # other specific agents should have created alerts - self.assertEquals(Alert.objects.filter(agent=agent_dashboard_alert).count(), 1) - self.assertEquals(Alert.objects.filter(agent=agent_text_alert).count(), 1) - self.assertEquals(Alert.objects.filter(agent=agent_email_alert).count(), 1) - self.assertEquals(Alert.objects.filter(agent=agent_template_email).count(), 1) - self.assertEquals( + self.assertEqual(Alert.objects.filter(agent=agent_dashboard_alert).count(), 1) + self.assertEqual(Alert.objects.filter(agent=agent_text_alert).count(), 1) + self.assertEqual(Alert.objects.filter(agent=agent_email_alert).count(), 1) + self.assertEqual(Alert.objects.filter(agent=agent_template_email).count(), 1) + self.assertEqual( Alert.objects.filter(agent=agent_template_dashboard).count(), 1 ) - self.assertEquals(Alert.objects.filter(agent=agent_template_text).count(), 1) - self.assertEquals(Alert.objects.filter(agent=agent_template_blank).count(), 0) + self.assertEqual(Alert.objects.filter(agent=agent_template_text).count(), 1) + self.assertEqual(Alert.objects.filter(agent=agent_template_blank).count(), 0) # check if email and text tasks were called - self.assertEquals(outage_email.call_count, 2) - self.assertEquals(outage_sms.call_count, 2) + self.assertEqual(outage_email.call_count, 2) + self.assertEqual(outage_sms.call_count, 2) outage_sms.assert_any_call( pk=Alert.objects.get(agent=agent_text_alert).pk, alert_interval=None @@ -630,7 +630,7 @@ def test_handle_agent_alerts( # calling agent outage task again shouldn't create duplicate alerts and won't send alerts agent_outages_task() - self.assertEquals(Alert.objects.count(), 6) + self.assertEqual(Alert.objects.count(), 6) # test periodic notification # change email/text sent to sometime in the past @@ -942,7 +942,7 @@ def test_handle_check_alerts( send_email.assert_not_called() send_sms.assert_not_called() - self.assertEquals( + self.assertEqual( Alert.objects.filter(assigned_check=check_template_email).count(), 1 ) @@ -1244,7 +1244,7 @@ def test_handle_task_alerts( send_email.assert_not_called() send_sms.assert_not_called() - self.assertEquals( + self.assertEqual( Alert.objects.filter(assigned_task=task_template_email).count(), 1 ) diff --git a/api/tacticalrmm/apiv3/tests.py b/api/tacticalrmm/apiv3/tests.py index 7ddc06c0ee..6a430b37fa 100644 --- a/api/tacticalrmm/apiv3/tests.py +++ b/api/tacticalrmm/apiv3/tests.py @@ -62,7 +62,7 @@ def test_get_checks(self): r = self.client.get(url) self.assertEqual(r.status_code, 200) self.assertEqual(r.data["check_interval"], 20) - self.assertEquals(len(r.data["checks"]), 2) + self.assertEqual(len(r.data["checks"]), 2) url = "/api/v3/Maj34ACb324j234asdj2n34kASDjh34-DESKTOPTEST123/checkrunner/" r = self.client.get(url) diff --git a/api/tacticalrmm/automation/tests.py b/api/tacticalrmm/automation/tests.py index a202ccc838..c50adbc57e 100644 --- a/api/tacticalrmm/automation/tests.py +++ b/api/tacticalrmm/automation/tests.py @@ -410,11 +410,11 @@ def test_policy_related(self): ) self.assertEqual(resp.status_code, 200) - self.assertEquals(len(resp.data["server_clients"]), 1) - self.assertEquals(len(resp.data["server_sites"]), 0) - self.assertEquals(len(resp.data["workstation_clients"]), 1) - self.assertEquals(len(resp.data["workstation_sites"]), 0) - self.assertEquals(len(resp.data["agents"]), 0) + self.assertEqual(len(resp.data["server_clients"]), 1) + self.assertEqual(len(resp.data["server_sites"]), 0) + self.assertEqual(len(resp.data["workstation_clients"]), 1) + self.assertEqual(len(resp.data["workstation_sites"]), 0) + self.assertEqual(len(resp.data["agents"]), 0) # Add Site to Policy policy.server_sites.add(server_agents[10].site) @@ -422,9 +422,9 @@ def test_policy_related(self): resp = self.client.get( f"/automation/policies/{policy.pk}/related/", format="json" ) - self.assertEquals(len(resp.data["server_sites"]), 1) - self.assertEquals(len(resp.data["workstation_sites"]), 1) - self.assertEquals(len(resp.data["agents"]), 0) + self.assertEqual(len(resp.data["server_sites"]), 1) + self.assertEqual(len(resp.data["workstation_sites"]), 1) + self.assertEqual(len(resp.data["agents"]), 0) # Add Agent to Policy policy.agents.add(server_agents[2]) @@ -432,7 +432,7 @@ def test_policy_related(self): resp = self.client.get( f"/automation/policies/{policy.pk}/related/", format="json" ) - self.assertEquals(len(resp.data["agents"]), 2) + self.assertEqual(len(resp.data["agents"]), 2) def test_getting_agent_policy_checks(self): @@ -442,7 +442,7 @@ def test_getting_agent_policy_checks(self): agent = baker.make_recipe("agents.agent", policy=policy) # test policy assigned to agent - self.assertEquals(len(agent.get_checks_from_policies()), 7) + self.assertEqual(len(agent.get_checks_from_policies()), 7) def test_getting_agent_policy_checks_with_enforced(self): # setup data diff --git a/api/tacticalrmm/checks/tests.py b/api/tacticalrmm/checks/tests.py index 19a8d22780..e6c3c79cdb 100644 --- a/api/tacticalrmm/checks/tests.py +++ b/api/tacticalrmm/checks/tests.py @@ -842,8 +842,8 @@ def test_handle_eventlog_check(self): check_result = CheckResult.objects.get(assigned_check=check, agent=self.agent) - self.assertEquals(check.alert_severity, "warning") - self.assertEquals(check_result.status, "failing") + self.assertEqual(check.alert_severity, "warning") + self.assertEqual(check_result.status, "failing") # test passing when contains resp = self.client.patch(url, no_logs_data, format="json") @@ -851,7 +851,7 @@ def test_handle_eventlog_check(self): check_result = CheckResult.objects.get(assigned_check=check, agent=self.agent) - self.assertEquals(check_result.status, "passing") + self.assertEqual(check_result.status, "passing") # test failing when not contains and message and source check.fail_when = "not_contains" @@ -863,8 +863,8 @@ def test_handle_eventlog_check(self): check_result = CheckResult.objects.get(assigned_check=check, agent=self.agent) - self.assertEquals(check_result.status, "failing") - self.assertEquals(check.alert_severity, "error") + self.assertEqual(check_result.status, "failing") + self.assertEqual(check.alert_severity, "error") # test passing when contains with source and message resp = self.client.patch(url, data, format="json") @@ -872,7 +872,7 @@ def test_handle_eventlog_check(self): check_result = CheckResult.objects.get(assigned_check=check, agent=self.agent) - self.assertEquals(check_result.status, "passing") + self.assertEqual(check_result.status, "passing") class TestCheckPermissions(TacticalTestCase): diff --git a/api/tacticalrmm/scripts/tests.py b/api/tacticalrmm/scripts/tests.py index 981c2bb544..30063b2a9f 100644 --- a/api/tacticalrmm/scripts/tests.py +++ b/api/tacticalrmm/scripts/tests.py @@ -80,7 +80,7 @@ def test_modify_script(self): resp = self.client.put(url, data, format="json") self.assertEqual(resp.status_code, 200) script = Script.objects.get(pk=script.pk) - self.assertEquals(script.description, "Description Change") + self.assertEqual(script.description, "Description Change") # correct_hash = hmac.new( # settings.SECRET_KEY.encode(), data["script_body"].encode(), hashlib.sha256 @@ -467,7 +467,7 @@ def test_modify_script_snippet(self): resp = self.client.put(url, data, format="json") self.assertEqual(resp.status_code, 200) snippet = ScriptSnippet.objects.get(pk=snippet.pk) - self.assertEquals(snippet.name, "New Name") + self.assertEqual(snippet.name, "New Name") self.check_not_authenticated("put", url) diff --git a/api/tacticalrmm/services/tests.py b/api/tacticalrmm/services/tests.py index 3d1d03a0f0..cfed9d9822 100644 --- a/api/tacticalrmm/services/tests.py +++ b/api/tacticalrmm/services/tests.py @@ -63,7 +63,7 @@ def test_get_services(self, nats_cmd): resp = self.client.get(url, format="json") self.assertEqual(resp.status_code, 200) nats_cmd.assert_called_with(data={"func": "winservices"}, timeout=10) - self.assertEquals(Agent.objects.get(pk=agent.pk).services, nats_return) + self.assertEqual(Agent.objects.get(pk=agent.pk).services, nats_return) self.check_not_authenticated("get", url) @@ -141,7 +141,7 @@ def test_service_detail(self, nats_cmd): nats_cmd.assert_called_with( {"func": "winsvcdetail", "payload": {"name": "alg"}}, timeout=10 ) - self.assertEquals(resp.data, nats_return) + self.assertEqual(resp.data, nats_return) self.check_not_authenticated("get", url) diff --git a/api/tacticalrmm/software/tests.py b/api/tacticalrmm/software/tests.py index d48d614631..5033f23c74 100644 --- a/api/tacticalrmm/software/tests.py +++ b/api/tacticalrmm/software/tests.py @@ -42,7 +42,7 @@ def test_get_installed_software(self): # test without agent software resp = self.client.get(url, format="json") self.assertEqual(resp.status_code, 200) - self.assertEquals(resp.data, []) + self.assertEqual(resp.data, []) # make some software software = baker.make( @@ -60,7 +60,7 @@ def test_get_installed_software(self): serializer = InstalledSoftwareSerializer([software], many=True) resp = self.client.get(f"{base_url}/", format="json") self.assertEqual(resp.status_code, 200) - self.assertEquals(resp.data, serializer.data) + self.assertEqual(resp.data, serializer.data) self.check_not_authenticated("get", url) From 528470c37f81de991ab7ae62965941b414429add Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Mon, 25 Apr 2022 00:17:34 +0000 Subject: [PATCH 11/12] fix slow query --- api/tacticalrmm/agents/views.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/tacticalrmm/agents/views.py b/api/tacticalrmm/agents/views.py index 051cbf37b8..b4975163bd 100644 --- a/api/tacticalrmm/agents/views.py +++ b/api/tacticalrmm/agents/views.py @@ -136,10 +136,10 @@ def get(self, request): else: agents = ( Agent.objects.filter_by_role(request.user) # type: ignore - .select_related("site") + .defer(*AGENT_DEFER) + .select_related("site__client") .filter(monitoring_type_filter) .filter(client_site_filter) - .only("agent_id", "hostname", "site") ) serializer = AgentHostnameSerializer(agents, many=True) From d8dd3e133fa9953406605f349c2474bfe5f2ea90 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Mon, 25 Apr 2022 00:31:14 +0000 Subject: [PATCH 12/12] bump version --- api/tacticalrmm/tacticalrmm/settings.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/tacticalrmm/tacticalrmm/settings.py b/api/tacticalrmm/tacticalrmm/settings.py index 3a0adb136c..6ddc8e7fbe 100644 --- a/api/tacticalrmm/tacticalrmm/settings.py +++ b/api/tacticalrmm/tacticalrmm/settings.py @@ -17,11 +17,11 @@ AUTH_USER_MODEL = "accounts.User" # latest release -TRMM_VERSION = "0.13.1" +TRMM_VERSION = "0.13.2" # bump this version everytime vue code is changed # to alert user they need to manually refresh their browser -APP_VER = "0.0.162" +APP_VER = "0.0.163" # https://github.com/amidaware/rmmagent LATEST_AGENT_VER = "2.0.3"