Skip to content

Commit

Permalink
fix(Inventory): correctly handle Cisco stacked switch (#15759)
Browse files Browse the repository at this point in the history
  • Loading branch information
stonebuzz authored Nov 7, 2023
1 parent 1f1ae81 commit 6d74daf
Show file tree
Hide file tree
Showing 3 changed files with 3,924 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Inventory/Asset/NetworkPort.php
Original file line number Diff line number Diff line change
Expand Up @@ -799,11 +799,19 @@ public function handlePorts($itemtype = null, $items_id = null)
$bkp_ports = $this->ports;
$stack_id = $mainasset->getStackId();
$need_increment_index = false;
$count_char = 0;
foreach ($this->ports as $k => $val) {
$matches = [];
if (
preg_match('@[\w\s+]+(\d+)/[\w]@', $val->name, $matches)
) {
//reset increment when name lenght differ
//Gi0/0 then Gi0/0/1, Gi0/0/2, Gi0/0/3
if ($count_char && $count_char != strlen($val->name)) {
$need_increment_index = false;
}
$count_char = strlen($val->name);

//in case when port is related to chassis index 0 (stack_id)
//ex : GigabitEthernet 0/1 Gi0/0/1
//GLPI compute stack_id by starting with 1 (see: NetworkEquipment->getStackedSwitches)
Expand All @@ -813,7 +821,6 @@ public function handlePorts($itemtype = null, $items_id = null)
//current NetworkEquipement must have the index incremented
$need_increment_index = true;
}

if ($matches[1] != $stack_id) {
//port attached to another stack entry, remove from here
unset($this->ports[$k]);
Expand Down
Loading

0 comments on commit 6d74daf

Please sign in to comment.