Remove redundant comments, streamline query logic, and clean up variable handling for improved code readability and efficiency in StdOut.php and StdOut-detail.php.
This commit is contained in:
@@ -68,9 +68,6 @@
|
|||||||
<!-- TABLE -->
|
<!-- TABLE -->
|
||||||
<div>
|
<div>
|
||||||
<?php
|
<?php
|
||||||
// =================================================================
|
|
||||||
// ETAPE 1: Récupérer la liste des serveurs (inchangé)
|
|
||||||
// =================================================================
|
|
||||||
$aix = $linux = $dun = $azt = $other = "Checked";
|
$aix = $linux = $dun = $azt = $other = "Checked";
|
||||||
$where = " and OS_TYPE IN (";
|
$where = " and OS_TYPE IN (";
|
||||||
if (isset($_GET['AIX'])) {
|
if (isset($_GET['AIX'])) {
|
||||||
@@ -126,29 +123,16 @@
|
|||||||
$sql = "select hostname, os_type from srvall where decomtime is null and (ucase(filter) not like 'X_%' or filter is null) $where order by hostname";
|
$sql = "select hostname, os_type from srvall where decomtime is null and (ucase(filter) not like 'X_%' or filter is null) $where order by hostname";
|
||||||
$hosts = Invoke_aixcmdb($sql);
|
$hosts = Invoke_aixcmdb($sql);
|
||||||
|
|
||||||
// Initialisation des compteurs
|
|
||||||
$taix = $aixok = $aixko = $tlinux = $linuxok = $linuxko = 0;
|
$taix = $aixok = $aixko = $tlinux = $linuxok = $linuxko = 0;
|
||||||
$resultsByHost = []; // Tableau pour stocker les résultats par host
|
$resultsByHost = [];
|
||||||
|
|
||||||
// =================================================================
|
|
||||||
// ETAPE 2: Récupérer TOUS les résultats en une seule requête
|
|
||||||
// =================================================================
|
|
||||||
if (!empty($hosts)) {
|
if (!empty($hosts)) {
|
||||||
// Créer une liste de noms de serveurs pour la clause IN
|
|
||||||
$hostnames = array_map(function ($h) {
|
$hostnames = array_map(function ($h) {
|
||||||
// Important: échapper les noms pour éviter l'injection SQL
|
|
||||||
return "'" . strtoupper($h['HOSTNAME']) . "'";
|
return "'" . strtoupper($h['HOSTNAME']) . "'";
|
||||||
}, $hosts);
|
}, $hosts);
|
||||||
$hostnamesList = implode(',', $hostnames);
|
$hostnamesList = implode(',', $hostnames);
|
||||||
|
|
||||||
// La deuxième et dernière requête SQL
|
|
||||||
$sqlResults = "SELECT * FROM x_stdout WHERE cmd = '$script' AND host IN ($hostnamesList)";
|
$sqlResults = "SELECT * FROM x_stdout WHERE cmd = '$script' AND host IN ($hostnamesList)";
|
||||||
$allAnswers = Invoke_Infra($sqlResults);
|
$allAnswers = Invoke_Infra($sqlResults);
|
||||||
|
|
||||||
// =================================================================
|
|
||||||
// ETAPE 3: Organiser les résultats dans un tableau associatif pour un accès rapide
|
|
||||||
// La clé du tableau sera le nom du serveur
|
|
||||||
// =================================================================
|
|
||||||
if (is_array($allAnswers)) {
|
if (is_array($allAnswers)) {
|
||||||
foreach ($allAnswers as $answer) {
|
foreach ($allAnswers as $answer) {
|
||||||
$resultsByHost[strtoupper($answer['host'])] = $answer;
|
$resultsByHost[strtoupper($answer['host'])] = $answer;
|
||||||
@@ -200,29 +184,23 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody> <?php
|
<tbody> <?php
|
||||||
// =================================================================
|
|
||||||
// ETAPE 4: Boucle pour afficher les données (maintenant très rapide)
|
|
||||||
// =================================================================
|
|
||||||
foreach ($hosts as $h) {
|
foreach ($hosts as $h) {
|
||||||
$host = strtoupper($h['HOSTNAME']);
|
$host = strtoupper($h['HOSTNAME']);
|
||||||
$os = strtoupper($h['OS_TYPE']);
|
$os = strtoupper($h['OS_TYPE']);
|
||||||
|
|
||||||
// Comptage initial
|
|
||||||
if ($os == "AIX") {
|
if ($os == "AIX") {
|
||||||
$taix++;
|
$taix++;
|
||||||
} else {
|
} else {
|
||||||
$tlinux++;
|
$tlinux++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Récupération des résultats depuis notre tableau, SANS requête !
|
$answer = $resultsByHost[$host] ?? null;
|
||||||
$answer = $resultsByHost[$host] ?? null; // Utilise l'opérateur null coalescent
|
|
||||||
|
|
||||||
if ($answer) {
|
if ($answer) {
|
||||||
$rc = $answer['rc'];
|
$rc = $answer['rc'];
|
||||||
$stdout = $answer['stdout'];
|
$stdout = $answer['stdout'];
|
||||||
$ts = $answer['ts'];
|
$ts = $answer['ts'];
|
||||||
|
|
||||||
// Comptage des status OK/KO
|
|
||||||
if ($os == "AIX") {
|
if ($os == "AIX") {
|
||||||
if ($rc == 0 && (string)$rc <> "") {
|
if ($rc == 0 && (string)$rc <> "") {
|
||||||
$aixok++;
|
$aixok++;
|
||||||
@@ -237,11 +215,9 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Si aucun résultat n'a été trouvé pour ce host
|
|
||||||
$rc = $stdout = $ts = "";
|
$rc = $stdout = $ts = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Affichage du tableau HTML (inchangé)
|
|
||||||
echo "<tr><td><b>$host</b></td>";
|
echo "<tr><td><b>$host</b></td>";
|
||||||
echo "<td>$os</td>";
|
echo "<td>$os</td>";
|
||||||
echo "<td>" . $ts . "</td>";
|
echo "<td>" . $ts . "</td>";
|
||||||
@@ -260,7 +236,6 @@
|
|||||||
</tbody>
|
</tbody>
|
||||||
<br>
|
<br>
|
||||||
<?php
|
<?php
|
||||||
// Calcul et affichage final des totaux (inchangé)
|
|
||||||
$aixNO = $taix - $aixok - $aixko;
|
$aixNO = $taix - $aixok - $aixko;
|
||||||
$linuxNO = $tlinux - $linuxok - $linuxko;
|
$linuxNO = $tlinux - $linuxok - $linuxko;
|
||||||
echo "<div class='row'><div class='col text-center h4'><b>$taix AIX : </b>";
|
echo "<div class='row'><div class='col text-center h4'><b>$taix AIX : </b>";
|
||||||
|
|||||||
13
X/StdOut.php
13
X/StdOut.php
@@ -63,29 +63,22 @@
|
|||||||
</div>
|
</div>
|
||||||
<!-- TABLE -->
|
<!-- TABLE -->
|
||||||
<div>
|
<div>
|
||||||
<?php // DATA OPTIMIZED
|
<?php
|
||||||
|
|
||||||
// The one and only query to get everything we need
|
|
||||||
$sql = "SELECT cmd, MIN(ts) AS debut, MAX(ts) AS fin FROM x_stdout GROUP BY cmd ORDER BY fin DESC";
|
$sql = "SELECT cmd, MIN(ts) AS debut, MAX(ts) AS fin FROM x_stdout GROUP BY cmd ORDER BY fin DESC";
|
||||||
$results = Invoke_infra($sql);
|
$results = Invoke_infra($sql);
|
||||||
|
|
||||||
echo "<div class='row'>";
|
echo "<div class='row'>";
|
||||||
|
|
||||||
// Loop through the results (now very fast, no more queries inside)
|
|
||||||
if (is_array($results)) {
|
if (is_array($results)) {
|
||||||
foreach ($results as $script) {
|
foreach ($results as $script) {
|
||||||
$scriptName = $script['cmd'];
|
$scriptName = $script['cmd'];
|
||||||
$startTime = $script['debut'];
|
$startTime = $script['debut'];
|
||||||
$endTime = $script['fin'];
|
$endTime = $script['fin'];
|
||||||
|
|
||||||
echo "<div class='col-3 mb-3'>";
|
echo "<div class='col-3 mb-3'>";
|
||||||
echo "<a href='StdOut-detail.php?s={$scriptName}&AIX=1&linux=1&DUN=1' class='btn btn-primary btn-lg' role='button'>";
|
echo "<a href='StdOut-detail.php?s=$scriptName&AIX=1&linux=1&DUN=1' class='btn btn-primary btn-lg' role='button'>";
|
||||||
echo "<b>{$scriptName}</b><br><small>{$startTime} --> {$endTime}</small>";
|
echo "<b>$scriptName</b><br><small>$startTime --> $endTime</small>";
|
||||||
echo "</a>";
|
echo "</a>";
|
||||||
echo "</div>";
|
echo "</div>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "</div>";
|
echo "</div>";
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user