From 2d72aab0a88baa906127489e1c25fd11881bdc35 Mon Sep 17 00:00:00 2001 From: Ruben Beltran del Rio Date: Tue, 8 Jun 2021 21:37:55 +0200 Subject: Add the monitor --- public/js/monitorcito.js | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 public/js/monitorcito.js (limited to 'public/js') diff --git a/public/js/monitorcito.js b/public/js/monitorcito.js new file mode 100644 index 0000000..ef428a5 --- /dev/null +++ b/public/js/monitorcito.js @@ -0,0 +1,40 @@ +(function () { + + const table = document.querySelector('#monitorcito'); + + function loadData () { + fetch('/api') + .then((response) => response.json()) + .then((serviceStatus) => { + + while (table.firstChild) { + table.removeChild(table.firstChild) + } + + for (const [service, isActive] of Object.entries(serviceStatus)) { + const row = document.createElement('tr'); + const serviceCell = document.createElement('td'); + serviceCell.appendChild(document.createTextNode(service)); + const isActiveCell = document.createElement('td'); + isActiveCell.appendChild(document.createTextNode(isActive ? 'OK' : 'FAIL')); + isActiveCell.classList.add(isActive); + row.appendChild(serviceCell); + row.appendChild(isActiveCell); + table.appendChild(row); + } + + setTimeout(loadData, 5000); + }) + .catch(() => { + const container = document.querySelector('main'); + container.removeChild(table); + const paragraph = document.createElement('p'); + paragraph.appendChild(document.createTextNode('Everything is broken. If your internet works, please check the server\'s not on fire. When in doubt, just refresh.')); + paragraph.classList.add('critical'); + container.appendChild(paragraph); + }) + } + + loadData(); +} +)(); -- cgit