rename: checks → pings throughout (DB, API, UI, Rust)
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import { Elysia, t } from "elysia";
|
||||
import sql from "../db";
|
||||
|
||||
// Internal-only: called by the Rust monitor runner
|
||||
export const ingest = new Elysia()
|
||||
.post("/internal/ingest", async ({ body, headers, error }) => {
|
||||
const token = headers["x-monitor-token"];
|
||||
if (token !== process.env.MONITOR_TOKEN) return error(401, { error: "Unauthorized" });
|
||||
|
||||
const meta = body.meta ? { ...body.meta } : {};
|
||||
if (body.cert_expiry_days != null) meta.cert_expiry_days = body.cert_expiry_days;
|
||||
|
||||
await sql`
|
||||
INSERT INTO pings (monitor_id, status_code, latency_ms, up, error, meta)
|
||||
VALUES (
|
||||
${body.monitor_id},
|
||||
${body.status_code ?? null},
|
||||
${body.latency_ms ?? null},
|
||||
${body.up},
|
||||
${body.error ?? null},
|
||||
${Object.keys(meta).length > 0 ? sql.json(meta) : null}
|
||||
)
|
||||
`;
|
||||
return { ok: true };
|
||||
}, {
|
||||
body: t.Object({
|
||||
monitor_id: t.String(),
|
||||
status_code: t.Optional(t.Number()),
|
||||
latency_ms: t.Optional(t.Number()),
|
||||
up: t.Boolean(),
|
||||
error: t.Optional(t.Nullable(t.String())),
|
||||
cert_expiry_days: t.Optional(t.Nullable(t.Number())),
|
||||
meta: t.Optional(t.Any()),
|
||||
}),
|
||||
detail: { hide: true },
|
||||
});
|
||||
Reference in New Issue
Block a user