mirror of https://github.com/Aelita4/sshmon.git
Fix "Invalid date" error
This commit is contained in:
parent
30865c6bd0
commit
95b5be4e5b
|
@ -21,7 +21,7 @@ const getIP = () : Promise<string[]> => {
|
|||
return new Promise((resolve, reject) => {
|
||||
connection.query("SELECT * FROM ips", async (err, results, fields) => {
|
||||
if(err) reject(err);
|
||||
const addresses = [...results.slice()];
|
||||
const addresses = [...results.slice()].map(a => a.ip);
|
||||
|
||||
resolve(addresses);
|
||||
});
|
||||
|
@ -54,7 +54,7 @@ const pings = new Map();
|
|||
|
||||
let addresses: Array<string> = await getIP();
|
||||
|
||||
addresses.forEach((a: string) => pings.set(a, -1));
|
||||
addresses.forEach((a: string) => pings.set(a, `${Date.now()}_1`));
|
||||
const timeoutDelay = 60000;
|
||||
|
||||
const routes = readdirSync(__dirname + "/routes");
|
||||
|
|
|
@ -6,7 +6,7 @@ export default {
|
|||
callback: async (data: any, req: Request, res: Response) => {
|
||||
const ip = req.params.ip;
|
||||
|
||||
const json = { downSince: data.pings.get(ip) };
|
||||
const json = { downSince: data.pings.get(ip).split("_")[0] };
|
||||
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify(json));
|
||||
|
|
|
@ -4,10 +4,11 @@ export default {
|
|||
method: "GET",
|
||||
url: "/ping/:ip",
|
||||
callback: async (data: any, req: Request, res: Response) => {
|
||||
console.log(data.pings)
|
||||
const ip = req.params.ip;
|
||||
const r = await data.ping(ip);
|
||||
if(!r.alive && data.pings.get(ip) === -1) data.pings.set(ip, Date.now());
|
||||
else if(r.alive) data.pings.set(ip, -1);
|
||||
if(!r.alive && data.pings.get(ip).split("_")[1] === "1") data.pings.set(ip, `${Date.now()}_0`);
|
||||
else if(r.alive) data.pings.set(ip, `${Date.now()}_1`);
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
res.end(JSON.stringify(r));
|
||||
}
|
||||
|
|
|
@ -6,9 +6,7 @@ export default {
|
|||
method: "GET",
|
||||
url: "/",
|
||||
callback: async (data: any, req: Request, res: Response) => {
|
||||
const tmp = await getIP();
|
||||
//@ts-ignore
|
||||
data.addresses = tmp.map(a => a.ip);
|
||||
data.addresses = await getIP();
|
||||
//@ts-ignore
|
||||
if(!req.session.user) res.redirect("/login");
|
||||
else res.render('pages/index.ejs', {
|
||||
|
|
|
@ -40,7 +40,7 @@
|
|||
await fetch('http://localhost:8080/ping/' + a)
|
||||
.then((response) => response.json())
|
||||
.then(async (data) => {
|
||||
b.innerHTML = data.alive ? '<span style="color:green;">UP (' + data.numeric_host + ") " + data.time + 'ms</span>' : '<span style="color:red;">DOWN' + ((data.host == "unknown") ? " (UNKNOWN HOST)" : (" (" + data.numeric_host + ")")) + " since " + new Date((await (await fetch('http://localhost:8080/downtime/' + a)).json()).downSince) + '</span>'
|
||||
b.innerHTML = data.alive ? '<span style="color:green;">UP (' + data.numeric_host + ") " + data.time + 'ms</span>' : '<span style="color:red;">DOWN' + ((data.host == "unknown") ? " (UNKNOWN HOST)" : (" (" + data.numeric_host + ")")) + " since " + new Date(Number((await (await fetch('http://localhost:8080/downtime/' + a)).json()).downSince)) + '</span>'
|
||||
});
|
||||
})
|
||||
setTimeout(aaa, <%= timeoutDelay %>)
|
||||
|
|
Loading…
Reference in New Issue