$(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.vpn") { 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 = 'Wake up NAS' $node.find(".host").append(ele); $nasStatus = $node.find("#nasStatus") } if (data["Status"] == "DOWN") { $nasStatus.show(); } else { $nasStatus.hide(); } }