Fibre Channel Switch Status
$ports) {
$switchIndex++;
$collapseId = "collapse_" . $switchIndex; // Unique ID for Bootstrap
// Initialize counters
$upCount = 0;
$downCount = 0;
$errorCount = 0;
// Arrays to store HTML rows (for sorting logic)
$errorRows = [];
$normalRows = [];
// 4. Loop through Ports to calculate stats and build rows
foreach ($ports as $portId => $portData) {
$state = $portData['State'];
$errors = (int)$portData['Errors']; // Cast to int for safety
if ($state === 'UP') {
$upCount++;
// Determine row color
$rowClass = "table-success";
if ($errors > 0) {
$errorCount++;
$rowClass = "table-danger";
}
// Build the HTML for this row
// Note: Using variables in double quotes for cleaner syntax
$rowHtml = "
{$portId}
{$portData['Status']}
{$portData['State']}
{$portData['Speed']}
{$portData['Nego']}
{$portData['FrameTX']}
{$portData['FrameRX']}
{$portData['Errors']}
";
// Sort into appropriate array
if ($errors > 0) {
$errorRows[] = $rowHtml;
} else {
$normalRows[] = $rowHtml;
}
} elseif ($state === 'DN') {
$downCount++;
}
}
// 5. Merge rows: Errors first
$finalRows = array_merge($errorRows, $normalRows);
$tableBody = implode("\n", $finalRows);
// 6. Determine Header Style
$headerColor = "green";
$msg = "OK";
if ($errorCount > 0) {
$headerColor = "DarkOrange";
$msg = " --> {$errorCount} issue(s)";
}
// 7. Output the Accordion Item (Card)
?>
No data available via API.
";
}
?>
| Port | Status | State | Speed | Nego | FrameTX | FrameRX | Errors |
|---|
No data available via API.