Skip to content

feat(device): collect static machine resource info#68

Open
swarit-stepsecurity wants to merge 1 commit intostep-security:mainfrom
swarit-stepsecurity:swarit/feat/wt/machine-resource-info
Open

feat(device): collect static machine resource info#68
swarit-stepsecurity wants to merge 1 commit intostep-security:mainfrom
swarit-stepsecurity:swarit/feat/wt/machine-resource-info

Conversation

@swarit-stepsecurity
Copy link
Copy Markdown
Member

Summary

Adds CPU model / physical+logical cores / architecture, total RAM, and root volume capacity to the device snapshot reported on every scan. High-signal answer to "how much resource does this machine have" — no volatile fields (free RAM, per-process load) that would muddy a static snapshot.

DEVICE
  Hostname    EC2AMAZ-HJS7CVB
  Serial      ec241363-fe37-f981-a408-72c4cfdf51c7
  Windows     10.0.26100
  User        EC2AMAZ-HJS7CVB\Administrator
  CPU         Intel(R) Xeon(R) Platinum 8175M CPU @ 2.50GHz (1c / 2t, amd64)
  Memory      7 GB
  Disk        99 GB

Implementation

  • New model.MachineResources struct embedded as Device.Resources — single nested key, additive change.
  • internal/device/resources.{go,_other.go,_windows.go} follow the existing platform-split convention in this package.
    • Linux: /proc/cpuinfo + /proc/meminfo (no subprocess). Graceful ARM degradation — falls back to Hardware/Model lines and reports physical_cores: 0 rather than misreporting.
    • macOS: sysctl machdep.cpu.brand_string, hw.physicalcpu, hw.logicalcpu, hw.memsize.
    • Windows: native Win32 APIs (registry ProcessorNameString, GetLogicalProcessorInformation, GlobalMemoryStatusEx, GetDiskFreeSpaceEx) with PowerShell Get-CimInstance as the only fallback. wmic is no longer available on Win11 / Server 2025 and was deliberately not used.
  • Disk capacity goes through a new Executor.DiskCapacityBytes(path) uint64 method (syscall.Statfs on unix, GetDiskFreeSpaceEx on windows) so it stays mockable like every other OS interaction.
  • Surfaced in pretty + HTML output and added to the enterprise telemetry Payload.
  • Tests cover parsers (x86, ARM, multi-socket, malformed), all three OS code paths via SetGOOS, and missing-file degradation.

Test plan

  • go test ./... — full suite green
  • go vet ./... clean
  • Cross-compile verified for darwin/amd64+arm64, linux/amd64+arm64, windows/amd64
  • macOS host (M4 Pro MBP): numbers match local hardware
  • Linux (Fedora 42 EC2 t3.xlarge): matches nproc (4), free -h (15Gi), df -h / (29G)
  • Windows (Server 2025 EC2 t3.large): matches Get-CimInstance Win32_Processor (1c/2t Xeon 8175M) and Win32_ComputerSystem (8.36 GB / 99.5 GB)

Adds CPU model / physical+logical cores / architecture, total RAM, and
root volume capacity to the device snapshot reported on every scan.
Answers "how much resource does this machine have" without including
volatile signals like free memory or per-process load.

Linux reads /proc/cpuinfo and /proc/meminfo (no subprocess); macOS uses
sysctl; Windows uses native Win32 APIs (registry CPU name,
GetLogicalProcessorInformation, GlobalMemoryStatusEx, GetDiskFreeSpaceEx)
with PowerShell Get-CimInstance as fallback — wmic is unavailable on
Win11 / Server 2025. Disk capacity routes through a new
Executor.DiskCapacityBytes method so it stays mockable like everything
else.

Surfaced in pretty + HTML output and the enterprise telemetry payload.
Verified end-to-end against ground truth on macOS, Fedora 42 EC2, and
Server 2025 EC2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant