Fibre Channel Switch Status

$ports) { $switchIndex++; $collapseId = "collapse_" . $switchIndex; // Inject PortID into the array content for easier sorting foreach ($ports as $k => $v) $ports[$k]['_PortID'] = $k; // Custom Sort: Errors (Desc) > vFabric (Asc) > Port (Natural Asc) uasort($ports, function ($a, $b) { // Errors (Descending) $errA = (int)$a['Errors']; $errB = (int)$b['Errors']; if ($errA !== $errB) { return $errB <=> $errA; } // vFabric (Ascending / Case Insensitive) $vfA = $a['vFabric'] ?? ''; $vfB = $b['vFabric'] ?? ''; $cmpVf = strcasecmp($vfA, $vfB); if ($cmpVf !== 0) { return $cmpVf; } // Port ID (Natural Sort, e.g. 2 comes before 10) return strnatcmp($a['_PortID'], $b['_PortID']); }); // Initialize counters & buffers $upCount = 0; $downCount = 0; $errorCount = 0; $tableBody = ""; // Generate HTML Rows based on sorted data foreach ($ports as $portId => $portData) { $state = $portData['State']; $errors = (int)$portData['Errors']; if ($state === 'UP') $upCount++; elseif ($state === 'DN') $downCount++; if ($errors > 0 && $state === 'UP') $errorCount++; if ($state === 'DN') { continue; } // Determine Row CSS Class $rowClass = "table-success"; if ($errors > 0) $rowClass = "table-danger"; // Build Row HTML $tableBody .= " {$portData['vFabric']} {$portId} {$portData['Status']} {$portData['State']} {$portData['Speed']} {$portData['Nego']} {$portData['FrameTX']} {$portData['FrameRX']} {$portData['Errors']} "; } // Determine Header Color $headerColor = ($errorCount > 0) ? "DarkOrange" : "green"; $msg = ($errorCount > 0) ? " {$errorCount} issue(s)" : "OK"; ?>
vFabric Port Status State Speed Nego FrameTX FrameRX Errors

No data available via API.
"; } ?>