MediaWiki:Common.js: mudanças entre as edições
Ir para navegação
Ir para pesquisar
Sem resumo de edição |
Sem resumo de edição |
||
| Linha 1: | Linha 1: | ||
async function atualizarStatus(host, elementId) { | |||
try { | |||
const response = await fetch('/noc/status.php?host=' + host); | |||
const data = await response.json(); | |||
const el = document.getElementById(elementId); | |||
if (!el) return; | |||
let html = ''; | |||
el. | |||
if (data.status === "online") { | |||
el. | html = `🟢 Operacional<br> | ||
<small>Uptime: ${formatUptime(data.uptime)}</small><br> | |||
<small>Último check: ${data.lastcheck}</small>`; | |||
el.classList.remove("blink"); | |||
} else if (data.status === "offline") { | |||
html = `🔴 Offline<br> | |||
<small>Último check: ${data.lastcheck ?? '-'}</small>`; | |||
el.classList.add("blink"); | |||
} else { | |||
html = `🟡 Indefinido`; | |||
} | |||
el.innerHTML = html; | |||
} catch (e) { | |||
document.getElementById(elementId).innerHTML = "🟡 Erro"; | |||
} | } | ||
} | |||
function formatUptime(seconds) { | |||
if (!seconds) return '-'; | |||
const days = Math.floor(seconds / 86400); | |||
const hours = Math.floor((seconds % 86400) / 3600); | |||
const minutes = Math.floor((seconds % 3600) / 60); | |||
return `${days}d ${hours}h ${minutes}m`; | |||
} | |||
function atualizarTodos() { | |||
atualizarStatus("web01", "web01-status"); | |||
atualizarStatus("web02", "web02-status"); | |||
atualizarStatus("web03", "web03-status"); | |||
atualizarStatus("web04", "web04-status"); | |||
atualizarStatus("ns1", "ns1-status"); | |||
atualizarStatus("ns2", "ns2-status"); | |||
} | |||
document.addEventListener("DOMContentLoaded", function () { | |||
atualizarTodos(); | |||
setInterval(atualizarTodos, 30000); | |||
}); | }); | ||
Edição das 16h57min de 18 de fevereiro de 2026
async function atualizarStatus(host, elementId) {
try {
const response = await fetch('/noc/status.php?host=' + host);
const data = await response.json();
const el = document.getElementById(elementId);
if (!el) return;
let html = '';
if (data.status === "online") {
html = `🟢 Operacional<br>
<small>Uptime: ${formatUptime(data.uptime)}</small><br>
<small>Último check: ${data.lastcheck}</small>`;
el.classList.remove("blink");
} else if (data.status === "offline") {
html = `🔴 Offline<br>
<small>Último check: ${data.lastcheck ?? '-'}</small>`;
el.classList.add("blink");
} else {
html = `🟡 Indefinido`;
}
el.innerHTML = html;
} catch (e) {
document.getElementById(elementId).innerHTML = "🟡 Erro";
}
}
function formatUptime(seconds) {
if (!seconds) return '-';
const days = Math.floor(seconds / 86400);
const hours = Math.floor((seconds % 86400) / 3600);
const minutes = Math.floor((seconds % 3600) / 60);
return `${days}d ${hours}h ${minutes}m`;
}
function atualizarTodos() {
atualizarStatus("web01", "web01-status");
atualizarStatus("web02", "web02-status");
atualizarStatus("web03", "web03-status");
atualizarStatus("web04", "web04-status");
atualizarStatus("ns1", "ns1-status");
atualizarStatus("ns2", "ns2-status");
}
document.addEventListener("DOMContentLoaded", function () {
atualizarTodos();
setInterval(atualizarTodos, 30000);
});