$(function() { refreshNodes(); }) function refreshNodes() { $("#nodeTable tr[data-node]").each(function(){ var $this = $(this); var node = $this.data("node"); $.getJSON("/status/"+node, function (data) { $this.find("span.loading").hide(); var label; if (data["Status"] === "UP") { label = "label-success"; $this.addClass("success"); $this.find("td.ping").text(data["Ping"] + "ms"); } else if (data["Status"] === "SLOW") { label = "label-warning"; $this.addClass("warning"); $this.find("td.ping").text(data["Ping"] + "ms"); } else { label = "label-danger"; $this.addClass("danger"); } if (data["Domain"] === "devkid-nas.vpn") { setNasWakeUpLink($this, data); } $this.find("span.status").addClass(label).text(data["Status"]); }) }); } function setNasWakeUpLink($row, data) { var $nasStatus = $row.find("#nasStatus"); if ($nasStatus.length == 0){ var ele = 'Wake up NAS' $row.find(".host").append(ele); $nasStatus = $row.find("#nasStatus") } if (data["Status"] == "DOWN") { $nasStatus.show(); } else { $nasStatus.hide(); } }