MediaWiki:Common.js: mudanças entre as edições

De WIKI Netnews
Ir para navegação Ir para pesquisar
Sem resumo de edição
Etiqueta: Reversão manual
Sem resumo de edição
Linha 1: Linha 1:
async function atualizarStatus(host, elementId) {
$(function () {
    try {
        const response = await fetch('/noc/status.php?host=' + host);
        const data = await response.json();
        const el = document.getElementById(elementId);


        if (!el) return;
function formatUptime(seconds) {
    if (!seconds) return '-';
 
    var days = Math.floor(seconds / 86400);
    var hours = Math.floor((seconds % 86400) / 3600);
    var minutes = Math.floor((seconds % 3600) / 60);
 
    return days + "d " + hours + "h " + minutes + "m";
}
 
function atualizarStatus(host, elementId) {
 
    $.getJSON('/noc/status.php?host=' + host)
    .done(function(data){


         let html = '';
         var el = $('#' + elementId);
        if (!el.length) return;


         if (data.status === "online") {
         if (data.status === "online") {


             html =
             el.html(
                 '<span style="color:#22c55e;font-weight:600;">● OPERACIONAL</span><br>' +
                 '<span class="status-dot status-green"></span> Operacional<br>' +
                 '<small>Uptime: ' + formatUptime(data.uptime) + '</small><br>' +
                 '<small>Uptime: ' + formatUptime(data.uptime) + '</small><br>' +
                 '<small>Atualizado: ' + formatHora(data.lastcheck) + '</small>';
                 '<small>Último check: ' + data.lastcheck + '</small>'
            );


             el.classList.remove("blink");
             el.removeClass("blink");


         } else if (data.status === "offline") {
         } else if (data.status === "offline") {


             html =
             el.html(
                 '<span style="color:#ef4444;font-weight:600;">● OFFLINE</span><br>' +
                 '<span class="status-dot status-red"></span> Offline<br>' +
                 '<small>Último check: ' + (data.lastcheck || '-') + '</small>';
                 '<small>Último check: ' + (data.lastcheck || '-') + '</small>'
            );


             el.classList.add("blink");
             el.addClass("blink");


         } else {
         } else {


             html =
             el.html('<span class="status-dot status-yellow"></span> Indefinido');
                '<span style="color:#facc15;font-weight:600;">● INDEFINIDO</span>';


            el.classList.remove("blink");
         }
         }


         el.innerHTML = html;
    })
    .fail(function(){
         $('#' + elementId).html("🟡 Erro");
    });


    } catch (e) {
        document.getElementById(elementId).innerHTML =
            '<span style="color:#facc15;">● ERRO</span>';
    }
}
function formatUptime(seconds) {
    if (!seconds || seconds <= 0) return '-';
    const days = Math.floor(seconds / 86400);
    const hours = Math.floor((seconds % 86400) / 3600);
    return days + 'd ' + hours + 'h';
}
function formatHora(datetime) {
    if (!datetime) return '-';
    const partes = datetime.split(' ');
    if (partes.length > 1) {
        return partes[1];
    }
    return datetime;
}
}


Linha 70: Linha 60:
}
}


document.addEventListener("DOMContentLoaded", function () {
atualizarTodos();
    atualizarTodos();
setInterval(atualizarTodos, 30000);
    setInterval(atualizarTodos, 30000);
 
});
});

Edição das 17h51min de 18 de fevereiro de 2026

$(function () {

function formatUptime(seconds) {
    if (!seconds) return '-';

    var days = Math.floor(seconds / 86400);
    var hours = Math.floor((seconds % 86400) / 3600);
    var minutes = Math.floor((seconds % 3600) / 60);

    return days + "d " + hours + "h " + minutes + "m";
}

function atualizarStatus(host, elementId) {

    $.getJSON('/noc/status.php?host=' + host)
    .done(function(data){

        var el = $('#' + elementId);
        if (!el.length) return;

        if (data.status === "online") {

            el.html(
                '<span class="status-dot status-green"></span> Operacional<br>' +
                '<small>Uptime: ' + formatUptime(data.uptime) + '</small><br>' +
                '<small>Último check: ' + data.lastcheck + '</small>'
            );

            el.removeClass("blink");

        } else if (data.status === "offline") {

            el.html(
                '<span class="status-dot status-red"></span> Offline<br>' +
                '<small>Último check: ' + (data.lastcheck || '-') + '</small>'
            );

            el.addClass("blink");

        } else {

            el.html('<span class="status-dot status-yellow"></span> Indefinido');

        }

    })
    .fail(function(){
        $('#' + elementId).html("🟡 Erro");
    });

}

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");
}

atualizarTodos();
setInterval(atualizarTodos, 30000);

});