From fe16a923190243dfde5db6ceff2ef0bcf9158926 Mon Sep 17 00:00:00 2001 From: Toby Vincent Date: Tue, 1 Oct 2024 13:15:24 -0500 Subject: feat: simplify service status type --- assets/index.html | 8 ++------ assets/index.js | 44 ++++++++++++++++++++++++++------------------ 2 files changed, 28 insertions(+), 24 deletions(-) (limited to 'assets') diff --git a/assets/index.html b/assets/index.html index c168318..b0a6c18 100644 --- a/assets/index.html +++ b/assets/index.html @@ -3,27 +3,23 @@ - status.tobyvin.dev - +
-

tobyvin.dev Status

+

SrvStat

-
Status No issues detected
-
-
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); + }); } }); -- cgit v1.2.3-70-g09d2