48 lines
1.3 KiB
JavaScript
48 lines
1.3 KiB
JavaScript
$(function() {
|
|
refreshNodes();
|
|
})
|
|
|
|
function refreshNodes() {
|
|
$("#nodeTable tr[data-node]").each(function(){
|
|
refreshNode($(this));
|
|
});
|
|
}
|
|
|
|
function refreshNode($node) {
|
|
var node = $node.data("node");
|
|
$.getJSON("/status/"+node, function (data) {
|
|
$node.find("span.loading").hide();
|
|
var label;
|
|
if (data["Status"] === "UP") {
|
|
label = "label-success";
|
|
$node.addClass("success");
|
|
$node.find("td.ping").text(data["Ping"] + "ms");
|
|
} else if (data["Status"] === "SLOW") {
|
|
label = "label-warning";
|
|
$node.addClass("warning");
|
|
$node.find("td.ping").text(data["Ping"] + "ms");
|
|
} else {
|
|
label = "label-danger";
|
|
$node.addClass("danger");
|
|
}
|
|
if (data["Domain"] === "devkid-nas") {
|
|
setNasWakeUpLink($node, data);
|
|
}
|
|
$node.find("span.status-text").addClass(label).text(data["Status"]);
|
|
})
|
|
}
|
|
|
|
function setNasWakeUpLink($node, data) {
|
|
var $nasStatus = $node.find("#nasStatus");
|
|
if ($nasStatus.length == 0){
|
|
var ele = '<a id="nasStatus" href="http://devkid-router.vpn:8080/cgi-bin/wake-nas" class="btn btn-link btn-sm">Wake up NAS</a>'
|
|
$node.find(".host").append(ele);
|
|
$nasStatus = $node.find("#nasStatus")
|
|
}
|
|
if (data["Status"] == "DOWN") {
|
|
$nasStatus.show();
|
|
} else {
|
|
$nasStatus.hide();
|
|
}
|
|
}
|