Skip to content

feat(win32): collect network adapter description, manufacturer, model, mtu, virtualdev and link status from WMI#1176

Open
eduardomozart wants to merge 33 commits into
glpi-project:developfrom
eduardomozart:fix-netadapter-invent
Open

feat(win32): collect network adapter description, manufacturer, model, mtu, virtualdev and link status from WMI#1176
eduardomozart wants to merge 33 commits into
glpi-project:developfrom
eduardomozart:fix-netadapter-invent

Conversation

@eduardomozart

@eduardomozart eduardomozart commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Summary

On Windows, the hardware inventory for network cards was only showing the MAC address in GLPI's component list, without any network card name. This happened because the MANUFACTURER and MODEL fields were never populated for the NETWORKS section.

Additionally, GLPI users expect the network adapter DESCRIPTION field to display the Windows connection name (e.g., "Ethernet" or "Wi-Fi" from ncpa.cpl). This provides parity with Unix systems, where this field typically holds the logical interface name (like eth0 or wlan0).

Finally, setups using NIC Teaming or LoadBalance multiplexors had two major reporting inaccuracies:

  1. Physical network adapters belonging to the team were incorrectly reported with a STATUS of "Down" even when physically connected, because the agent relied on IP address assignment to determine link status.
  2. The virtual teamed adapter (e.g., "LoadBalance") was erroneously reported as a physical hardware device (virtualdev: false).

Root Cause

  1. The getInterfaces() function in Tools/Win32.pm queried MSFT_NetAdapter (Win8+) and Win32_NetworkAdapter (legacy) but did not request the driver/manufacturer, connection name, physical connection state, hardware MTU, or virtual status properties.
  2. NetAdapter.pm had no data to populate MANUFACTURER and MODEL in the base interface, and passed the raw hardware description to the DESCRIPTION field instead of the connection name (e.g., "Ethernet" or "Wi-Fi" from ncpa.cpl).
  3. NetAdapter.pm historically derived the STATUS of an interface by checking IPEnabled in Win32_NetworkAdapterConfiguration. In LoadBalance scenarios, the underlying physical NICs do not have IP addresses directly assigned, causing them to falsely report as "Down".
  4. The _isVirtual() method relied on string matching (e.g., ROOT\ or "RAS Adapter") to identify virtual interfaces, completely missing modern software-defined network adapters like the COMPOSITEBUS multiplexor used in LoadBalancing.
  5. The agent relied solely on Win32_NetworkAdapterConfiguration for MTU, which is often empty or unreliable on modern Windows environments unless explicitly set in the registry.

Changes

lib/GLPI/Agent/Tools/Win32.pm

  • Added DriverProvider, DriverDescription, Name, MediaConnectState, Virtual, and MtuSize to the MSFT_NetAdapter WMI query (Windows 8 and above).
  • Added Manufacturer, Name, NetConnectionID, and NetConnectionStatus to the Win32_NetworkAdapter query (Windows XP/7 legacy fallback).

lib/GLPI/Agent/Tools/Win32/NetAdapter.pm

  • Added MANUFACTURER and MODEL fields to getBaseInterface().
  • Added _getManufacturer(): returns DriverProvider (MSFT) or Manufacturer (legacy).
  • Added _getModel(): returns DriverDescription (MSFT) or Name (legacy).
  • Added _getConnectionName(): returns the connection name (Name for MSFT, NetConnectionID for legacy).
  • Added _getMtu(): extracts the MTU natively from MtuSize (MSFT) if available, falling back to Win32_NetworkAdapterConfiguration (legacy).
  • Extracted original description fallback logic into _getHardwareDescription() to safely preserve legacy VPN/RAS adapter validation in _isVirtual() and getInterfaces().
  • Updated _isVirtual() to directly query the native Virtual WMI property if available, accurately flagging LoadBalance and other modern software adapters as virtualdev.
  • Updated _getDescription() to prioritize the connection name (e.g., "Ethernet" or "Wi-Fi" from ncpa.cpl) for GLPI reporting, making it equivalent to Unix logical interface names (e.g. eth0).
  • Added _getStatus() to check the adapter's physical link state via MediaConnectState or NetConnectionStatus instead of relying solely on IP configuration, fixing the "Down" status for physical NICs in Teaming/LoadBalance setups.

Tests

  • Updated expectations in t/agent/tools/win32.t to accommodate the natively extracted MSFT WMI properties and modern MtuSize values.

Field Mapping

GLPI Field Win8+ (MSFT_NetAdapter) Legacy (Win32_NetworkAdapter) Post-Processing
MANUFACTURER DriverProvider Manufacturer None
MODEL DriverDescription Name None
DESCRIPTION Name NetConnectionID None
MTU MtuSize Win32_NetworkAdapterConfiguration None
STATUS MediaConnectState NetConnectionStatus Fallback to IPEnabled
VIRTUALDEV Virtual Legacy string matching None

Request additional WMI properties for network adapters and populate vendor/model in the interface data. getInterfaces now asks for DriverProvider/DriverDescription (MSFT_NetAdapter) and Manufacturer/Name (Win32_NetworkAdapter). New helpers _getManufacturer and _getModel select the correct field depending on Windows version, and getBaseInterface sets MANUFACTURER and MODEL so adapter vendor and model are captured consistently across Win8+ and legacy systems.
Populate MANUFACTURER and MODEL fields across Windows network adapter test fixtures to include vendor and device model metadata. Updates multiple entries (Realtek, Microsoft, Fortinet, Intel, Broadcom, Symantec, DisplayLink, TAP-Windows, Hyper‑V, etc.) in t/agent/tools/win32.t to enable testing of parsing/identification logic using vendor/model values.
Include connection-name properties from WMI (MSFT_NetAdapter.Name and Win32_NetworkAdapter.NetConnectionID) and prefer those as the adapter description. Update WMI queries to request Name/NetConnectionID. Refactor NetAdapter methods: introduce _getHardwareDescription and _getConnectionName, make _getDescription return the connection name when available, switch VPN and virtual-adapter checks to use the hardware description/connection name appropriately. This ensures correct detection of VPN and virtual adapters across legacy (Win<8) and Win8+ systems.
Add vendor lookup for network interfaces using the PCIID. Import GLPI::Agent::Tools::Generic and parse the PCIID to extract the vendor ID, call getPCIDeviceVendor (using lc vendor id, datadir and logger from params), and set interface->{MANUFACTURER} when a vendor name is found to enrich inventory data.
Query MediaConnectState/NetConnectionStatus and normalize link state to 'Up'/'Down'. Update Win32::getInterfaces to request MediaConnectState (MSFT_NetAdapter) and NetConnectionStatus (Win32_NetworkAdapter). Replace direct STATUS use with a new _getStatus method in NetAdapter that maps MediaConnectState and NetConnectionStatus to 'Up'/'Down' and falls back to the existing STATUS value. Add a unit test t/tasks/inventory/windows/networks_doInventory.t that mocks getInterfaces/getRegistryKey and verifies inventory behavior (three adapters and expected manufacturer overwrite for PCI devices). This ensures accurate connection status across newer and legacy WMI classes.
@eduardomozart eduardomozart changed the title feat(win32): collect network adapter manufacturer and model from WMI feat(win32): collect network adapter description, manufacturer, model and link status from WMI Jun 4, 2026
Include the Virtual property when querying MSFT_NetAdapter and use it in _isVirtual() to detect virtual network adapters (Win8+). Keeps existing fallbacks (PNP/PhysicalAdapter) when Virtual is not defined. Update unit tests to expect virtual devices to be flagged and adjust test count accordingly.
@eduardomozart eduardomozart changed the title feat(win32): collect network adapter description, manufacturer, model and link status from WMI feat(win32): collect network adapter description, manufacturer, model, virtualdev and link status from WMI Jun 4, 2026
Add WMI resource blobs for load-balanced adapters (resources/win32/wmi/loadbalance-*.wmi), extend t/agent/tools/win32.t with a 'loadbalance' test vector and bump the Win32-only test count, and remove the now-obsolete integration test t/tasks/inventory/windows/networks_doInventory.t. These changes add coverage for virtual/multiplexor network adapters and align test expectations with the new WMI resources.
Remove the 'dns => undef' entry from the %tests hash in t/agent/tools/win32.t so test expectations no longer include a DNS field. Also update the loadbalance-Win32_NetworkAdapterConfiguration.wmi binary fixture to reflect the corresponding WMI data change, keeping tests and fixtures in sync.
@eduardomozart eduardomozart changed the title feat(win32): collect network adapter description, manufacturer, model, virtualdev and link status from WMI feat(win32): collect network adapter description, virtualdev and link status from WMI Jun 4, 2026
Remove manufacturer/model detection and PCI vendor lookup for Windows network adapters. Updated Win32 tools to stop requesting DriverProvider/DriverDescription/Manufacturer/Name properties from WMI, removed _getManufacturer/_getModel and related fields from NetAdapter and disabled the PCI vendor lookup in Networks inventory. Test expectations were updated to remove MANUFACTURER and MODEL entries. Affected files: lib/GLPI/Agent/Task/Inventory/Win32/Networks.pm, lib/GLPI/Agent/Tools/Win32.pm, lib/GLPI/Agent/Tools/Win32/NetAdapter.pm, and t/agent/tools/win32.t.
Populate MANUFACTURER and MODEL for Windows network interfaces. NetAdapter: add _getManufacturer and _getModel helpers and set MANUFACTURER/MODEL in getBaseInterface (prefer DriverProvider/DriverDescription for MSFT_NetAdapter, fallback to Manufacturer/Name for legacy). Tools::Win32: request DriverProvider/DriverDescription and Manufacturer/Name in WMI queries for MSFT_NetAdapter and Win32_NetworkAdapter. Networks: if PCIID is present, look up PCI vendor via getPCIDeviceVendor and populate MANUFACTURER. Update unit tests to cover expected MANUFACTURER and MODEL values. These changes improve inventory accuracy for both modern and legacy adapters.
@eduardomozart eduardomozart changed the title feat(win32): collect network adapter description, virtualdev and link status from WMI feat(win32): collect network adapter description, manufacturer, model, virtualdev and link status from WMI Jun 5, 2026
@eduardomozart eduardomozart changed the title feat(win32): collect network adapter description, manufacturer, model, virtualdev and link status from WMI feat(win32): collect network adapter description, manufacturer, model, mtu, virtualdev and link status from WMI Jun 6, 2026
Expose MTU reported by MSFT_NetAdapter (MtuSize) and surface it in the NetAdapter object. Added MtuSize to the WMI properties in Win32.pm, implemented _getMtu() in NetAdapter.pm (returns MtuSize or falls back to Win32_NetworkAdapterConfiguration MTU), and switched the base interface MTU to use this getter. Updated unit tests to reflect expected MTU values.
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.
@g-bougard

Copy link
Copy Markdown
Member

Hi @eduardomozart

thank you for your PR, but I see one big problem: you're attempting to change the inventory format in GLPI::Agent::Inventory. And indeed, the final format doesn't match the specified one: https://github.com/glpi-project/inventory_format

So actually, we can't accept your PR.

If this actually works with GLPI, this may be a coincidence but this is finally not correct.

@eduardomozart

eduardomozart commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

Hello,
It should match the GLPI inventory data; there's an open PR that uses this new data on GLPI at: glpi-project/glpi#24471
There is, in fact, a limitation in GLPI regarding the stats information. I think transmitting it would require checking the GLPI version, because actually there is an artificial limitation in GLPI regarding the stats for non-NetworkEquipment objects (like Computer assets). I think I'll split the stats on a new PR #1184 until glpi-project/glpi#24471 is approved

@g-bougard

Copy link
Copy Markdown
Member

Hi Eduardo,

tests are failing actually. Can you fix them ?

Add UTF-8 handling to the Windows firewall inventory test and update expected interface DESCRIPTION values. Replace vendor-specific NIC names with generic OS interface names (e.g. 'Connexion au réseau local', 'Ethernet') so the test expectations match actual Windows output.
@eduardomozart

Copy link
Copy Markdown
Contributor Author

Yes, it's now fixed. The firewall test was still using the old hardware description. Now it's passing:

1..5
ok 1 - test windows 10 FirewallPolicy: extract firewall profiles from registry
ok 2 - test windows 10 _getFirewallProfiles()
ok 3 - test windows 7_firewall FirewallPolicy: extract firewall profiles from registry
ok 4 - test windows 7_firewall _getFirewallProfiles()
ok 5 - no warnings

@eduardomozart eduardomozart changed the title feat(win32): collect network adapter description, manufacturer, model, mtu, virtualdev and link status from WMI feat(win32): collect network adapter description, manufacturer, model/driver, mtu, virtualdev and link status from WMI Jun 10, 2026
@eduardomozart eduardomozart changed the title feat(win32): collect network adapter description, manufacturer, model/driver, mtu, virtualdev and link status from WMI feat(win32): collect network adapter description, manufacturer, model, mtu, virtualdev and link status from WMI Jun 11, 2026
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