]> git.r.bdr.sh - rbdr/monitorcito/blame_incremental - public/js/monitorcito.js
Add LICENSE
[rbdr/monitorcito] / public / js / monitorcito.js
... / ...
CommitLineData
1(function () {
2
3 const table = document.querySelector('#monitorcito');
4
5 function loadData () {
6 fetch('/api')
7 .then((response) => response.json())
8 .then((serviceStatus) => {
9
10 while (table.firstChild) {
11 table.removeChild(table.firstChild)
12 }
13
14 for (const [service, isActive] of Object.entries(serviceStatus)) {
15 const row = document.createElement('tr');
16 const serviceCell = document.createElement('td');
17 serviceCell.appendChild(document.createTextNode(service));
18 const isActiveCell = document.createElement('td');
19 isActiveCell.appendChild(document.createTextNode(isActive ? 'OK' : 'FAIL'));
20 isActiveCell.classList.add(isActive);
21 row.appendChild(serviceCell);
22 row.appendChild(isActiveCell);
23 table.appendChild(row);
24 }
25
26 setTimeout(loadData, 5000);
27 })
28 .catch(() => {
29 const container = document.querySelector('main');
30 container.removeChild(table);
31 const paragraph = document.createElement('p');
32 paragraph.appendChild(document.createTextNode('Everything is broken. If your internet works, please check the server\'s not on fire. When in doubt, just refresh.'));
33 paragraph.classList.add('critical');
34 container.appendChild(paragraph);
35 })
36 }
37
38 loadData();
39}
40)();