red and green observer status icons
[plstackapi.git] / planetstack / core / static / observer_status.js
diff --git a/planetstack/core/static/observer_status.js b/planetstack/core/static/observer_status.js
new file mode 100644 (file)
index 0000000..56e9f09
--- /dev/null
@@ -0,0 +1,25 @@
+function updateObserverStatus() {
+    var url="/observer";
+    console.log("fetching observer status url " + url);
+    $.ajax({ url: url,
+             dataType : 'json',
+             type : 'GET',
+             success: function(newData) {
+                  console.log(newData);
+                  if (newData.health==":-)") {
+                      html = '<span style="margin-left: 16px;" title="last observer run time = ' + Math.floor(newData.last_duration) + ' seconds"><img src="/static/img/green-cloud.gif" width=16 height=16></span>';
+                  } else {
+                      html = '<span style="margin-left: 16px;" title="observer is offline"><img src="/static/img/red-cloud.gif"></span>';
+                  }
+                  $("#observer-status").html(html);
+                  setTimeout(function() { updateObserverStatus(); }, 60000);
+             },
+             error: function() {
+                  setTimeout(function() { updateObserverStatus(); }, 60000);
+             }
+});
+}
+
+$( document ).ready(function() {
+    updateObserverStatus();
+});