feat(inventory): Map network port metrics and logical_number for computer assets#24508
Draft
eduardomozart wants to merge 17 commits into
Draft
feat(inventory): Map network port metrics and logical_number for computer assets#24508eduardomozart wants to merge 17 commits into
logical_number for computer assets#24508eduardomozart wants to merge 17 commits into
Conversation
Add icon entries to CommonDevice menu options using getIcon() so device/type menu items include icons. In NetworkCard, map 'model' to devicenetworkcardmodels_id and populate designation from model or description when designation is missing, ensuring cards have a sensible name when model data is present.
This reverts commit d21ab4f.
Add support for an extra_data.network_ports array in NetworkCard and use it to match ports by MAC or name to populate logical_number from ifnumber. Also add method_exists guards in NetworkPort before calling getManagementPorts and isStackedSwitch to avoid fatal errors when those methods are not present. Small mapping reorder (speed) was adjusted while integrating the new matching logic.
Ensure safer handling of network port data and asset type checks: in NetworkCard, verify extra_data['network_ports'] is iterable, assign it to a local variable, add a docblock, and cast port properties to string before lowercasing to avoid warnings on unexpected types. In NetworkPort, replace method_exists checks with instanceof checks against Glpi\Inventory\MainAsset\NetworkEquipment and Glpi\Inventory\MainAsset\Printer (fully-qualified) when accessing management ports and stacked-switch logic, improving type safety and clarity.
Add use statements for NetworkEquipment and Printer in NetworkPort.php and replace fully-qualified class names with the imported names for clearer instanceof checks. Also apply minor spacing cleanup around (string) casts in NetworkCard.php. These are refactors only and do not change behavior.
Remove network_ports from NetworkCard extra_data and simplify port normalization logic: set logical_number only when missing and normalize virtualdev to 0 unless explicitly 1. This removes the previous cross-check against extra_data['network_ports'] (matching by MAC/name) to derive logical_number. Add a functional test (testComputerNetworkPortMetrics) that exercises NetworkCard then NetworkPort processing, asserting that network port metrics are saved and that logical_number is set as expected.
Add use statement for NetworkCard and replace fully-qualified instantiations with imported class names (Converter, Conf, NetworkCard) in tests/functional/Glpi/Inventory/Assets/NetworkPortTest.php. Also apply minor whitespace cleanup to improve readability and consistency in the test.
Add support for linking extra_data['network_ports'] entries to inventory ports and using their ifnumber as the port's logical_number. Introduce 'network_ports' to NetworkCard::extra_data, adjust virtualdev/logical_number initialization, and iterate network_ports to match by mac and name, setting logical_number when a match with ifnumber is found. Update phpstan baseline: add an ignore for undefined property $mtu in NetworkCard.php and increment a related classConstant.nonObject count for NetworkPort.php.
Increment the 'count' for the offsetAccess.invalidOffset entry in .phpstan-baseline.specific.php (path: src/Glpi/Inventory/Asset/NetworkPort.php) from 4 to 5 to account for an additional reported issue.
Delete the 'mtu' entry from NetworkCard's attribute mapping and remove the corresponding phpstan baseline ignore for an undefined $mtu property. Cleans up an unused mapping and eliminates the need for a suppression entry in .phpstan-baseline.php.
This was referenced Jun 8, 2026
Contributor
|
Will wait for Agent PR. |
stonebuzz
suggested changes
Jun 11, 2026
Co-authored-by: Stanislas <skita@teclib.com>
Contributor
|
Back to draft since agent change has not been validated |
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.
Checklist before requesting a review
Please delete options that are not relevant.
Description
Closes #24509
Note
(There is an ongoing discussion about this feature at #24509)
This PR introduces server-side support for mapping network port statistics and interface metrics to computer assets during inventory. Vital interface statistics like the Number of I/O bytes (
ifinbytes,ifoutbytes,ifinerrors,ifouterrors) and the Port Number (logical_number/ifnumber) are now correctly extracted from the payload and mapped to the respectiveNetworkCardandNetworkPortrecords.This brings host-level network monitoring parity to computer assets. While metrics are traditionally associated with network equipment (like manageable switches), capturing them at the computer/host level provides direct insight into the actual traffic processed by the server's or workstation's OS, regardless of the upstream network topology. This mapping does not conflict with or affect switch metrics. Computer network ports and switch network ports remain separate entities in the database, meaning each retains its own independent telemetry data.
Key Under-the-Hood Changes:
network_portsdata from the inventory payload and links it toNetworkCardentries by matching MAC addresses and interface names.ifnumberto the interface'slogical_number.NetworkCardport handling for simplicity and accuracy.Warning
Dependency & Compatibility Notice
1. Agent Requirement: For this feature to work, the GLPI-Agent must be patched to collect and send these statistics. See the companion PR: glpi-project/glpi-agent#1184.
2. Backward Compatibility Warning: Although sending
NETWORK_PORTSfor computers is technically valid according to the inventory schema, older versions of GLPI do not expect this data for non-NetworkEquipment assets. If an updated agent sends this payload to an older GLPI server, it will trigger a fatal error:(A similar error also occurs with
isStackedSwitch()).Because of this, the GLPI-Agent must perform a version check against GLPI to ensure it only transmits the
NETWORK_PORTSpayload to compatible GLPI instances (such as the version containing this PR).How to test: