$ports) {
$switchIndex++;
- $collapseId = "collapse_" . $switchIndex; // Unique ID for Bootstrap
+ $collapseId = "collapse_" . $switchIndex;
- // Initialize counters
+ // 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 = "";
- // Arrays to store HTML rows (for sorting logic)
- $errorRows = [];
- $normalRows = [];
-
- // 4. Loop through Ports to calculate stats and build rows
+ // Generate HTML Rows based on sorted data
foreach ($ports as $portId => $portData) {
$state = $portData['State'];
- $errors = (int)$portData['Errors']; // Cast to int for safety
+ $errors = (int)$portData['Errors'];
- if ($state === 'UP') {
- $upCount++;
+ if ($state === 'UP') $upCount++;
+ elseif ($state === 'DN') $downCount++;
- // Determine row color
- $rowClass = "table-success";
- if ($errors > 0) {
- $errorCount++;
- $rowClass = "table-danger";
- }
+ if ($errors > 0 && $state === 'UP') $errorCount++;
- // 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++;
+ 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']} |
+
";
}
- // 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)
+ // Determine Header Color
+ $headerColor = ($errorCount > 0) ? "DarkOrange" : "green";
+ $msg = ($errorCount > 0) ? "
{$errorCount} issue(s)" : "OK";
?>
@@ -142,20 +143,22 @@
+
-
+
- | Port |
- Status |
- State |
- Speed |
- Nego |
- FrameTX |
- FrameRX |
- Errors |
+ vFabric |
+ Port |
+ Status |
+ State |
+ Speed |
+ Nego |
+ FrameTX |
+ FrameRX |
+ Errors |
@@ -168,14 +171,16 @@
No data available via API.";
}
?>
-
+
+
+