From d5b45dbc22ab357c92966eebccaab022bc6a1e77 Mon Sep 17 00:00:00 2001 From: e025532 Date: Wed, 4 Feb 2026 14:52:49 +0100 Subject: [PATCH] Remove `test.php` and enhance null safety and sorting across components - Deleted `test.php` as it was no longer in use. - Enhanced null safety checks in `Inventory.php`, `StdOut-detail.php`, `Backups.php`, and `SwitchsSAN.php` to prevent potential warnings. - Refactored `SwitchsSAN.php` to improve sorting logic for ports based on errors, vFabric, and Port ID. - Added seasonal snow effect script in `all.php` with toggle functionality for user engagement. - Updated navigation bar (`navbar.html`) to include a new VIO page link. - Introduced a new `VIO.php` page to display VIO monitoring details with table export and sorting features. --- Hyper-V/VMs-Backups.php | 110 ++++++++++++--------- Storage/SwitchsSAN.php | 149 +++++++++++++++-------------- X/Backups.php | 6 +- X/Inventory.php | 6 +- X/StdOut-detail.php | 4 +- X/VIO.php | 191 +++++++++++++++++++++++++++++++++++++ include/all.php | 206 +++++++++++++++++++++++++++++++++++++++- include/test.php | 46 --------- navbar.html | 1 + 9 files changed, 544 insertions(+), 175 deletions(-) create mode 100644 X/VIO.php delete mode 100644 include/test.php diff --git a/Hyper-V/VMs-Backups.php b/Hyper-V/VMs-Backups.php index db21a56..6cc7ceb 100644 --- a/Hyper-V/VMs-Backups.php +++ b/Hyper-V/VMs-Backups.php @@ -79,69 +79,87 @@ 'OK' or lastresult is null) and policy is not null order by lastresult,name"); foreach ($answers as $row) { - $er++; - $date1 = date_create($row['LastKnownGood']??'01/01/1970'); $diff = date_diff($date1, date_create(date("Y-m-d"))); - if ($diff->format("%R%a") >= 2 || $row['LastKnownGood'] == ''){ - echo ""; - }else{ - echo ""; - } - if($diff->format("%R%a") == "-0"){$LastGood = "NEVER";}else{$LastGood = $row['LastKnownGood']." (".$diff->format("%R%a")."J)";} - echo "".$row['Name'].""; - echo "".$row['LastBackup']." ".$row['TimeStamp'].""; - echo "".$row['LastResult'].""; - echo "".$LastGood.""; - echo "".$row['LastSize'].""; - echo "".$row['Owner'].""; - echo "".$row['Policy'].""; + if(in_array($row['Name'], $active)){ + $er++; + $date1 = date_create($row['LastKnownGood'] ?? '01/01/1970'); + $diff = date_diff($date1, date_create(date("Y-m-d"))); + if ($diff->format("%R%a") >= 2 || $row['LastKnownGood'] == '') { + echo ""; + } else { + echo ""; + } + if ($diff->format("%R%a") == "-0") { + $LastGood = "NEVER"; + } else { + $LastGood = $row['LastKnownGood'] . " (" . $diff->format("%R%a") . "J)"; + } + echo "" . $row['Name'] . ""; + echo "" . $row['LastBackup'] . " " . $row['TimeStamp'] . ""; + echo "" . $row['LastResult'] . ""; + echo "" . $LastGood . ""; + echo "" . $row['LastSize'] . ""; + echo "" . $row['Owner'] . ""; + echo "" . $row['Policy'] . ""; - echo ""; + echo ""; + } } // Outdated $outdated = 0; $answers = Invoke_infra("SELECT * FROM VMs_Backup where ( Owner like 'DUN-VMH%' or Owner like 'MDK-VMH%' ) and name not like 'WS%' and owner not like '%WKG%' and owner not like '%VMH-WM%' and Exclusion ='' and LastResult = 'OK' and TRY_CAST(lastknowngood AS DATE) < CAST(DATEADD(DAY, -2, GETDATE()) AS DATE) order by name"); foreach ($answers as $row) { - $date1 = date_create($row['LastKnownGood']); $diff = date_diff($date1, date_create(date("Y-m-d"))); - if(date('w') >= 2 && date('w') <= 6 ){ - if ($diff->format("%R%a") >= 2){ - echo ""; - }else{ - echo ""; - } - }else{ - if((date('w') < 2 || date('w') == 7)){ - if($diff->format("%R%a") <= 3){ - echo ""; - }else{ + if (in_array($row['Name'], $active)) { + $date1 = date_create($row['LastKnownGood']); + $diff = date_diff($date1, date_create(date("Y-m-d"))); + if (date('w') >= 2 && date('w') <= 6) { + if ($diff->format("%R%a") >= 2) { echo ""; + } else { + echo ""; + } + } else { + if ((date('w') < 2 || date('w') == 7)) { + if ($diff->format("%R%a") <= 3) { + echo ""; + } else { + echo ""; + } } } - } - if($diff->format("%R%a") == "-0"){$LastGood = $row['LastKnownGood'];}else{$LastGood = $row['LastKnownGood']." (".$diff->format("%R%a")."J)";} - echo "".$row['Name'].""; - echo "".$row['LastBackup']." ".$row['TimeStamp'].""; - echo "".$row['LastResult'].""; - if (date('w') >= 2 && date('w') <= 6 && $diff->format("%R%a") < 1){ - echo "".$LastGood.""; - }else{ - if ((date('w') == 1 || date('w') == 7) && $diff->format("%R%a") <= 3){ - echo "".$LastGood.""; - }else{ - echo "".$LastGood.""; - $outdated++; + if ($diff->format("%R%a") == "-0") { + $LastGood = $row['LastKnownGood']; + } else { + $LastGood = $row['LastKnownGood'] . " (" . $diff->format("%R%a") . "J)"; } + echo "" . $row['Name'] . ""; + echo "" . $row['LastBackup'] . " " . $row['TimeStamp'] . ""; + echo "" . $row['LastResult'] . ""; + if (date('w') >= 2 && date('w') <= 6 && $diff->format("%R%a") < 1) { + echo "" . $LastGood . ""; + } else { + if ((date('w') == 1 || date('w') == 7) && $diff->format("%R%a") <= 3) { + echo "" . $LastGood . ""; + } else { + echo "" . $LastGood . ""; + $outdated++; + } + } + echo "" . $row['LastSize'] . ""; + echo "" . $row['Owner'] . ""; + echo "" . $row['Policy'] . ""; + echo ""; } - echo "".$row['LastSize'].""; - echo "".$row['Owner'].""; - echo "".$row['Policy'].""; - echo ""; } - // Backup OK $answers = Invoke_infra("SELECT * FROM VMs_Backup where ( Owner like 'DUN-VMH%' or Owner like 'MDK-VMH%' ) and name not like 'WS%' and owner not like '%WKG%' and owner not like '%VMH-WM%' and Exclusion ='' and LastResult = 'OK' and TRY_CAST(lastknowngood AS DATE) >= CAST(DATEADD(DAY, -2, GETDATE()) AS DATE) order by name"); diff --git a/Storage/SwitchsSAN.php b/Storage/SwitchsSAN.php index c49402f..5e47f5f 100644 --- a/Storage/SwitchsSAN.php +++ b/Storage/SwitchsSAN.php @@ -14,11 +14,11 @@ + + + + @@ -26,13 +26,12 @@ @@ -62,77 +61,79 @@
$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 @@
+
- +
- - - - - - - - + + + + + + + + + @@ -168,14 +171,16 @@
No data available via API."; } ?> - + + + \ No newline at end of file diff --git a/X/Backups.php b/X/Backups.php index fc8b43e..d659469 100644 --- a/X/Backups.php +++ b/X/Backups.php @@ -82,7 +82,7 @@ foreach ($list as $s) { $name = $s['HOSTNAME']; $ts = $s['ts']; - $lastBackup = (explode(".",$s['LastBackup']))[0]; + $lastBackup = (explode(".",$s['LastBackup'] ?? ''))[0]; $location = $s['Location']; $log = $s['Log']; $backuptype = $s['BackupType']; @@ -135,19 +135,15 @@ - + + + + + + + + + + + + + + + + + + $rows) { + // 1. Sort by date desc + usort($rows, function($a, $b) { + return strcmp($b['ts'], $a['ts']); + }); + + // 2. Keep max 2 + if (count($rows) > 2) { + $rows = array_slice($rows, 0, 2); + } + + $names = []; $inerrs = []; $vfcs = []; $vios = []; + $clintids = []; $fcnames = []; $tss = []; $vioerrs = []; + + $hasError = false; + $maxVioErr = 0; + + foreach ($rows as $r) { + if ($r['inerr'] != 0 && $r['inerr'] != '0') $hasError = true; + + // Track VIOErr + $errVal = (int)($r['VIOErr'] ?? 0); + if ($errVal > $maxVioErr) $maxVioErr = $errVal; + + // Format VIOErr for display (Red badge if > 0) + $vioerrs[] = ($errVal > 0) ? "$errVal" : $errVal; + + $names[] = $r['name'] ?? '-'; + $inerrs[] = $r['inerr'] ?? '-'; + $vfcs[] = $r['vfcclientname'] ?? '-'; + $vios[] = $r['vio'] ?? '-'; + $clintids[] = $r['clintid'] ?? '-'; + $fcnames[] = $r['fcname'] ?? '-'; + $tss[] = $r['ts'] ?? '-'; + } + + $displayRows[] = [ + 'clintname' => $clientKey, + 'hasError' => $hasError, + 'maxVioErr' => $maxVioErr, + 'name' => implode('
', $names), + 'inerr' => implode('
', $inerrs), + 'vfc' => implode('
', $vfcs), + 'vio' => implode('
', $vios), + 'clintid' => implode('
', $clintids), + 'fcname' => implode('
', $fcnames), + 'ts' => implode('
', $tss), + 'vioerr' => implode('
', $vioerrs), + ]; +} + +// 4. Final Sort: 1. Warning (inerr), 2. VIOErr > 0, 3. Alpha +usort($displayRows, function($a, $b) { + // Priority 1: InErr (table-warning) + if ($a['hasError'] && !$b['hasError']) return -1; + if (!$a['hasError'] && $b['hasError']) return 1; + + // Priority 2: VIOErr count + if ($a['maxVioErr'] > 0 && $b['maxVioErr'] == 0) return -1; + if ($a['maxVioErr'] == 0 && $b['maxVioErr'] > 0) return 1; + if ($a['maxVioErr'] != $b['maxVioErr']) return $b['maxVioErr'] - $a['maxVioErr']; + + // Priority 3: Alphabetical + return strcasecmp($a['clintname'], $b['clintname']); +}); +?> + +
+
+
+ +
+ +
+

VIO Monitoring

+ +
+
+
PortStatusStateSpeedNegoFrameTXFrameRXErrorsvFabricPortStatusStateSpeedNegoFrameTXFrameRXErrors
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Clint NameNameVIOErrInErrVFC Client NameVIOClintIDFC NameLast Update
+
+
+
+
+ + + + + \ No newline at end of file diff --git a/include/all.php b/include/all.php index cd23c8f..b190e23 100644 --- a/include/all.php +++ b/include/all.php @@ -335,6 +335,207 @@ ?> + + + + + + + + - \ No newline at end of file + + + + diff --git a/include/test.php b/include/test.php deleted file mode 100644 index 513f8a4..0000000 --- a/include/test.php +++ /dev/null @@ -1,46 +0,0 @@ -"; - // Pour débogage, tu peux aussi loguer cette erreur dans un fichier - // error_log($error_message); - return "ERROR: Could not connect to DB2. Check connection string and ODBC setup."; // Retourne une erreur pour éviter l'appel à odbc_exec - } - - $rs = odbc_exec($conn, $request); - - // Ton code existant après la connexion - if (strpos(strtoupper($request), "SELECT") !== false) { // strpos est plus robuste que instr ici en PHP - $answer = []; // Initialize array to prevent undefined variable warning - while ($row = odbc_fetch_array($rs)) { - $answer[] = $row; - } - } - - if (isset($answer)) { - return $answer; - } else { - if ($rs) { - return "OK"; - } else { - // If odbc_exec failed - error_reporting(E_ALL); // Re-enable for this specific error if needed - return "ERROR : " . odbc_errormsg($conn); - } - } - diff --git a/navbar.html b/navbar.html index c1636f1..f99832a 100644 --- a/navbar.html +++ b/navbar.html @@ -48,6 +48,7 @@ - AutoRemediation Logs - Scripts Result - Backups + - VIO