feat(win32): collect network adapter description, manufacturer, model, mtu, virtualdev and link status from WMI#1176
Conversation
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.
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.
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.
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.
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.
|
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. |
|
Hello, |
|
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.
|
Yes, it's now fixed. The firewall test was still using the old hardware description. Now it's passing: |
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
MANUFACTURERandMODELfields were never populated for theNETWORKSsection.Additionally, GLPI users expect the network adapter
DESCRIPTIONfield to display the Windows connection name (e.g., "Ethernet" or "Wi-Fi" fromncpa.cpl). This provides parity with Unix systems, where this field typically holds the logical interface name (likeeth0orwlan0).Finally, setups using NIC Teaming or LoadBalance multiplexors had two major reporting inaccuracies:
STATUSof "Down" even when physically connected, because the agent relied on IP address assignment to determine link status.virtualdev: false).Root Cause
getInterfaces()function inTools/Win32.pmqueriedMSFT_NetAdapter(Win8+) andWin32_NetworkAdapter(legacy) but did not request the driver/manufacturer, connection name, physical connection state, hardware MTU, or virtual status properties.NetAdapter.pmhad no data to populateMANUFACTURERandMODELin the base interface, and passed the raw hardware description to theDESCRIPTIONfield instead of the connection name (e.g., "Ethernet" or "Wi-Fi" fromncpa.cpl).NetAdapter.pmhistorically derived theSTATUSof an interface by checkingIPEnabledinWin32_NetworkAdapterConfiguration. In LoadBalance scenarios, the underlying physical NICs do not have IP addresses directly assigned, causing them to falsely report as "Down"._isVirtual()method relied on string matching (e.g.,ROOT\or "RAS Adapter") to identify virtual interfaces, completely missing modern software-defined network adapters like theCOMPOSITEBUSmultiplexor used in LoadBalancing.Win32_NetworkAdapterConfigurationfor MTU, which is often empty or unreliable on modern Windows environments unless explicitly set in the registry.Changes
lib/GLPI/Agent/Tools/Win32.pmDriverProvider,DriverDescription,Name,MediaConnectState,Virtual, andMtuSizeto theMSFT_NetAdapterWMI query (Windows 8 and above).Manufacturer,Name,NetConnectionID, andNetConnectionStatusto theWin32_NetworkAdapterquery (Windows XP/7 legacy fallback).lib/GLPI/Agent/Tools/Win32/NetAdapter.pmMANUFACTURERandMODELfields togetBaseInterface()._getManufacturer(): returnsDriverProvider(MSFT) orManufacturer(legacy)._getModel(): returnsDriverDescription(MSFT) orName(legacy)._getConnectionName(): returns the connection name (Namefor MSFT,NetConnectionIDfor legacy)._getMtu(): extracts the MTU natively fromMtuSize(MSFT) if available, falling back toWin32_NetworkAdapterConfiguration(legacy)._getHardwareDescription()to safely preserve legacy VPN/RAS adapter validation in_isVirtual()andgetInterfaces()._isVirtual()to directly query the nativeVirtualWMI property if available, accurately flagging LoadBalance and other modern software adapters asvirtualdev._getDescription()to prioritize the connection name (e.g., "Ethernet" or "Wi-Fi" fromncpa.cpl) for GLPI reporting, making it equivalent to Unix logical interface names (e.g.eth0)._getStatus()to check the adapter's physical link state viaMediaConnectStateorNetConnectionStatusinstead of relying solely on IP configuration, fixing the "Down" status for physical NICs in Teaming/LoadBalance setups.Tests
t/agent/tools/win32.tto accommodate the natively extracted MSFT WMI properties and modernMtuSizevalues.Field Mapping
MSFT_NetAdapter)Win32_NetworkAdapter)MANUFACTURERDriverProviderManufacturerMODELDriverDescriptionNameDESCRIPTIONNameNetConnectionIDMTUMtuSizeWin32_NetworkAdapterConfigurationSTATUSMediaConnectStateNetConnectionStatusIPEnabledVIRTUALDEVVirtual