Add json api
This commit is contained in:
parent
3fa6a199ee
commit
14837275b9
12
index.js
12
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", () => {
|
||||
|
|
Loading…
Reference in a new issue