From f0c2bdc2833b1857d36b8bd299558816779c386f Mon Sep 17 00:00:00 2001 From: rever-tecnologia Date: Thu, 18 Dec 2025 08:04:43 -0300 Subject: [PATCH] feat(agent): adiciona captura de bateria, sensores termicos, rede e monitores MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Captura info de bateria (Win32_Battery) com status traduzido - Captura sensores termicos via WMI ThermalZone e OpenHardwareMonitor - Captura adaptadores de rede fisicos com status de conexao - Captura monitores conectados (fabricante, serial, modelo) - Captura info de chassis/gabinete com tipo traduzido 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- apps/desktop/src-tauri/src/agent.rs | 133 ++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) diff --git a/apps/desktop/src-tauri/src/agent.rs b/apps/desktop/src-tauri/src/agent.rs index d6d944f..a49292b 100644 --- a/apps/desktop/src-tauri/src/agent.rs +++ b/apps/desktop/src-tauri/src/agent.rs @@ -971,6 +971,134 @@ fn collect_windows_extended() -> serde_json::Value { "#).unwrap_or_else(|| json!([])); let disks = ps("@(Get-CimInstance Win32_DiskDrive | Select-Object Model,SerialNumber,Size,InterfaceType,MediaType)").unwrap_or_else(|| json!([])); + // Bateria (notebooks/laptops) + let battery = ps(r#" + $batteries = @(Get-CimInstance Win32_Battery | Select-Object Name,DeviceID,Status,BatteryStatus,EstimatedChargeRemaining,EstimatedRunTime,DesignCapacity,FullChargeCapacity,DesignVoltage,Chemistry,BatteryRechargeTime) + if ($batteries.Count -eq 0) { + [PSCustomObject]@{ Present = $false; Batteries = @() } + } else { + # Mapeia status numérico para texto + $statusMap = @{ + 1 = 'Discharging' + 2 = 'AC Power' + 3 = 'Fully Charged' + 4 = 'Low' + 5 = 'Critical' + 6 = 'Charging' + 7 = 'Charging High' + 8 = 'Charging Low' + 9 = 'Charging Critical' + 10 = 'Undefined' + 11 = 'Partially Charged' + } + foreach ($b in $batteries) { + if ($b.BatteryStatus) { + $b | Add-Member -NotePropertyName 'BatteryStatusText' -NotePropertyValue ($statusMap[[int]$b.BatteryStatus] ?? 'Unknown') -Force + } + } + [PSCustomObject]@{ Present = $true; Batteries = $batteries } + } + "#).unwrap_or_else(|| json!({ "Present": false, "Batteries": [] })); + + // Sensores térmicos (temperatura CPU/GPU quando disponível) + let thermal = ps(r#" + $temps = @() + # Tenta WMI thermal zone (requer admin em alguns sistemas) + try { + $zones = Get-CimInstance -Namespace 'root/WMI' -ClassName MSAcpi_ThermalZoneTemperature -ErrorAction SilentlyContinue + foreach ($z in $zones) { + if ($z.CurrentTemperature) { + $celsius = [math]::Round(($z.CurrentTemperature - 2732) / 10, 1) + $temps += [PSCustomObject]@{ + Source = 'ThermalZone' + Name = $z.InstanceName + TemperatureCelsius = $celsius + CriticalTripPoint = if ($z.CriticalTripPoint) { [math]::Round(($z.CriticalTripPoint - 2732) / 10, 1) } else { $null } + } + } + } + } catch {} + # CPU temp via Open Hardware Monitor WMI (se instalado) + try { + $ohm = Get-CimInstance -Namespace 'root/OpenHardwareMonitor' -ClassName Sensor -ErrorAction SilentlyContinue | Where-Object { $_.SensorType -eq 'Temperature' } + foreach ($s in $ohm) { + $temps += [PSCustomObject]@{ + Source = 'OpenHardwareMonitor' + Name = $s.Name + TemperatureCelsius = $s.Value + Parent = $s.Parent + } + } + } catch {} + @($temps) + "#).unwrap_or_else(|| json!([])); + + // Adaptadores de rede (físicos e virtuais) + let network_adapters = ps(r#" + @(Get-CimInstance Win32_NetworkAdapter | Where-Object { $_.PhysicalAdapter -eq $true -or $_.NetConnectionStatus -ne $null } | Select-Object Name,Description,MACAddress,Speed,NetConnectionStatus,AdapterType,Manufacturer,NetConnectionID,PNPDeviceID | ForEach-Object { + $statusMap = @{ + 0 = 'Disconnected' + 1 = 'Connecting' + 2 = 'Connected' + 3 = 'Disconnecting' + 4 = 'Hardware not present' + 5 = 'Hardware disabled' + 6 = 'Hardware malfunction' + 7 = 'Media disconnected' + 8 = 'Authenticating' + 9 = 'Authentication succeeded' + 10 = 'Authentication failed' + 11 = 'Invalid address' + 12 = 'Credentials required' + } + $_ | Add-Member -NotePropertyName 'StatusText' -NotePropertyValue ($statusMap[[int]$_.NetConnectionStatus] ?? 'Unknown') -Force + $_ + }) + "#).unwrap_or_else(|| json!([])); + + // Monitores conectados + let monitors = ps(r#" + @(Get-CimInstance WmiMonitorID -Namespace root/wmi -ErrorAction SilentlyContinue | ForEach-Object { + $decode = { param($arr) if ($arr) { -join ($arr | Where-Object { $_ -ne 0 } | ForEach-Object { [char]$_ }) } else { $null } } + [PSCustomObject]@{ + ManufacturerName = & $decode $_.ManufacturerName + ProductCodeID = & $decode $_.ProductCodeID + SerialNumberID = & $decode $_.SerialNumberID + UserFriendlyName = & $decode $_.UserFriendlyName + YearOfManufacture = $_.YearOfManufacture + WeekOfManufacture = $_.WeekOfManufacture + } + }) + "#).unwrap_or_else(|| json!([])); + + // Fonte de alimentação / chassis + let power_supply = ps(r#" + $chassis = Get-CimInstance Win32_SystemEnclosure | Select-Object ChassisTypes,Manufacturer,SerialNumber,SMBIOSAssetTag + $chassisTypeMap = @{ + 1 = 'Other'; 2 = 'Unknown'; 3 = 'Desktop'; 4 = 'Low Profile Desktop' + 5 = 'Pizza Box'; 6 = 'Mini Tower'; 7 = 'Tower'; 8 = 'Portable' + 9 = 'Laptop'; 10 = 'Notebook'; 11 = 'Hand Held'; 12 = 'Docking Station' + 13 = 'All in One'; 14 = 'Sub Notebook'; 15 = 'Space-Saving'; 16 = 'Lunch Box' + 17 = 'Main Server Chassis'; 18 = 'Expansion Chassis'; 19 = 'SubChassis' + 20 = 'Bus Expansion Chassis'; 21 = 'Peripheral Chassis'; 22 = 'RAID Chassis' + 23 = 'Rack Mount Chassis'; 24 = 'Sealed-case PC'; 25 = 'Multi-system chassis' + 30 = 'Tablet'; 31 = 'Convertible'; 32 = 'Detachable' + } + $types = @() + if ($chassis.ChassisTypes) { + foreach ($t in $chassis.ChassisTypes) { + $types += $chassisTypeMap[[int]$t] ?? "Type$t" + } + } + [PSCustomObject]@{ + ChassisTypes = $chassis.ChassisTypes + ChassisTypesText = $types + Manufacturer = $chassis.Manufacturer + SerialNumber = $chassis.SerialNumber + SMBIOSAssetTag = $chassis.SMBIOSAssetTag + } + "#).unwrap_or_else(|| json!({})); + json!({ "windows": { "software": software, @@ -992,6 +1120,11 @@ fn collect_windows_extended() -> serde_json::Value { "windowsUpdate": windows_update, "computerSystem": computer_system, "azureAdStatus": device_join, + "battery": battery, + "thermal": thermal, + "networkAdapters": network_adapters, + "monitors": monitors, + "chassis": power_supply, } }) }