diff --git a/api/tacticalrmm/agents/tests.py b/api/tacticalrmm/agents/tests.py index 504a9dbd..562378f5 100644 --- a/api/tacticalrmm/agents/tests.py +++ b/api/tacticalrmm/agents/tests.py @@ -843,7 +843,7 @@ class TestAgentViewsNew(TacticalTestCase): self.authenticate() self.setup_coresettings() - def test_agent_counts(self): + """ def test_agent_counts(self): url = "/agents/agent_counts/" # create some data @@ -870,7 +870,7 @@ class TestAgentViewsNew(TacticalTestCase): self.assertEqual(r.status_code, 200) self.assertEqual(r.data, data) # type: ignore - self.check_not_authenticated("post", url) + self.check_not_authenticated("post", url) """ def test_agent_maintenance_mode(self): url = "/agents/maintenance/" diff --git a/api/tacticalrmm/agents/urls.py b/api/tacticalrmm/agents/urls.py index d4d488ff..c1d0fa44 100644 --- a/api/tacticalrmm/agents/urls.py +++ b/api/tacticalrmm/agents/urls.py @@ -27,7 +27,6 @@ urlpatterns = [ path("/notes/", views.GetAddNotes.as_view()), path("/note/", views.GetEditDeleteNote.as_view()), path("bulk/", views.bulk), - path("agent_counts/", views.agent_counts), path("maintenance/", views.agent_maintenance), path("/wmi/", views.WMI.as_view()), ] diff --git a/api/tacticalrmm/agents/views.py b/api/tacticalrmm/agents/views.py index 6a224948..eea65a0e 100644 --- a/api/tacticalrmm/agents/views.py +++ b/api/tacticalrmm/agents/views.py @@ -671,49 +671,6 @@ def bulk(request): return notify_error("Something went wrong") -@api_view(["POST"]) -def agent_counts(request): - - server_offline_count = len( - [ - agent - for agent in Agent.objects.filter(monitoring_type="server").only( - "pk", - "last_seen", - "overdue_time", - "offline_time", - ) - if not agent.status == "online" - ] - ) - - workstation_offline_count = len( - [ - agent - for agent in Agent.objects.filter(monitoring_type="workstation").only( - "pk", - "last_seen", - "overdue_time", - "offline_time", - ) - if not agent.status == "online" - ] - ) - - return Response( - { - "total_server_count": Agent.objects.filter( - monitoring_type="server" - ).count(), - "total_server_offline_count": server_offline_count, - "total_workstation_count": Agent.objects.filter( - monitoring_type="workstation" - ).count(), - "total_workstation_offline_count": workstation_offline_count, - } - ) - - @api_view(["POST"]) def agent_maintenance(request): if request.data["type"] == "Client": diff --git a/api/tacticalrmm/core/consumers.py b/api/tacticalrmm/core/consumers.py index 99768b34..925a62fa 100644 --- a/api/tacticalrmm/core/consumers.py +++ b/api/tacticalrmm/core/consumers.py @@ -9,7 +9,7 @@ from agents.models import Agent from accounts.models import User -class NetTop(AsyncWebsocketConsumer): +class DashInfo(AsyncWebsocketConsumer): async def connect(self): self.user = self.scope["user"] @@ -19,12 +19,12 @@ class NetTop(AsyncWebsocketConsumer): await self.accept() self.connected = True - self.net = asyncio.create_task(self.send_net_top()) + self.dash_info = asyncio.create_task(self.send_dash_info()) async def disconnect(self, close_code): try: - self.net.cancel() + self.dash_info.cancel() except: pass @@ -82,7 +82,7 @@ class NetTop(AsyncWebsocketConsumer): } return json.dumps(ret) - async def send_net_top(self): + async def send_dash_info(self): while self.connected: c = await self.get_dashboard_info() await self.send(c) diff --git a/api/tacticalrmm/tacticalrmm/urls.py b/api/tacticalrmm/tacticalrmm/urls.py index 3bfd9251..034127c5 100644 --- a/api/tacticalrmm/tacticalrmm/urls.py +++ b/api/tacticalrmm/tacticalrmm/urls.py @@ -32,5 +32,5 @@ if hasattr(settings, "ADMIN_ENABLED") and settings.ADMIN_ENABLED: urlpatterns += (path(settings.ADMIN_URL, admin.site.urls),) ws_urlpatterns = [ - path("ws/nettop/", consumers.NetTop.as_asgi()), # type: ignore + path("ws/dashinfo/", consumers.DashInfo.as_asgi()), # type: ignore ] diff --git a/web/src/store/index.js b/web/src/store/index.js index 1556c087..6b354a37 100644 --- a/web/src/store/index.js +++ b/web/src/store/index.js @@ -154,9 +154,6 @@ export default function () { toggleMaintenanceMode(context, data) { return axios.post("/agents/maintenance/", data) }, - /* getAgentCounts(context, data = {}) { - return axios.post("/agents/agent_counts/", data) - }, */ getDashInfo(context) { return axios.get("/core/dashinfo/"); }, diff --git a/web/src/views/Dashboard.vue b/web/src/views/Dashboard.vue index 1cd30c6a..a4680789 100644 --- a/web/src/views/Dashboard.vue +++ b/web/src/views/Dashboard.vue @@ -540,7 +540,7 @@ export default { methods: { setupWS() { console.log("Starting websocket"); - this.ws = new WebSocket(`ws://${this.wsUrl}/ws/nettop/?access_token=${this.token}`); + this.ws = new WebSocket(`ws://${this.wsUrl}/ws/dashinfo/?access_token=${this.token}`); this.ws.onopen = e => { console.log("Connected to ws"); }; @@ -550,9 +550,6 @@ export default { this.$q.dark.set(this.darkMode); this.currentTRMMVersion = data.trmm_version; this.serverCount = data.total_server_count; - this.$store.commit("SET_AGENT_DBLCLICK_ACTION", data.dbl_click_action); - this.$store.commit("SET_DEFAULT_AGENT_TBL_TAB", data.default_agent_tbl_tab); - this.$store.commit("SET_CLIENT_TREE_SORT", data.client_tree_sort); this.serverOfflineCount = data.total_server_offline_count; this.workstationCount = data.total_workstation_count; this.workstationOfflineCount = data.total_workstation_offline_count; @@ -562,7 +559,7 @@ export default { if (e.code !== 1000) { setTimeout(() => { this.setupWS(); - }, 5 * 1000); + }, 2 * 1000); } }; this.ws.onerror = err => { @@ -577,7 +574,6 @@ export default { refreshEntireSite() { this.$store.dispatch("loadTree"); this.getDashInfo(false); - //this.getAgentCounts(); if (this.allClientsActive) { this.loadAllClients(); @@ -709,30 +705,21 @@ export default { livePoll() { this.poll = setInterval(() => { this.$store.dispatch("checkVer"); - //this.getAgentCounts(); this.getDashInfo(false); }, 60 * 5 * 1000); }, setSplitter(val) { this.$store.commit("SET_SPLITTER", val); }, - /* getAgentCounts(selected) { - this.$store.dispatch("getAgentCounts").then(r => { - this.serverCount = r.data.total_server_count; - this.serverOfflineCount = r.data.total_server_offline_count; - this.workstationCount = r.data.total_workstation_count; - this.workstationOfflineCount = r.data.total_workstation_offline_count; - }); - }, */ getDashInfo(edited = true) { this.$store.dispatch("getDashInfo").then(r => { - /* if (edited) { + if (edited) { this.$store.commit("SET_DEFAULT_AGENT_TBL_TAB", r.data.default_agent_tbl_tab); this.$store.commit("SET_CLIENT_TREE_SORT", r.data.client_tree_sort); - } */ - //this.darkMode = r.data.dark_mode; - //this.$q.dark.set(this.darkMode); - //this.$store.commit("SET_AGENT_DBLCLICK_ACTION", r.data.dbl_click_action); + } + this.darkMode = r.data.dark_mode; + this.$q.dark.set(this.darkMode); + this.$store.commit("SET_AGENT_DBLCLICK_ACTION", r.data.dbl_click_action); this.$store.commit("setShowCommunityScripts", r.data.show_community_scripts); }); }, @@ -865,7 +852,6 @@ export default { this.getDashInfo(); this.$store.dispatch("getUpdatedSites"); this.$store.dispatch("checkVer"); - //this.getAgentCounts(); this.getTree(); }, mounted() {