aktaliosieren
This commit is contained in:
@@ -27,10 +27,20 @@ async function runCheck(check) {
|
||||
}
|
||||
|
||||
if (check.type === "script") {
|
||||
|
||||
if (!check.script_name) {
|
||||
return {
|
||||
status: "FAIL",
|
||||
message: "No script_name defined",
|
||||
duration: Date.now() - start
|
||||
};
|
||||
}
|
||||
|
||||
return new Promise((resolve) => {
|
||||
const scriptPath = path.join(CHECKS_DIR, check.script_name);
|
||||
|
||||
const child = spawn("sh", [scriptPath], {
|
||||
timeout: check.timeout_seconds * 1000
|
||||
timeout: (check.timeout_seconds || 10) * 1000
|
||||
});
|
||||
|
||||
child.on("close", (code) => {
|
||||
|
||||
3
app/checks/check_http_schooltech.sh
Executable file
3
app/checks/check_http_schooltech.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/sh
|
||||
wget -q --spider https://server.schooltech.de/ || exit 1
|
||||
exit $?
|
||||
@@ -2,6 +2,8 @@ const express = require("express");
|
||||
const pool = require("./db");
|
||||
const scheduleChecks = require("./scheduler");
|
||||
|
||||
const runCheck = require("./checkRunner");
|
||||
|
||||
const app = express();
|
||||
app.set("view engine", "ejs");
|
||||
app.use(express.static("public"));
|
||||
@@ -11,6 +13,32 @@ app.get("/", async (req, res) => {
|
||||
res.render("index", { checks: rows });
|
||||
});
|
||||
|
||||
app.post("/run/:id", async (req, res) => {
|
||||
const checkId = req.params.id;
|
||||
|
||||
const { rows } = await pool.query("SELECT * FROM checks WHERE id = $1", [checkId]);
|
||||
if (rows.length === 0) {
|
||||
return res.status(404).send("Check not found");
|
||||
}
|
||||
|
||||
const check = rows[0];
|
||||
const result = await runCheck(check);
|
||||
|
||||
await pool.query(
|
||||
`INSERT INTO results (check_id, status, message, duration_ms)
|
||||
VALUES ($1,$2,$3,$4)`,
|
||||
[check.id, result.status, result.message, result.duration]
|
||||
);
|
||||
|
||||
await pool.query(
|
||||
`UPDATE checks SET last_run = NOW(), last_status = $1 WHERE id = $2`,
|
||||
[result.status, check.id]
|
||||
);
|
||||
|
||||
res.redirect("/");
|
||||
});
|
||||
|
||||
|
||||
app.listen(3000, async () => {
|
||||
console.log("Server läuft auf Port 3000");
|
||||
await scheduleChecks();
|
||||
|
||||
@@ -12,16 +12,23 @@
|
||||
<th>Name</th>
|
||||
<th>Status</th>
|
||||
<th>Last Run</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
|
||||
<% checks.forEach(c => { %>
|
||||
<tr>
|
||||
<td><%= c.id %></td>
|
||||
<td>
|
||||
<%= c.display_id || c.id %></td>
|
||||
<td><%= c.name %></td>
|
||||
<td class="<%= c.last_status === 'OK' ? 'ok' : 'fail' %>">
|
||||
<%= c.last_status || 'N/A' %>
|
||||
</td>
|
||||
<td><%= c.last_run || 'N/A' %></td>
|
||||
<td>
|
||||
<form method="POST" action="/run/<%= c.id %>" style="margin:0;">
|
||||
<button type="submit">Run-Test</button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
<% }) %>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user