diff options
Diffstat (limited to 'assets')
-rw-r--r-- | assets/index.html | 8 | ||||
-rw-r--r-- | assets/index.js | 44 |
2 files changed, 28 insertions, 24 deletions
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 @@ <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> - <title>status.tobyvin.dev</title> <link rel="stylesheet" type="text/css" href="index.css" /> - <script src="index.js"></script> + <script src="index.js"></script> </head> <body> <main> <header> <hgroup> - <h1>tobyvin.dev Status</h1> + <h1>SrvStat</h1> </hgroup> </header> - <table> <tr id="status"> <td><b>Status</b></td> <td id="issues">No issues detected</td> </tr> </table> - <hr></hr> - <table id="services"></table> </main> </body> 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); + }); } }); |