diff --git a/index.js b/index.js index 6c5d25f..f272c46 100644 --- a/index.js +++ b/index.js @@ -145,6 +145,18 @@ function renderStatusPage() { fs.writeFileSync(process.env.DEV ? "./dev/index.html" : "/var/www/html/status/index.html", str); } }); + + const jsonOutput = { + endpoints: parseEndpoints(getEndpoints()), + userInfo: Object.fromEntries(Object.entries(getUsers()).map(([key, value]) => [key, value[1]])) + }; + + jsonOutput.endpoints.forEach(endpoint => { + const avgPing = endpoint.contacts.reduce((sum, contact) => sum + contact.ping, 0) / endpoint.contacts.length; + endpoint.contacts = [{ ping: isNaN(avgPing) ? 'No Data' : avgPing.toFixed(2) }]; + }); + + fs.writeFileSync(process.env.DEV ? "./dev/status.json" : "/var/www/html/status/status.json", JSON.stringify(jsonOutput, null, 2)); } client.on("ready", () => {