Adds agent status check button
parent
daf41efa4c
commit
ed9ce2bb07
|
@ -22,11 +22,13 @@
|
||||||
// print_r($_SESSION);
|
// print_r($_SESSION);
|
||||||
?>
|
?>
|
||||||
<?php if (isset($_SESSION["agent{$agent['id']}_cache"])) { ?>
|
<?php if (isset($_SESSION["agent{$agent['id']}_cache"])) { ?>
|
||||||
|
<button id="agent<?= htmlspecialchars($agent['id']) ?>-status" class="btn btn-primary" data-toggle="tooltip" data-trigger="hover" data-placement="bottom" title="get the agent status" onclick="fetchData('<?= htmlspecialchars($agent['id']) ?>', '<?= htmlspecialchars($agent['url']) ?>', '/status', '<?= htmlspecialchars($jwt) ?>', true)">get status</button>
|
||||||
<button id="agent<?= htmlspecialchars($agent['id']) ?>-fetch" class="btn btn-primary" data-toggle="tooltip" data-trigger="hover" data-placement="bottom" title="get data from the agent" onclick="fetchData('<?= htmlspecialchars($agent['id']) ?>', '<?= htmlspecialchars($agent['url']) ?>', '<?= htmlspecialchars($agent['agent_endpoint']) ?>', '<?= htmlspecialchars($jwt) ?>', true)">fetch data</button>
|
<button id="agent<?= htmlspecialchars($agent['id']) ?>-fetch" class="btn btn-primary" data-toggle="tooltip" data-trigger="hover" data-placement="bottom" title="get data from the agent" onclick="fetchData('<?= htmlspecialchars($agent['id']) ?>', '<?= htmlspecialchars($agent['url']) ?>', '<?= htmlspecialchars($agent['agent_endpoint']) ?>', '<?= htmlspecialchars($jwt) ?>', true)">fetch data</button>
|
||||||
<button id="agent<?= htmlspecialchars($agent['id']) ?>-cache" class="btn btn-secondary" data-toggle="tooltip" data-trigger="hover" data-placement="bottom" title="load cache" onclick="loadCache('<?= htmlspecialchars($agent['id']) ?>')">load cache</button>
|
<button id="agent<?= htmlspecialchars($agent['id']) ?>-cache" class="btn btn-secondary" data-toggle="tooltip" data-trigger="hover" data-placement="bottom" title="load cache" onclick="loadCache('<?= htmlspecialchars($agent['id']) ?>')">load cache</button>
|
||||||
<button id="agent<?= htmlspecialchars($agent['id']) ?>-clear" class="btn btn-danger" data-toggle="tooltip" data-trigger="hover" data-placement="bottom" title="clear cache" onclick="clearCache('<?= htmlspecialchars($agent['id']) ?>')">clear cache</button>
|
<button id="agent<?= htmlspecialchars($agent['id']) ?>-clear" class="btn btn-danger" data-toggle="tooltip" data-trigger="hover" data-placement="bottom" title="clear cache" onclick="clearCache('<?= htmlspecialchars($agent['id']) ?>')">clear cache</button>
|
||||||
<span id="cacheInfo<?= htmlspecialchars($agent['id']) ?>" style="margin: 5px 0;"></span>
|
<span id="cacheInfo<?= htmlspecialchars($agent['id']) ?>" style="margin: 5px 0;"></span>
|
||||||
<?php } else { ?>
|
<?php } else { ?>
|
||||||
|
<button id="agent<?= htmlspecialchars($agent['id']) ?>-status" class="btn btn-primary" data-toggle="tooltip" data-trigger="hover" data-placement="bottom" title="get the agent status" onclick="fetchData('<?= htmlspecialchars($agent['id']) ?>', '<?= htmlspecialchars($agent['url']) ?>', '/status', '<?= htmlspecialchars($jwt) ?>', true)">get status</button>
|
||||||
<button id="agent<?= htmlspecialchars($agent['id']) ?>-fetch" class="btn btn-primary" data-toggle="tooltip" data-trigger="hover" data-placement="bottom" title="get data from the agent" onclick="fetchData('<?= htmlspecialchars($agent['id']) ?>', '<?= htmlspecialchars($agent['url']) ?>', '<?= htmlspecialchars($agent['agent_endpoint']) ?>', '<?= htmlspecialchars($jwt) ?>')">fetch data</button>
|
<button id="agent<?= htmlspecialchars($agent['id']) ?>-fetch" class="btn btn-primary" data-toggle="tooltip" data-trigger="hover" data-placement="bottom" title="get data from the agent" onclick="fetchData('<?= htmlspecialchars($agent['id']) ?>', '<?= htmlspecialchars($agent['url']) ?>', '<?= htmlspecialchars($agent['agent_endpoint']) ?>', '<?= htmlspecialchars($jwt) ?>')">fetch data</button>
|
||||||
<button style="display: none" disabled id="agent<?= htmlspecialchars($agent['id']) ?>-cache" class="btn btn-secondary" data-toggle="tooltip" data-trigger="hover" data-placement="bottom" title="load cache" onclick="loadCache('<?= htmlspecialchars($agent['id']) ?>')">load cache</button>
|
<button style="display: none" disabled id="agent<?= htmlspecialchars($agent['id']) ?>-cache" class="btn btn-secondary" data-toggle="tooltip" data-trigger="hover" data-placement="bottom" title="load cache" onclick="loadCache('<?= htmlspecialchars($agent['id']) ?>')">load cache</button>
|
||||||
<button style="display: none" disabled id="agent<?= htmlspecialchars($agent['id']) ?>-clear" class="btn btn-danger" data-toggle="tooltip" data-trigger="hover" data-placement="bottom" title="clear cache" onclick="clearCache('<?= htmlspecialchars($agent['id']) ?>')">clear cache</button>
|
<button style="display: none" disabled id="agent<?= htmlspecialchars($agent['id']) ?>-clear" class="btn btn-danger" data-toggle="tooltip" data-trigger="hover" data-placement="bottom" title="clear cache" onclick="clearCache('<?= htmlspecialchars($agent['id']) ?>')">clear cache</button>
|
||||||
|
|
|
@ -58,24 +58,27 @@ function fetchData(agent_id, url, endpoint, jwtToken, force = false) {
|
||||||
// show the result in the html
|
// show the result in the html
|
||||||
resultElement.innerHTML = JSON.stringify(result, null, 2);
|
resultElement.innerHTML = JSON.stringify(result, null, 2);
|
||||||
|
|
||||||
// get the cache timestamp from the session
|
// we don't cache the /status
|
||||||
const now = Date.now();
|
if (endpoint !== '/status') {
|
||||||
const cacheTimestamp = new Date(now);
|
// get the cache timestamp from the session
|
||||||
|
const now = Date.now();
|
||||||
|
const cacheTimestamp = new Date(now);
|
||||||
|
|
||||||
// display the cache retrieval date and time
|
// display the cache retrieval date and time
|
||||||
const formattedDate = cacheTimestamp.toLocaleDateString();
|
const formattedDate = cacheTimestamp.toLocaleDateString();
|
||||||
const formattedTime = cacheTimestamp.toLocaleTimeString();
|
const formattedTime = cacheTimestamp.toLocaleTimeString();
|
||||||
cacheInfoElement.style.display = '';
|
cacheInfoElement.style.display = '';
|
||||||
cacheInfoElement.innerHTML = `cache refreshed on ${formattedDate} at ${formattedTime}`;
|
cacheInfoElement.innerHTML = `cache refreshed on ${formattedDate} at ${formattedTime}`;
|
||||||
|
|
||||||
// show the cache buttons
|
// show the cache buttons
|
||||||
loadCacheButton.disabled = false;
|
loadCacheButton.disabled = false;
|
||||||
loadCacheButton.style.display = '';
|
loadCacheButton.style.display = '';
|
||||||
clearCacheButton.disabled = false;
|
clearCacheButton.disabled = false;
|
||||||
clearCacheButton.style.display = '';
|
clearCacheButton.style.display = '';
|
||||||
|
|
||||||
// send the result to PHP to store in session
|
// send the result to PHP to store in session
|
||||||
saveResultToSession(result, agent_id);
|
saveResultToSession(result, agent_id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// Display the error
|
// Display the error
|
||||||
|
|
Loading…
Reference in New Issue