From 00f6eff10a74ad7c41076115ac0a2ba6548723a6 Mon Sep 17 00:00:00 2001 From: wh1te909 Date: Sun, 23 Feb 2020 11:17:57 +0000 Subject: [PATCH] start adding hardware info and summary tab --- _modules/system_info.py | 47 ++++++ .../migrations/0003_agent_wmi_detail.py | 19 +++ api/tacticalrmm/agents/models.py | 1 + api/tacticalrmm/agents/serializers.py | 1 + api/tacticalrmm/agents/tasks.py | 12 ++ api/tacticalrmm/api/views.py | 15 +- web/src/components/SubTableTabs.vue | 8 +- web/src/components/SummaryTab.vue | 145 ++++++++++++++++-- 8 files changed, 222 insertions(+), 26 deletions(-) create mode 100644 _modules/system_info.py create mode 100644 api/tacticalrmm/agents/migrations/0003_agent_wmi_detail.py diff --git a/_modules/system_info.py b/_modules/system_info.py new file mode 100644 index 00000000..753d3bec --- /dev/null +++ b/_modules/system_info.py @@ -0,0 +1,47 @@ +from __future__ import absolute_import +import wmi + + +class SystemDetail: + def __init__(self): + self.c = wmi.WMI() + self.make_model = self.c.Win32_ComputerSystemProduct() + self.memory = self.c.Win32_PhysicalMemory() + self.os = self.c.Win32_OperatingSystem() + self.base_board = self.c.Win32_BaseBoard() + self.bios = self.c.Win32_BIOS() + self.disk = self.c.Win32_DiskDrive() + self.network_adapter = self.c.Win32_NetworkAdapter() + self.network_config = self.c.Win32_NetworkAdapterConfiguration() + self.desktop_monitor = self.c.Win32_DesktopMonitor() + self.cpu = self.c.Win32_Processor() + self.usb = self.c.Win32_USBController() + + def get_all(self, obj): + ret = [] + for i in obj: + tmp = [ + {j: getattr(i, j)} + for j in list(i.properties) + if getattr(i, j) is not None + ] + ret.append(tmp) + + return ret + + +def system_info(): + info = SystemDetail() + return { + "make_model": info.get_all(info.make_model), + "mem": info.get_all(info.memory), + "os": info.get_all(info.os), + "base_board": info.get_all(info.base_board), + "bios": info.get_all(info.bios), + "disk": info.get_all(info.disk), + "network_adapter": info.get_all(info.network_adapter), + "network_config": info.get_all(info.network_config), + "desktop_monitor": info.get_all(info.desktop_monitor), + "cpu": info.get_all(info.cpu), + "usb": info.get_all(info.usb), + } diff --git a/api/tacticalrmm/agents/migrations/0003_agent_wmi_detail.py b/api/tacticalrmm/agents/migrations/0003_agent_wmi_detail.py new file mode 100644 index 00000000..95f30d06 --- /dev/null +++ b/api/tacticalrmm/agents/migrations/0003_agent_wmi_detail.py @@ -0,0 +1,19 @@ +# Generated by Django 3.0.3 on 2020-02-23 07:23 + +import django.contrib.postgres.fields.jsonb +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('agents', '0002_auto_20200206_0554'), + ] + + operations = [ + migrations.AddField( + model_name='agent', + name='wmi_detail', + field=django.contrib.postgres.fields.jsonb.JSONField(null=True), + ), + ] diff --git a/api/tacticalrmm/agents/models.py b/api/tacticalrmm/agents/models.py index 83f56f0a..efd205a0 100644 --- a/api/tacticalrmm/agents/models.py +++ b/api/tacticalrmm/agents/models.py @@ -50,6 +50,7 @@ class Agent(models.Model): managed_by_wsus = models.BooleanField(default=False) is_updating = models.BooleanField(default=False) choco_installed = models.BooleanField(default=False) + wmi_detail = JSONField(null=True) def __str__(self): return self.hostname diff --git a/api/tacticalrmm/agents/serializers.py b/api/tacticalrmm/agents/serializers.py index b5377ba4..a9499f34 100644 --- a/api/tacticalrmm/agents/serializers.py +++ b/api/tacticalrmm/agents/serializers.py @@ -52,6 +52,7 @@ class AgentSerializer(serializers.ModelSerializer): "winupdatepolicy", "salt_id", "choco_installed", + "wmi_detail", ) diff --git a/api/tacticalrmm/agents/tasks.py b/api/tacticalrmm/agents/tasks.py index 05b08aaf..2df164a2 100644 --- a/api/tacticalrmm/agents/tasks.py +++ b/api/tacticalrmm/agents/tasks.py @@ -11,6 +11,18 @@ from agents.models import Agent logger.configure(**settings.LOG_CONFIG) +@app.task +def get_wmi_detail_task(pk): + sleep(30) + agent = Agent.objects.get(pk=pk) + resp = agent.salt_api_cmd( + hostname=agent.salt_id, timeout=30, func="system_info.system_info" + ) + agent.wmi_detail = resp.json()["return"][0][agent.salt_id] + agent.save(update_fields=["wmi_detail"]) + return "ok" + + @app.task def sync_salt_modules_task(pk): agent = Agent.objects.get(pk=pk) diff --git a/api/tacticalrmm/api/views.py b/api/tacticalrmm/api/views.py index 402e6e06..cc25c1c2 100644 --- a/api/tacticalrmm/api/views.py +++ b/api/tacticalrmm/api/views.py @@ -38,7 +38,11 @@ from checks.models import ( CpuHistory, ) from winupdate.models import WinUpdate, WinUpdatePolicy -from agents.tasks import uninstall_agent_task, sync_salt_modules_task +from agents.tasks import ( + uninstall_agent_task, + sync_salt_modules_task, + get_wmi_detail_task, +) from winupdate.tasks import check_for_updates_task from agents.serializers import AgentHostnameSerializer from software.tasks import install_chocolatey, get_installed_software @@ -168,6 +172,7 @@ def get_mesh_exe(request): response["X-Accel-Redirect"] = "/protected/meshagent.exe" return response + @api_view(["POST"]) @authentication_classes((BasicAuthentication,)) @permission_classes((IsAuthenticated,)) @@ -229,10 +234,8 @@ def accept_salt_key(request): return Response("accepted") else: return Response(status=status.HTTP_400_BAD_REQUEST) - + return Response(status=status.HTTP_400_BAD_REQUEST) - - @api_view(["POST"]) @@ -306,7 +309,7 @@ def add(request): WinUpdatePolicy(agent=agent, run_time_days=[5, 6]).save() else: WinUpdatePolicy(agent=agent).save() - + return Response({"pk": agent.pk}) else: return Response("err", status=status.HTTP_400_BAD_REQUEST) @@ -354,6 +357,7 @@ def update(request): sync_salt_modules_task.delay(agent.pk) get_installed_software.delay(agent.pk) + get_wmi_detail_task.delay(agent.pk) if not agent.choco_installed: install_chocolatey.delay(agent.pk, wait=True) @@ -442,4 +446,3 @@ def hello(request): cpu.save(update_fields=["cpu_history"]) return Response("ok") - diff --git a/web/src/components/SubTableTabs.vue b/web/src/components/SubTableTabs.vue index 505c639b..0a76fac5 100644 --- a/web/src/components/SubTableTabs.vue +++ b/web/src/components/SubTableTabs.vue @@ -11,10 +11,10 @@ narrow-indicator no-caps > - - - - + + + + diff --git a/web/src/components/SummaryTab.vue b/web/src/components/SummaryTab.vue index 0ebf2f57..de41947b 100644 --- a/web/src/components/SummaryTab.vue +++ b/web/src/components/SummaryTab.vue @@ -1,26 +1,139 @@