Files
Aruba-PoE/srv/poe_manager/templates/logs.html

78 lines
2.7 KiB
HTML

{% extends "base.html" %}
{% block content %}
<h2>Live Log</h2>
<button id="refresh-btn" class="btn btn-success mb-3">
<span style="font-size: 1.2rem; color: white;"></span> Logs aktualisieren
</button>
<div id="log-container">
<div id="log-box"></div>
<div id="refresh-timer">
Nächstes Update in <span id="timer"></span> Sekunden
</div>
</div>
<script>
document.addEventListener("DOMContentLoaded", () => {
const intervalMinutes = {{ interval | int }};
const intervalMilliseconds = intervalMinutes * 60 * 1000;
let lastUpdateTime = Date.now(); // wird nach Log-Auswertung gesetzt
function fetchLog() {
fetch("{{ url_for('get_log') }}")
.then(response => response.text())
.then(data => {
const box = document.getElementById("log-box");
const filteredLines = data
.split("\n")
.filter(line => !line.includes("ist erreichbar!"));
box.innerText = filteredLines.join("\n");
box.scrollTop = box.scrollHeight;
// letzte Separator-Linie finden
let lastSeparatorIndex = -1;
for (let i = filteredLines.length - 1; i >= 0; i--) {
if (filteredLines[i].startsWith("--------------------------------------------------------------------")) {
lastSeparatorIndex = i;
break;
}
}
// ersten Zeitstempel nach Separator nehmen
if (lastSeparatorIndex >= 0 && lastSeparatorIndex + 1 < filteredLines.length) {
const firstLine = filteredLines[lastSeparatorIndex + 1];
const match = firstLine.match(/^(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})/);
if (match) {
lastUpdateTime = new Date(match[1]).getTime();
} else {
lastUpdateTime = Date.now();
}
} else {
lastUpdateTime = Date.now();
}
})
.catch(err => console.error("Fehler beim Laden der Logs:", err));
}
function updateTimer() {
const now = Date.now();
const nextRefresh = lastUpdateTime + intervalMilliseconds;
const remainingMs = nextRefresh - now;
const remainingSec = Math.max(Math.ceil(remainingMs / 1000), 0);
document.getElementById("timer").innerText = remainingSec;
}
document.getElementById("refresh-btn").addEventListener("click", fetchLog);
fetchLog();
setInterval(fetchLog, intervalMilliseconds);
setInterval(updateTimer, 1000);
});
</script>
{% endblock %}