Skip to content

feat(win32): add network port statistics#1184

Open
eduardomozart wants to merge 8 commits into
glpi-project:developfrom
eduardomozart:feat-netadapter-invent-stats
Open

feat(win32): add network port statistics#1184
eduardomozart wants to merge 8 commits into
glpi-project:developfrom
eduardomozart:feat-netadapter-invent-stats

Conversation

@eduardomozart

@eduardomozart eduardomozart commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Description

This PR introduces network port statistics collection for the Windows inventory agent, generating a new NETWORK_PORTS section in the payload. It extracts network interface traffic metrics and index data to allow accurate tracking, correlation, and monitoring of network performance.

image

Warning

Important Note on Inventory Format & GLPI Compatibility
This PR modifies the inventory format in GLPI::Agent::Inventory by introducing the NETWORK_PORTS section for non-NetworkEquipment assets (such as Computers).

Note

Test Dependencies
For the tests in this PR to pass successfully, it requires $interface->{DESCRIPTION} to match the Windows connection name proposed in PR glpi-project/glpi-agent#1176.

Key Changes

  • New NETWORK_PORTS Inventory Section: Added support to collect and report NAME, MAC, IFNUMBER, IFINOCTETS, IFOUTOCTETS, IFINERRORS, and IFOUTERRORS.
  • Modern API with Legacy Fallback:
    • Prioritizes querying MSFT_NetAdapterStatisticsSettingData via StandardCimv2 for modern performance stats.
    • Implements a fallback to Win32_PerfRawData_Tcpip_NetworkInterface for older systems, ensuring broad compatibility without overwriting modern stats.
  • Interface Index Tracking: The NetAdapter now exposes _IFNUMBER, allowing the inventory to correctly correlate interface statistics.
  • Data Deduplication & Standardization: Deduplicates network ports by MAC and description (resolving issues with interfaces holding multiple IPs). Standardized all inventory keys to uppercase and formalized the section name to NETWORK_PORTS.
  • Testing & WMI Fixtures: Added new unit tests (t/tasks/inventory/windows/network_ports.t) and WMI resource fixtures (including Broadcom/load-balance adapter cases) to validate correct data extraction.

Collect and include network interface counters in Windows inventory. The Networks task now queries MSFT_NetAdapterStatisticsSettingData (via StandardCimv2) and falls back to Win32_PerfRawData_Tcpip_NetworkInterface when needed, mapping WMI fields to ifinoctets/ifoutoctets/ifinerrors/ifouterrors. Inventory entries for NETWORKPORTS are added (with deduplication by MAC+description) and include MTU and speed. Also adds WMI resource files and a unit test (t/tasks/inventory/windows/network_ports.t) to validate expected counters.
Introduce a NETWORKPORTS section to the inventory (fields: NAME, MAC, IFINOCTETS, IFOUTOCTETS, IFINERRORS, IFOUTERRORS) and include it in the "network" category mapping. Stop collecting ifmtu and ifspeed in the Win32 network inventory output (only keep statistics like ifinoctets/ifoutoctets/ifinerrors/ifouterrors). Update the corresponding unit test fixtures to remove the ifmtu and ifspeed expectations.
Switch network port hash keys from lowercase to uppercase (name->NAME, mac->MAC, ifinoctets->IFINOCTETS, ifoutoctets->IFOUTOCTETS, ifinerrors->IFINERRORS, ifouterrors->IFOUTERRORS) to match the expected inventory field names. Updated the implementation in lib/GLPI/Agent/Task/Inventory/Win32/Networks.pm and adjusted the test data in t/tasks/inventory/windows/network_ports.t accordingly.
Query MSFT_NetAdapterStatisticsSettingData first and populate statistics from it; then query Win32_PerfRawData_Tcpip_NetworkInterface as a legacy fallback but do not overwrite modern stats. Add per-model counting and a generated lookup_name (with " _N" suffix) so adapters of the same model can be mapped 1:1 to legacy entries. Update lookup logic to use DESCRIPTION or the generated lookup_name and keep a seen_key to avoid duplicating NETWORKPORTS for interfaces with multiple IPs. Add Broadcom WMI fixtures and remove the old 7-Win32_PerfRawData_Tcpip_NetworkInterface fixture; update the network_ports test expectations (rename test key to "broadcom" and adjust expected entries).
Standardize the inventory section name by renaming NETWORKPORTS to NETWORK_PORTS. Updated %fields and %categoryMap in lib/GLPI/Agent/Inventory.pm, changed the emitted section in Win32 network inventory task, and adjusted the unit test to expect NETWORK_PORTS. This is a naming change only and preserves existing inventory data structure semantics.
Include interface index (IFNUMBER) for network ports to correctly correlate interface statistics. NetAdapter now exposes _IFNUMBER from _getObjectIndex(), Inventory collects IFNUMBER into NETWORK_PORTS and removes the temporary field after use. Tests updated to expect IFNUMBER values. Also cleanup/rename of several Win32 WMI resource files related to Broadcom/loadbalance adapters.
Wrap WMI statistics collection and NETWORK_PORTS insertion behind a GLPI version check (inventory->{_glpi_version} >= glpiVersion('12')). Move the $inventory assignment earlier so the version is available during stats collection. Use modern MSFT_NetAdapterStatisticsSettingData when available and fall back to Win32_PerfRawData_Tcpip_NetworkInterface for adapters that only appear there. Ensure NETWORK_PORTS entries are only added for GLPI 12+, and update the unit test mock to set _glpi_version (12_000_000) accordingly.
@eduardomozart

Copy link
Copy Markdown
Contributor Author

Hello @g-bougard, on PR #24508, Trasher said he will wait for this to be committed before analyzing GLPI side code changes.

@g-bougard

Copy link
Copy Markdown
Member

I'll take an eye on it after next release.

Anyway, any format update will also require a dedicated inventory_format spec project PR.

@eduardomozart

Copy link
Copy Markdown
Contributor Author

This PR does not require modification to the inventory_schema; it uses the existing network_ports entry used by NetworkEquipment device classes ported to Computer assets.

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.

2 participants