Fixes the html of agents pages

main
Yasen Pramatarov 2025-01-28 15:54:42 +02:00
parent 779d3e0bf6
commit 6e4657e90f
2 changed files with 111 additions and 110 deletions

View File

@ -3,8 +3,8 @@
<div class="container-fluid mt-2"> <div class="container-fluid mt-2">
<div class="row mb-4"> <div class="row mb-4">
<div class="col-12 mb-4"> <div class="col-12 mb-4">
<h2 class="mb-0">Jilo Agents on platform <?= htmlspecialchars($platform_id) ?> (<?= htmlspecialchars($platformDetails[0]['name']) ?>)</h2> <h2 class="mb-0">Jilo Agents status</h2>
<small>Manage and monitor agents on this platform.</small> <small>manage and monitor agents on platform <?= htmlspecialchars($platform_id) ?> (<?= htmlspecialchars($platformDetails[0]['name']) ?>).</small>
</div> </div>
</div> </div>

View File

@ -1,25 +1,29 @@
<div class="row"> <!-- latest data -->
<div class="card w-auto bg-light border-light card-body" style="flex-direction: row;">Latest data from Jilo Agents</div> <div class="container-fluid mt-2">
<div class="row mb-4">
<div class="col-12 mb-4">
<h2 class="mb-0">Latest data from Jilo Agents</h2>
<small>gathered for platform <?= htmlspecialchars($platform_id) ?> (<?= htmlspecialchars($platformDetails[0]['name']) ?>)</small>
</div>
</div> </div>
<div class="collapse show"> <div class="row">
<div class="mb-5"> <div class="mb-4">
<?php if (!empty($hostsData)) { ?> <?php if (!empty($hostsData)) { ?>
<?php foreach ($hostsData as $host) { ?> <?php foreach ($hostsData as $host) { ?>
<div class="card mb-4"> <div class="card mb-4">
<div class="card-header"> <div class="card-header">
<h5 class="mb-0"> <h5 class="mb-0">
<i class="fas fa-network-wired me-2"></i> <i class="fas fa-network-wired me-2 text-secondary"></i>
<?= htmlspecialchars($host['name']) ?> <?= htmlspecialchars($host['name']) ?><small class="text-muted"> (<?= htmlspecialchars($host['address']) ?>)</small>
<small class="text-muted">(<?= htmlspecialchars($host['address']) ?>)</small>
</h5> </h5>
</div> </div>
<div class="card-body"> <div class="card-body">
<?php foreach ($host['agents'] as $agent) { ?> <?php foreach ($host['agents'] as $agent) { ?>
<div class="mb-4"> <div class="mb-4">
<h6 class="border-bottom pb-2"> <h6 class="border-bottom pb-2">
<i class="fas fa-robot me-2"></i> <i class="fas fa-robot me-2 text-secondary"></i>
<?= htmlspecialchars($agent['name']) ?> agent <?= htmlspecialchars($agent['name']) ?> agent
</h6> </h6>
<table class="table table-results table-striped table-hover table-bordered"> <table class="table table-results table-striped table-hover table-bordered">
@ -29,83 +33,79 @@
<th> <th>
Latest value Latest value
<br> <br>
<small class="text-muted"> <small class="text-muted"><?= date('d M Y H:i:s', strtotime($agent['timestamp'])) ?></small>
<?= date('d M Y H:i:s', strtotime($agent['timestamp'])) ?>
</small>
</th> </th>
<th> <th>
Previous value Previous value
<?php <?php
// Find first metric with previous data to get timestamp // Find first metric with previous data to get timestamp
$prevTimestamp = null; $prevTimestamp = null;
foreach ($metrics as $m_section => $m_metrics) { foreach ($metrics as $m_section => $m_metrics) {
foreach ($m_metrics as $m_metric => $m_config) { foreach ($m_metrics as $m_metric => $m_config) {
if (isset($agent['metrics'][$m_section][$m_metric]['previous'])) { if (isset($agent['metrics'][$m_section][$m_metric]['previous'])) {
$prevTimestamp = $agent['metrics'][$m_section][$m_metric]['previous']['timestamp']; $prevTimestamp = $agent['metrics'][$m_section][$m_metric]['previous']['timestamp'];
break 2; break 2;
} }
} }
} }
if ($prevTimestamp) { ?> if ($prevTimestamp) { ?>
<br> <br>
<small class="text-muted"> <small class="text-muted"><?= date('d M Y H:i:s', strtotime($prevTimestamp)) ?></small>
<?= date('d M Y H:i:s', strtotime($prevTimestamp)) ?> <?php } ?>
</small>
<?php } ?>
</th> </th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php foreach ($metrics as $section => $section_metrics) { ?> <?php foreach ($metrics as $section => $section_metrics) { ?>
<?php <?php
// Check if this section has any data for this agent // Check if this section has any data for this agent
$hasData = false; $hasData = false;
foreach ($section_metrics as $metric => $metricConfig) { foreach ($section_metrics as $metric => $metricConfig) {
if (isset($agent['metrics'][$section][$metric])) { if (isset($agent['metrics'][$section][$metric])) {
$hasData = true; $hasData = true;
break; break;
} }
} }
if (!$hasData) continue; if (!$hasData) continue;
?> ?>
<tr class="table-secondary"> <tr class="table-secondary">
<th colspan="3"><?= htmlspecialchars($section) ?></th> <th colspan="3"><?= htmlspecialchars($section) ?></th>
</tr> </tr>
<?php foreach ($section_metrics as $metric => $metricConfig) { ?> <?php foreach ($section_metrics as $metric => $metricConfig) { ?>
<?php if (isset($agent['metrics'][$section][$metric])) { <?php if (isset($agent['metrics'][$section][$metric])) {
$metric_data = $agent['metrics'][$section][$metric]; $metric_data = $agent['metrics'][$section][$metric];
?> ?>
<tr> <tr>
<td><?= htmlspecialchars($metricConfig['label']) ?></td> <td><?= htmlspecialchars($metricConfig['label']) ?></td>
<td> <td>
<?php if ($metric_data['link']) { ?> <?php if ($metric_data['link']) { ?>
<a href="<?= htmlspecialchars($app_root) ?>?platform=<?= htmlspecialchars($platform_id) ?>&page=<?= htmlspecialchars($metric_data['link']) ?>&from_time=<?= htmlspecialchars($metric_data['latest']['timestamp']) ?>&until_time=<?= htmlspecialchars($metric_data['latest']['timestamp']) ?>"><?= htmlspecialchars($metric_data['latest']['value']) ?></a> <a href="<?= htmlspecialchars($app_root) ?>?platform=<?= htmlspecialchars($platform_id) ?>&page=<?= htmlspecialchars($metric_data['link']) ?>&from_time=<?= htmlspecialchars($metric_data['latest']['timestamp']) ?>&until_time=<?= htmlspecialchars($metric_data['latest']['timestamp']) ?>"><?= htmlspecialchars($metric_data['latest']['value']) ?></a>
<?php } else { ?> <?php } else { ?>
<?= htmlspecialchars($metric_data['latest']['value']) ?> <?= htmlspecialchars($metric_data['latest']['value']) ?>
<?php } ?> <?php } ?>
</td> </td>
<td> <td>
<?php if ($metric_data['previous']) { ?> <?php if ($metric_data['previous']) { ?>
<?php if ($metric_data['link']) { ?> <?php if ($metric_data['link']) { ?>
<a href="<?= htmlspecialchars($app_root) ?>?platform=<?= htmlspecialchars($platform_id) ?>&page=<?= htmlspecialchars($metric_data['link']) ?>&from_time=<?= htmlspecialchars($metric_data['previous']['timestamp']) ?>&until_time=<?= htmlspecialchars($metric_data['previous']['timestamp']) ?>"><?= htmlspecialchars($metric_data['previous']['value']) ?></a> <a href="<?= htmlspecialchars($app_root) ?>?platform=<?= htmlspecialchars($platform_id) ?>&page=<?= htmlspecialchars($metric_data['link']) ?>&from_time=<?= htmlspecialchars($metric_data['previous']['timestamp']) ?>&until_time=<?= htmlspecialchars($metric_data['previous']['timestamp']) ?>"><?= htmlspecialchars($metric_data['previous']['value']) ?></a>
<?php } else { ?> <?php } else { ?>
<?= htmlspecialchars($metric_data['previous']['value']) ?> <?= htmlspecialchars($metric_data['previous']['value']) ?>
<?php } ?> <?php } ?>
<?php } else { ?> <?php } else { ?>
<span class="text-muted">No previous data</span> <span class="text-muted">No previous data</span>
<?php } ?> <?php } ?>
</td> </td>
</tr> </tr>
<?php } ?> <?php } ?>
<?php } ?> <?php } ?>
<?php } ?> <?php } ?>
</tbody> </tbody>
</table> </table>
</div> </div>
<?php } ?> <?php } ?>
</div> </div>
</div> </div>
<?php } ?> <?php } ?>
<?php } else { ?> <?php } else { ?>
<div class="alert alert-info m-3" role="alert"> <div class="alert alert-info m-3" role="alert">
No data available from any agents. Please check agent configuration and connectivity. No data available from any agents. Please check agent configuration and connectivity.
@ -113,4 +113,5 @@
<?php } ?> <?php } ?>
</div> </div>
</div> </div>
</div>
<!-- /latest data --> <!-- /latest data -->