current.js 3.96 KB
queryCurrentInfo();
setInterval("queryCurrentInfo()", 180000);

function queryCurrentInfo() {
    removePopoverDiv();

    $.ajax({
        url : getUrlBasePath() + "/dns_monitor/current",
        type: "get",
        dataType: "json",
        success : function(data) {
            var dataObj =eval("(" + data + ")");
            updateTimePanel(dataObj.updateTime);
            updateDNSView(eval(dataObj.dnsMonitorInfo));
            $(function () {
                $("[data-toggle='popover']").popover();
            });
        },
        error: function(e) {

        }
    });
}

function updateDNSView(data) {

    var html = "<table class='table table-bordered mb30' valign='middle'><tbody>";

    for(var i = 0; i < data.length; i ++) {
        html += "<tr><td width='15%' align='center' vertical-align='middle'><span style='font-size:18px;font-weight:bold'>" + data[i].host + "</td>";
        html += "<td>" + buildIpsTablesHTML(data[i].host, data[i].ips) + "</td>";
        html += "</tr>";
    }
    html += "</tbody><table>";
    console.log(html);
    document.getElementById("div_table").innerHTML = html;
}

function buildIpsTablesHTML(host, ips) {
    var html = "<table class='table' style='margin-bottom: 0'><tbody>";

    for(var uid in ips ) {

        //uid为1的用户 解析到qcloud的域名, uid为1000的用户,解析到aws的域名
        if(uid == 1) {
            html += "<tr><td width='10%'><span style='color: darkgray'><strong>QCloud</strong></span></td>";
        }else {
            html += "<tr><td width='10%'><span style='color: darkgray'><strong>AWS</strong></span></td>";
        }

        var ipList = ips[uid];

        //该uid+host组合下ips为0,则显示告警数据,不为0,则根据每个ip的解析状态显示出来
        if(ipList.length == 0) {
            html += "<td><button class='btn btn-danger btn-rounded' style='width: 140px'>NULL</button></td>";
        } else {

            html += "<td><div class = 'btn-list'>";

            for(var i = 0; i < ipList.length; i ++) {
                if(ipList[i].status == "SUCCESSED") {
                    html += "<button class='btn btn-success btn-rounded' style='width: 140px; margin-right: 10px'>" + ipList[i].ip + "</button>";
                } else {
                    html += "<a data-container='body' data-toggle='popover' data-placement='bottom' title='Detail'";
                    html += "data-content= '" + ipList[i].info + "'><button class='btn btn-danger btn-rounded' style='width: 140px; margin-right: 10px'>" + ipList[i].ip + "</button></a>";
                }
            }
            html +="</div></td>";
        }

        //超链接到查询历史记录的界面
        html += "<td width='10%'><a style='text-decoration:underline;' href=\"" + getUrlBasePath() + "/dns_monitor/history?host=" + host + "&uid=" + uid + "\"><span style='font-size: large'>history</span></a></td></tr>";
        html += "</tr>";
    }

    html += "</tbody></table>";
    return html;
}

//当分页控件被点击时,remove掉之前的popover
function removePopoverDiv() {
    var popovers = getClass('div','popover');

    if(popovers.length!== 0) {
        for(var i = 0; i < popovers.length; i++) {
            document.body.removeChild(popovers[i]);
        }
    }
}

//获得标签名为tagName,类名className的元素的所有内容作为数组输出
function getClass(tagName,className)
{
    if(document.getElementsByClassName) //支持这个函数
    {        return document.getElementsByClassName(className);
    }
    else
    {       var tags=document.getElementsByTagName(tagName);//获取标签
        var tagArr=[];//用于返回类名为className的元素
        for(var i=0;i < tags.length; i++)
        {
            if(tags[i].class == className)
            {
                tagArr[tagArr.length] = tags[i];//保存满足条件的元素
            }
        }
        return tagArr;
    }
}

function updateTimePanel(updateTime) {

    document.getElementById("updateTime").innerHTML = updateTime;
}