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:
@@ -145,7 +145,7 @@
|
|||||||
|
|
||||||
// Backup OK
|
// 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");
|
$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");
|
||||||
$total = count($answers);
|
$total = is_countable($answers) ? count($answers) : 0;
|
||||||
foreach ($answers as $row) {
|
foreach ($answers as $row) {
|
||||||
$date1 = date_create($row['LastKnownGood']); $diff = date_diff($date1, date_create(date("Y-m-d")));
|
$date1 = date_create($row['LastKnownGood']); $diff = date_diff($date1, date_create(date("Y-m-d")));
|
||||||
if(date('w') >= 2 && date('w') <= 6 ){
|
if(date('w') >= 2 && date('w') <= 6 ){
|
||||||
|
|||||||
@@ -45,7 +45,7 @@
|
|||||||
<div class="row">
|
<div class="row">
|
||||||
<?php
|
<?php
|
||||||
// =================================================================
|
// =================================================================
|
||||||
// STEP 1: Fetch all required data with minimal database queries (MSSQL SYNTAX)
|
// STEP 1: Fetch all required data with minimal database queries
|
||||||
// =================================================================
|
// =================================================================
|
||||||
|
|
||||||
// Query 1: Get aggregated data for all clusters at once.
|
// Query 1: Get aggregated data for all clusters at once.
|
||||||
@@ -198,8 +198,8 @@
|
|||||||
$p2 = ($total_vms > 0) ? ($owner2_count / $total_vms) * 100 : 0;
|
$p2 = ($total_vms > 0) ? ($owner2_count / $total_vms) * 100 : 0;
|
||||||
|
|
||||||
$vm_dist_html = "<div class='progress' style='border: 2px solid grey; height: 20px;'>
|
$vm_dist_html = "<div class='progress' style='border: 2px solid grey; height: 20px;'>
|
||||||
<div class='progress-bar text-white' role='progressbar' style='width:$p1%'><b>$owner1_name: $owner1_count</b></div>
|
<div class='progress-bar text-white' role='progressbar' style='width:$p1%'><b>$owner1_name</b></div>
|
||||||
<div class='progress-bar bg-info text-dark' role='progressbar' style='width:$p2%'><b>$owner2_name: $owner2_count</b></div>
|
<div class='progress-bar bg-info text-dark' role='progressbar' style='width:$p2%'><b>$owner2_name</b></div>
|
||||||
</div>";
|
</div>";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,3 +117,4 @@
|
|||||||
</body>
|
</body>
|
||||||
<script src="/js/switch.js"></script>
|
<script src="/js/switch.js"></script>
|
||||||
</HTML>
|
</HTML>
|
||||||
|
<script src="/js/tableResize.js"></script>
|
||||||
@@ -67,7 +67,10 @@
|
|||||||
</div>
|
</div>
|
||||||
<!-- TABLE -->
|
<!-- TABLE -->
|
||||||
<div>
|
<div>
|
||||||
<?php // DATA
|
<?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'])) {
|
||||||
@@ -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";
|
$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;
|
||||||
#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">
|
<form class="row">
|
||||||
<div class="col border rounded">
|
<div class="col border rounded">
|
||||||
<b>Filters : </b>
|
<b>Filters : </b>
|
||||||
<div class="form-check form-check-inline form-switch">
|
<div class="form-check form-check-inline form-switch">
|
||||||
<input class="form-check-input" type="checkbox" role="switch" id="AIX" <?php echo $aix; ?>
|
<input class="form-check-input" type="checkbox" role="switch" id="AIX" <?php echo $aix; ?> name="AIX" value="1">
|
||||||
name="AIX" value="1">
|
|
||||||
<label class="form-check-label" for="AIX">AIX</label>
|
<label class="form-check-label" for="AIX">AIX</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-check form-check-inline form-switch">
|
<div class="form-check form-check-inline form-switch">
|
||||||
<input class="form-check-input" type="checkbox" role="switch" id="linux" <?php echo $linux; ?>
|
<input class="form-check-input" type="checkbox" role="switch" id="linux" <?php echo $linux; ?> name="linux" value="1">
|
||||||
name="linux" value="1">
|
|
||||||
<label class="form-check-label" for="linux">Linux</label>
|
<label class="form-check-label" for="linux">Linux</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
|
||||||
<div class="form-check form-check-inline form-switch">
|
<div class="form-check form-check-inline form-switch">
|
||||||
<input class="form-check-input" type="checkbox" role="switch" id="DUN" <?php echo $dun; ?>
|
<input class="form-check-input" type="checkbox" role="switch" id="DUN" <?php echo $dun; ?> name="DUN" value="1">
|
||||||
name="DUN" value="1">
|
|
||||||
<label class="form-check-label" for="DUN">DMV/DUN/MDK</label>
|
<label class="form-check-label" for="DUN">DMV/DUN/MDK</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-check form-check-inline form-switch">
|
<div class="form-check form-check-inline form-switch">
|
||||||
<input class="form-check-input" type="checkbox" role="switch" id="AZT" <?php echo $azt; ?>
|
<input class="form-check-input" type="checkbox" role="switch" id="AZT" <?php echo $azt; ?> name="AZT" value="1">
|
||||||
name="AZT" value="1">
|
|
||||||
<label class="form-check-label" for="AZT">Azure</label>
|
<label class="form-check-label" for="AZT">Azure</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-check form-check-inline form-switch">
|
<div class="form-check form-check-inline form-switch">
|
||||||
<input class="form-check-input" type="checkbox" role="switch" id="other" <?php echo $other; ?>
|
<input class="form-check-input" type="checkbox" role="switch" id="other" <?php echo $other; ?> name="other" value="1">
|
||||||
name="other" value="1">
|
|
||||||
<label class="form-check-label" for="other">Other</label>
|
<label class="form-check-label" for="other">Other</label>
|
||||||
</div>
|
</div>
|
||||||
<input type="hidden" name="s" value="<?php echo $script; ?>">
|
<input type="hidden" name="s" value="<?php echo $script; ?>">
|
||||||
@@ -164,55 +190,58 @@
|
|||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
|
||||||
<table class='table table-bordered table-hover table-sm' id='t1' data-height="620" data-toggle="table"
|
<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">
|
||||||
data-search="true" data-show-columns="true" data-export-types="['xlsx','csv','json']"
|
<thead> <tr>
|
||||||
data-show-export="true" data-sortable="true" data-sort-name="vm">
|
|
||||||
<thead> <!-- Header -->
|
|
||||||
<tr>
|
|
||||||
<th data-field='host' data-sortable='true'>Host</th>
|
<th data-field='host' data-sortable='true'>Host</th>
|
||||||
<th data-field='OS' data-sortable='true'>OS</th>
|
<th data-field='OS' data-sortable='true'>OS</th>
|
||||||
<th data-field='TimeStamp' data-sortable='true'>TimeStamp</th>
|
<th data-field='TimeStamp' data-sortable='true'>TimeStamp</th>
|
||||||
<th data-field='RC' data-sortable='true'>RC</th>
|
<th data-field='RC' data-sortable='true'>RC</th>
|
||||||
<th data-field='Result' data-sortable='true'>StdOut</th>
|
<th data-field='Result' data-sortable='true'>StdOut</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
</thead>
|
</thead>
|
||||||
|
<tbody> <?php
|
||||||
<tbody> <!-- Body -->
|
// =================================================================
|
||||||
<?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']);
|
||||||
if (strtoupper($h['OS_TYPE']) == "AIX") {
|
|
||||||
|
// Comptage initial
|
||||||
|
if ($os == "AIX") {
|
||||||
$taix++;
|
$taix++;
|
||||||
} else {
|
} else {
|
||||||
$tlinux++;
|
$tlinux++;
|
||||||
}
|
}
|
||||||
$answer = Invoke_infra("SELECT * FROM x_stdout where cmd ='$script' and host ='$host'");
|
|
||||||
if (is_array($answer)) {
|
// Récupération des résultats depuis notre tableau, SANS requête !
|
||||||
$rc = $answer[0]['rc'];
|
$answer = $resultsByHost[$host] ?? null; // Utilise l'opérateur null coalescent
|
||||||
$stdout = $answer[0]['stdout'];
|
|
||||||
$ts = $answer[0]['ts'];
|
if ($answer) {
|
||||||
if (strtoupper($h['OS_TYPE']) == "AIX") {
|
$rc = $answer['rc'];
|
||||||
|
$stdout = $answer['stdout'];
|
||||||
|
$ts = $answer['ts'];
|
||||||
|
|
||||||
|
// Comptage des status OK/KO
|
||||||
|
if ($os == "AIX") {
|
||||||
if ($rc == 0 && (string)$rc <> "") {
|
if ($rc == 0 && (string)$rc <> "") {
|
||||||
$aixok++;
|
$aixok++;
|
||||||
} else {
|
} elseif ((string)$rc <> "") {
|
||||||
if ((string)$rc <> "") {
|
$aixko++;
|
||||||
$aixko++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else { // Linux
|
||||||
if ($rc == 0 && (string)$rc <> "") {
|
if ($rc == 0 && (string)$rc <> "") {
|
||||||
$linuxok++;
|
$linuxok++;
|
||||||
} else {
|
} elseif ((string)$rc <> "") {
|
||||||
if ((string)$rc <> "") {
|
$linuxko++;
|
||||||
$linuxko++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} 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>";
|
||||||
@@ -231,12 +260,14 @@
|
|||||||
</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>";
|
||||||
echo "<span class='badge bg-success'>$aixok</span> <span class='badge bg-danger'>$aixko</span> <span class='badge bg-secondary'>$aixNO</span></div>";
|
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 "<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>
|
||||||
</div>
|
</div>
|
||||||
<!-- End of main content -->
|
<!-- End of main content -->
|
||||||
|
|||||||
29
X/StdOut.php
29
X/StdOut.php
@@ -63,16 +63,29 @@
|
|||||||
</div>
|
</div>
|
||||||
<!-- TABLE -->
|
<!-- TABLE -->
|
||||||
<div>
|
<div>
|
||||||
<?php // DATA
|
<?php // DATA OPTIMIZED
|
||||||
$answers = Invoke_infra("SELECT distinct(cmd),max(ts) from x_stdout group by cmd order by max(ts) desc");
|
|
||||||
echo "<div class='row'>";
|
|
||||||
foreach($answers as $cmd){
|
|
||||||
$ts = Invoke_infra("SELECT max(ts) as fin, min(ts) as debut FROM x_stdout where cmd = '".$cmd['cmd']."'");
|
|
||||||
echo "<div class='col-3 mb-3'><a href='StdOut-detail.php?s=".$cmd['cmd']."&AIX=1&linux=1&DUN=1' class='btn btn-primary btn-lg' role='button'>";
|
|
||||||
echo "<b>".$cmd['cmd']."</b><br><small>".$ts[0]['debut']." --> ".$ts[0]['fin']."</small>";
|
|
||||||
echo "</a></div> ";
|
|
||||||
|
|
||||||
|
// 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";
|
||||||
|
$results = Invoke_infra($sql);
|
||||||
|
|
||||||
|
echo "<div class='row'>";
|
||||||
|
|
||||||
|
// Loop through the results (now very fast, no more queries inside)
|
||||||
|
if (is_array($results)) {
|
||||||
|
foreach ($results as $script) {
|
||||||
|
$scriptName = $script['cmd'];
|
||||||
|
$startTime = $script['debut'];
|
||||||
|
$endTime = $script['fin'];
|
||||||
|
|
||||||
|
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 "<b>{$scriptName}</b><br><small>{$startTime} --> {$endTime}</small>";
|
||||||
|
echo "</a>";
|
||||||
|
echo "</div>";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "</div>";
|
echo "</div>";
|
||||||
?>
|
?>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -115,7 +115,7 @@
|
|||||||
<i class="fs-6 bi bi-pc text-white"></i> <span class="ms-1 d-none d-sm-inline text-white h7">Clusters</span><i class="bi bi-caret-down"></i> </a>
|
<i class="fs-6 bi bi-pc text-white"></i> <span class="ms-1 d-none d-sm-inline text-white h7">Clusters</span><i class="bi bi-caret-down"></i> </a>
|
||||||
<ul class="collapse nav flex-column ms-1" id="cluster" data-bs-parent="#menu">
|
<ul class="collapse nav flex-column ms-1" id="cluster" data-bs-parent="#menu">
|
||||||
<li class="w-100">
|
<li class="w-100">
|
||||||
<a href="/Inventory/clusterresource.php" class="nav-link px-0" target="_blank"> <span class="d-none d-sm-inline text-white h7">- Cluster Ressources</span></a>
|
<a href="/Inventory/ClusterResource.php" class="nav-link px-0" target="_blank"> <span class="d-none d-sm-inline text-white h7">- Cluster Ressources</span></a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
|||||||
Reference in New Issue
Block a user