summaryrefslogtreecommitdiffstats
path: root/assets/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'assets/index.js')
-rw-r--r--assets/index.js44
1 files changed, 26 insertions, 18 deletions
diff --git a/assets/index.js b/assets/index.js
index e65369c..bd0f308 100644
--- a/assets/index.js
+++ b/assets/index.js
@@ -29,41 +29,49 @@ function updateStatus() {
function updateService(name, node, status) {
switch (status.status) {
- case "pass":
- node.textContent = "Operational";
+ case "ok":
+ node.textContent = "Ok";
node.setAttribute("class", "ok");
+ serviceMap.set(name, true);
break;
- case "fail":
- node.textContent = "Down";
+ case "error":
+ node.textContent = "Error";
node.title = status.output;
node.setAttribute("class", "error");
+ serviceMap.set(name, false);
break;
- case "warn":
- node.textContent = "Warning";
- node.title = status.output;
- node.setAttribute("class", "warning");
- break;
- case "unknown":
- node.textContent = "Unknown";
- node.setAttribute("class", "warning");
}
- serviceMap.set(name, status.status === "pass");
updateStatus();
}
getServices().then((services) => {
- for (const [service] of Object.entries(services)) {
+ const evtSource = new EventSource("sse");
+ evtSource.onmessage = (event) => {
+ console.log(event)
+ };
+
+ for (const [service, status] of Object.entries(services)) {
const table = document.getElementById("services");
const row = table.insertRow();
const nameNode = row.insertCell();
nameNode.textContent = service;
const node = row.insertCell();
+ updateService(service, node, status);
const evtSource = new EventSource(`sse/${service}`);
- evtSource.onmessage = (event) => {
- const status = JSON.parse(event.data);
- updateService(service, node, status);
- };
+
+ evtSource.addEventListener("ok", (event) => {
+ node.textContent = "Ok";
+ node.setAttribute("class", "ok");
+ serviceMap.set(name, true);
+ });
+
+ evtSource.addEventListener("error", (event) => {
+ node.textContent = "Error";
+ node.title = event.data;
+ node.setAttribute("class", "error");
+ serviceMap.set(name, false);
+ });
}
});