mirror of https://github.com/Aelita4/sshmon.git
Compare commits
2 Commits
473e7df43e
...
41995c90c2
Author | SHA1 | Date |
---|---|---|
Aelita4 | 41995c90c2 | |
Aelita4 | f30a04c32e |
36
README.md
36
README.md
|
@ -12,7 +12,7 @@
|
|||
|
||||
3. Create database and tables
|
||||
- Script does not create database and tables by default
|
||||
- Create database `sshmon` with 2 tables:
|
||||
- Create database `sshmon` with 3 tables:
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
|
@ -66,6 +66,40 @@
|
|||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th colspan=3>downtime</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>Name</td>
|
||||
<td>Type</td>
|
||||
<td>Extra</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>id</td>
|
||||
<td>int</td>
|
||||
<td>AUTO_INCREMENT PRIMARY KEY</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>ip</td>
|
||||
<td>varchar(255)</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>time</td>
|
||||
<td>datetime</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>status</td>
|
||||
<td>varchar(255)</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
4. Register new account in app
|
||||
5. Login
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { Request, Response } from 'express';
|
||||
import { connection } from '../index.js';
|
||||
|
||||
export default {
|
||||
method: "GET",
|
||||
|
@ -6,6 +7,21 @@ export default {
|
|||
callback: async (data: any, req: Request, res: Response) => {
|
||||
const ip = req.params.ip;
|
||||
const r = await data.ping(ip);
|
||||
if((Number(data.pings.get(ip).split("_")[0]) + (1000 * 60 * 5)) < Date.now()) {
|
||||
if(!r.alive) connection.query("SELECT * FROM downtime WHERE ip=? AND date=? AND status=?", [ip, new Date(Number(data.pings.get(ip).split("_")[0])).toISOString().slice(0, 19).replace('T', ' '), "DOWN"], (err, results, fields) => {
|
||||
if(err) throw err;
|
||||
if(results.length === 0) connection.query("INSERT INTO downtime VALUES (NULL, ?, ?, ?)", [ip, new Date(Number(data.pings.get(ip).split("_")[0])).toISOString().slice(0, 19).replace('T', ' '), "DOWN"], (errr, resultss, fieldss) => {
|
||||
if(errr) throw errr;
|
||||
});
|
||||
});
|
||||
|
||||
else connection.query("SELECT * FROM downtime WHERE ip=? AND date=? AND status=?", [ip, new Date(Number(data.pings.get(ip).split("_")[0])).toISOString().slice(0, 19).replace('T', ' '), "UP"], (err, results, fields) => {
|
||||
if(err) throw err;
|
||||
if(results.length === 0) connection.query("INSERT INTO downtime VALUES (NULL, ?, ?, ?)", [ip, new Date(Number(data.pings.get(ip).split("_")[0])).toISOString().slice(0, 19).replace('T', ' '), "UP"], (errr, resultss, fieldss) => {
|
||||
if(errr) throw errr;
|
||||
});
|
||||
});
|
||||
}
|
||||
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');
|
||||
|
|
|
@ -25,8 +25,8 @@
|
|||
|
||||
async function aaa() {
|
||||
const date = new Date();
|
||||
document.getElementById("main").innerHTML = "Last checked: " + date;
|
||||
document.getElementById("eta").innerHTML = "Next scheduled check: " + new Date(date.getTime() + <%= timeoutDelay %>);
|
||||
document.getElementById("main").innerHTML = "Last checked: " + date.toLocaleString();
|
||||
document.getElementById("eta").innerHTML = "Next scheduled check: " + new Date(date.getTime() + <%= timeoutDelay %>).toLocaleString();
|
||||
addresses.forEach(async a => {
|
||||
const b = document.getElementById(a + "_status");
|
||||
if(!b) return;
|
||||
|
@ -34,7 +34,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(Number((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)).toLocaleString() + '</span>'
|
||||
});
|
||||
})
|
||||
setTimeout(aaa, <%= timeoutDelay %>)
|
||||
|
|
Loading…
Reference in New Issue