From 70e1c155ce4b73ef11ca586fc71401de37f8754e Mon Sep 17 00:00:00 2001 From: Luke Berndt Date: Thu, 6 Feb 2025 21:19:23 -0500 Subject: [PATCH] add system status --- backend/controllers/systems.js | 15 +++++++++++++++ backend/index.js | 4 +++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/backend/controllers/systems.js b/backend/controllers/systems.js index f54c75a..452d8a5 100644 --- a/backend/controllers/systems.js +++ b/backend/controllers/systems.js @@ -147,6 +147,21 @@ async function load_systems(systemClients) { // console.log("Loaded Systems: " + systemList.length + " that have been active since: " + fromDate); } +exports.get_system_status = async function (req, res) { + var shortName = req.params.shortName.toLowerCase(); + var system = systemList.find(function (element) { + return element.shortName == shortName; + }); + + var response = { + active: system.active, + lastActive: system.lastActive, + clientCount: system.clientCount, + callAvg: system.callAvg, + } + res.contentType('json'); + res.send(JSON.stringify(response)); +} exports.get_systems = async function (req, res) { /* going to use a cron job to update the system list every 2 minutes diff --git a/backend/index.js b/backend/index.js index 080d023..666a0c6 100644 --- a/backend/index.js +++ b/backend/index.js @@ -107,7 +107,6 @@ function addSystemClients(req, res, next) { } function addTotalClients(req, res, next) { - req.totalClients = Object.keys(clients).length; next(); } @@ -153,6 +152,9 @@ app.get('/events/:id', events.getEvent); app.get('/:shortName/stats', stats.get_stats); app.get('/stats', addTotalClients, sys_stats.siteStats) +/*------ SYSTEM STATUS ----------*/ +app.get('/status/:shortName', systems.get_system_status); + function get_clients(req, res) { if (req.params.shortName) {