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

De WIKI Netnews
Ir para navegação Ir para pesquisar
Sem resumo de edição
Sem resumo de edição
 
(9 revisões intermediárias pelo mesmo usuário não estão sendo mostradas)
Linha 1: Linha 1:
mw.loader.using([], function () {
$(function () {


     function atualizarStatus(host, elementId) {
function formatUptime(seconds) {
         fetch('/noc/status.php?host=' + host)
    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-cloud", "ns1-status");
    atualizarStatus("ns2-cloud", "ns2-status");
}
 
atualizarTodos();
setInterval(atualizarTodos, 30000);
 
});
 
function criarNovoCliente() {
    var nome = prompt("Digite o nome do cliente:");
 
    if (!nome) return;
 
    nome = nome.trim().replace(/\s+/g, "_");
 
    var url = mw.util.getUrl("Cliente/" + nome, {
        action: "edit",
        preload: "Cliente:MODELO"
    });
 
    window.location.href = url;
}
 
document.addEventListener("DOMContentLoaded", function () {
 
    var btn = document.getElementById("btnCriarCliente");
 
    if (!btn) return;
 
    btn.addEventListener("click", function () {
 
        var nome = prompt("Digite o nome do cliente:");
 
        if (!nome) return;
 
        nome = nome.trim().replace(/\s+/g, "_");
 
        var base = mw.config.get("wgScriptPath") + "/index.php/";
 
        var url = base + "Cliente/" + nome + "?action=edit&preload=Cliente:MODELO";
 
        window.location.href = url;
 
    });
 
});
 
document.addEventListener("DOMContentLoaded", function () {
 
    function atualizarStatusServidor(nome) {
 
         fetch('/noc/status.php?host=' + nome.toLowerCase())
             .then(response => response.json())
             .then(response => response.json())
             .then(data => {
             .then(data => {
                 const el = document.getElementById(elementId);
 
                 var el = document.getElementById('status-' + nome);
 
                 if (!el) return;
                 if (!el) return;


                 if (data.status === "online") {
                 if (data.status === "online") {
                     el.innerHTML = "🟢 Operacional";
                     el.innerHTML = "🟢 Operacional<br><small>Uptime: "
                        + formatUptime(data.uptime)
                        + "</small><br><small>Último check: "
                        + data.lastcheck + "</small>";
                 } else if (data.status === "offline") {
                 } else if (data.status === "offline") {
                     el.innerHTML = "🔴 Offline";
                     el.innerHTML = "🔴 Offline<br><small>Último check: "
                        + data.lastcheck + "</small>";
                 } else {
                 } else {
                     el.innerHTML = "🟡 Indefinido";
                     el.innerHTML = "🟡 Indefinido";
                 }
                 }
            })
 
            .catch(() => {
                const el = document.getElementById(elementId);
                if (el) el.innerHTML = "🟡 Erro";
             });
             });
     }
     }


     function atualizarTodos() {
     function formatUptime(seconds) {
         atualizarStatus("web01", "web01-status");
         if (!seconds) return '-';
         atualizarStatus("web02", "web02-status");
 
         atualizarStatus("web03", "web03-status");
         const days = Math.floor(seconds / 86400);
         atualizarStatus("web04", "web04-status");
         const hours = Math.floor((seconds % 86400) / 3600);
        atualizarStatus("ns1", "ns1-status");
         const minutes = Math.floor((seconds % 3600) / 60);
         atualizarStatus("ns2", "ns2-status");
 
         return `${days}d ${hours}h ${minutes}m`;
     }
     }


     $(document).ready(function () {
     // Detecta automaticamente nome do servidor pela URL
         atualizarTodos();
    var pageName = mw.config.get("wgTitle");
        setInterval(atualizarTodos, 30000);
 
     });
    if (pageName.startsWith("WEB") || pageName.startsWith("NS")) {
         atualizarStatusServidor(pageName);
     }


});
});

Edição atual tal como às 19h44min de 20 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-cloud", "ns1-status");
    atualizarStatus("ns2-cloud", "ns2-status");
}

atualizarTodos();
setInterval(atualizarTodos, 30000);

});

function criarNovoCliente() {
    var nome = prompt("Digite o nome do cliente:");

    if (!nome) return;

    nome = nome.trim().replace(/\s+/g, "_");

    var url = mw.util.getUrl("Cliente/" + nome, {
        action: "edit",
        preload: "Cliente:MODELO"
    });

    window.location.href = url;
}

document.addEventListener("DOMContentLoaded", function () {

    var btn = document.getElementById("btnCriarCliente");

    if (!btn) return;

    btn.addEventListener("click", function () {

        var nome = prompt("Digite o nome do cliente:");

        if (!nome) return;

        nome = nome.trim().replace(/\s+/g, "_");

        var base = mw.config.get("wgScriptPath") + "/index.php/";

        var url = base + "Cliente/" + nome + "?action=edit&preload=Cliente:MODELO";

        window.location.href = url;

    });

});

document.addEventListener("DOMContentLoaded", function () {

    function atualizarStatusServidor(nome) {

        fetch('/noc/status.php?host=' + nome.toLowerCase())
            .then(response => response.json())
            .then(data => {

                var el = document.getElementById('status-' + nome);

                if (!el) return;

                if (data.status === "online") {
                    el.innerHTML = "🟢 Operacional<br><small>Uptime: " 
                        + formatUptime(data.uptime) 
                        + "</small><br><small>Último check: " 
                        + data.lastcheck + "</small>";
                } else if (data.status === "offline") {
                    el.innerHTML = "🔴 Offline<br><small>Último check: " 
                        + data.lastcheck + "</small>";
                } else {
                    el.innerHTML = "🟡 Indefinido";
                }

            });
    }

    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`;
    }

    // Detecta automaticamente nome do servidor pela URL
    var pageName = mw.config.get("wgTitle");

    if (pageName.startsWith("WEB") || pageName.startsWith("NS")) {
        atualizarStatusServidor(pageName);
    }

});