Optimize database queries, add resilience with is_countable, refine UI for progress bars and tables, update scripts for dynamic resizing, and correct navbar link case sensitivity.
This commit is contained in:
@@ -67,7 +67,10 @@
|
||||
</div>
|
||||
<!-- TABLE -->
|
||||
<div>
|
||||
<?php // DATA
|
||||
<?php
|
||||
// =================================================================
|
||||
// ETAPE 1: Récupérer la liste des serveurs (inchangé)
|
||||
// =================================================================
|
||||
$aix = $linux = $dun = $azt = $other = "Checked";
|
||||
$where = " and OS_TYPE IN (";
|
||||
if (isset($_GET['AIX'])) {
|
||||
@@ -123,39 +126,62 @@
|
||||
$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);
|
||||
|
||||
// Initialisation des compteurs
|
||||
$taix = $aixok = $aixko = $tlinux = $linuxok = $linuxko = 0;
|
||||
#print_r($hosts);
|
||||
$resultsByHost = []; // Tableau pour stocker les résultats par host
|
||||
|
||||
// =================================================================
|
||||
// ETAPE 2: Récupérer TOUS les résultats en une seule requête
|
||||
// =================================================================
|
||||
if (!empty($hosts)) {
|
||||
// Créer une liste de noms de serveurs pour la clause IN
|
||||
$hostnames = array_map(function ($h) {
|
||||
// Important: échapper les noms pour éviter l'injection SQL
|
||||
return "'" . strtoupper($h['HOSTNAME']) . "'";
|
||||
}, $hosts);
|
||||
$hostnamesList = implode(',', $hostnames);
|
||||
|
||||
// La deuxième et dernière requête SQL
|
||||
$sqlResults = "SELECT * FROM x_stdout WHERE cmd = '$script' AND host IN ($hostnamesList)";
|
||||
$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)) {
|
||||
foreach ($allAnswers as $answer) {
|
||||
$resultsByHost[strtoupper($answer['host'])] = $answer;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
<form class="row">
|
||||
<div class="col border rounded">
|
||||
<b>Filters : </b>
|
||||
<div class="form-check form-check-inline form-switch">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="AIX" <?php echo $aix; ?>
|
||||
name="AIX" value="1">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="AIX" <?php echo $aix; ?> name="AIX" value="1">
|
||||
<label class="form-check-label" for="AIX">AIX</label>
|
||||
</div>
|
||||
|
||||
<div class="form-check form-check-inline form-switch">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="linux" <?php echo $linux; ?>
|
||||
name="linux" value="1">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="linux" <?php echo $linux; ?> name="linux" value="1">
|
||||
<label class="form-check-label" for="linux">Linux</label>
|
||||
</div>
|
||||
|
|
||||
<div class="form-check form-check-inline form-switch">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="DUN" <?php echo $dun; ?>
|
||||
name="DUN" value="1">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="DUN" <?php echo $dun; ?> name="DUN" value="1">
|
||||
<label class="form-check-label" for="DUN">DMV/DUN/MDK</label>
|
||||
</div>
|
||||
|
||||
<div class="form-check form-check-inline form-switch">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="AZT" <?php echo $azt; ?>
|
||||
name="AZT" value="1">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="AZT" <?php echo $azt; ?> name="AZT" value="1">
|
||||
<label class="form-check-label" for="AZT">Azure</label>
|
||||
</div>
|
||||
|
||||
<div class="form-check form-check-inline form-switch">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="other" <?php echo $other; ?>
|
||||
name="other" value="1">
|
||||
<input class="form-check-input" type="checkbox" role="switch" id="other" <?php echo $other; ?> name="other" value="1">
|
||||
<label class="form-check-label" for="other">Other</label>
|
||||
</div>
|
||||
<input type="hidden" name="s" value="<?php echo $script; ?>">
|
||||
@@ -164,55 +190,58 @@
|
||||
</form>
|
||||
|
||||
|
||||
<table class='table table-bordered table-hover table-sm' id='t1' data-height="620" data-toggle="table"
|
||||
data-search="true" data-show-columns="true" data-export-types="['xlsx','csv','json']"
|
||||
data-show-export="true" data-sortable="true" data-sort-name="vm">
|
||||
<thead> <!-- Header -->
|
||||
<tr>
|
||||
<table class='table table-bordered table-hover table-sm' id='t1' data-height="620" data-toggle="table" data-search="true" data-show-columns="true" data-export-types="['xlsx','csv','json']" data-show-export="true" data-sortable="true" data-sort-name="vm">
|
||||
<thead> <tr>
|
||||
<th data-field='host' data-sortable='true'>Host</th>
|
||||
<th data-field='OS' data-sortable='true'>OS</th>
|
||||
<th data-field='TimeStamp' data-sortable='true'>TimeStamp</th>
|
||||
<th data-field='RC' data-sortable='true'>RC</th>
|
||||
<th data-field='Result' data-sortable='true'>StdOut</th>
|
||||
</tr>
|
||||
|
||||
</thead>
|
||||
|
||||
<tbody> <!-- Body -->
|
||||
<?php
|
||||
<tbody> <?php
|
||||
// =================================================================
|
||||
// ETAPE 4: Boucle pour afficher les données (maintenant très rapide)
|
||||
// =================================================================
|
||||
foreach ($hosts as $h) {
|
||||
$host = strtoupper($h['HOSTNAME']);
|
||||
$os = strtoupper($h['OS_TYPE']);
|
||||
if (strtoupper($h['OS_TYPE']) == "AIX") {
|
||||
|
||||
// Comptage initial
|
||||
if ($os == "AIX") {
|
||||
$taix++;
|
||||
} else {
|
||||
$tlinux++;
|
||||
}
|
||||
$answer = Invoke_infra("SELECT * FROM x_stdout where cmd ='$script' and host ='$host'");
|
||||
if (is_array($answer)) {
|
||||
$rc = $answer[0]['rc'];
|
||||
$stdout = $answer[0]['stdout'];
|
||||
$ts = $answer[0]['ts'];
|
||||
if (strtoupper($h['OS_TYPE']) == "AIX") {
|
||||
|
||||
// Récupération des résultats depuis notre tableau, SANS requête !
|
||||
$answer = $resultsByHost[$host] ?? null; // Utilise l'opérateur null coalescent
|
||||
|
||||
if ($answer) {
|
||||
$rc = $answer['rc'];
|
||||
$stdout = $answer['stdout'];
|
||||
$ts = $answer['ts'];
|
||||
|
||||
// Comptage des status OK/KO
|
||||
if ($os == "AIX") {
|
||||
if ($rc == 0 && (string)$rc <> "") {
|
||||
$aixok++;
|
||||
} else {
|
||||
if ((string)$rc <> "") {
|
||||
$aixko++;
|
||||
}
|
||||
} elseif ((string)$rc <> "") {
|
||||
$aixko++;
|
||||
}
|
||||
} else {
|
||||
} else { // Linux
|
||||
if ($rc == 0 && (string)$rc <> "") {
|
||||
$linuxok++;
|
||||
} else {
|
||||
if ((string)$rc <> "") {
|
||||
$linuxko++;
|
||||
}
|
||||
} elseif ((string)$rc <> "") {
|
||||
$linuxko++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Si aucun résultat n'a été trouvé pour ce host
|
||||
$rc = $stdout = $ts = "";
|
||||
}
|
||||
|
||||
// Affichage du tableau HTML (inchangé)
|
||||
echo "<tr><td><b>$host</b></td>";
|
||||
echo "<td>$os</td>";
|
||||
echo "<td>" . $ts . "</td>";
|
||||
@@ -231,12 +260,14 @@
|
||||
</tbody>
|
||||
<br>
|
||||
<?php
|
||||
// Calcul et affichage final des totaux (inchangé)
|
||||
$aixNO = $taix - $aixok - $aixko;
|
||||
$linuxNO = $tlinux - $linuxok - $linuxko;
|
||||
echo "<div class='row'><div class='col text-center h4'><b>$taix AIX : </b>";
|
||||
echo "<span class='badge bg-success'>$aixok</span> <span class='badge bg-danger'>$aixko</span> <span class='badge bg-secondary'>$aixNO</span></div>";
|
||||
echo "<div class='col text-center h4'><b>$tlinux Linux : </b>";
|
||||
echo "<span class='badge bg-success'>$linuxok</span> <span class='badge bg-danger'>$linuxko</span> <span class='badge bg-secondary'>$linuxNO</span></div></div> "; ?>
|
||||
echo "<span class='badge bg-success'>$linuxok</span> <span class='badge bg-danger'>$linuxko</span> <span class='badge bg-secondary'>$linuxNO</span></div></div> ";
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<!-- End of main content -->
|
||||
|
||||
Reference in New Issue
Block a user