feat(win32): add network port statistics#1184
Open
eduardomozart wants to merge 8 commits into
Open
Conversation
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.
This was referenced Jun 8, 2026
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.
Contributor
Author
|
Hello @g-bougard, on PR #24508, Trasher said he will wait for this to be committed before analyzing GLPI side code changes. |
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. |
Contributor
Author
|
This PR does not require modification to the inventory_schema; it uses the existing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR introduces network port statistics collection for the Windows inventory agent, generating a new
NETWORK_PORTSsection in the payload. It extracts network interface traffic metrics and index data to allow accurate tracking, correlation, and monitoring of network performance.Warning
Important Note on Inventory Format & GLPI Compatibility
This PR modifies the inventory format in
GLPI::Agent::Inventoryby introducing theNETWORK_PORTSsection for non-NetworkEquipment assets (such as Computers).logical_numberfor computer assets glpi#24508.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
NETWORK_PORTSInventory Section: Added support to collect and reportNAME,MAC,IFNUMBER,IFINOCTETS,IFOUTOCTETS,IFINERRORS, andIFOUTERRORS.MSFT_NetAdapterStatisticsSettingDataviaStandardCimv2for modern performance stats.Win32_PerfRawData_Tcpip_NetworkInterfacefor older systems, ensuring broad compatibility without overwriting modern stats._IFNUMBER, allowing the inventory to correctly correlate interface statistics.NETWORK_PORTS.t/tasks/inventory/windows/network_ports.t) and WMI resource fixtures (including Broadcom/load-balance adapter cases) to validate correct data extraction.