A web check can read a value out of a JSON answer (power.now, state, data.result[0].value[1]) and judge it: below, above, equal to, contains, is there. The value read is shown on the Endpoints page, charted under History, exported as homelab_endpoint_value and in the read API. A check can also send one header (a token), stored encrypted, never returned, and not forwarded to another host on a redirect. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
612 lines
31 KiB
TypeScript
612 lines
31 KiB
TypeScript
import { useEffect, useState } from "react";
|
|
import { Link } from "react-router-dom";
|
|
import { api, type CurrentUser, type EndpointCheck, type EndpointInput, type EndpointKind, type EndpointValueOp } from "../api/client";
|
|
import Pagination from "../components/Pagination";
|
|
import SortableTh from "../components/SortableTh";
|
|
import TableToolbar from "../components/TableToolbar";
|
|
import TimeAgo from "../components/TimeAgo";
|
|
import { ErrorNotice } from "../components/Notice";
|
|
import { BlockSkeleton } from "../components/Skeleton";
|
|
import { usePagination } from "../hooks/usePagination";
|
|
import { useSortable } from "../hooks/useSortable";
|
|
import { useTableSearch } from "../hooks/useTableSearch";
|
|
import { downloadCsv } from "../utils/csv";
|
|
import { confirmDialog } from "../utils/dialogs";
|
|
import { readableError } from "../utils/errors";
|
|
import { toast } from "../utils/toast";
|
|
import { EmptyRow } from "../components/EmptyState";
|
|
import EndpointSuggestions from "../components/EndpointSuggestions";
|
|
import EndpointHistory from "../components/EndpointHistory";
|
|
|
|
const KIND_LABELS: Record<EndpointKind, string> = { http: "Web address", tcp: "Port", tls: "Certificate" };
|
|
const KIND_HINTS: Record<EndpointKind, string> = {
|
|
http: "Asks the address and wants a good answer (and, if you like, a word in the page, or a value in a JSON answer within its limits).",
|
|
tcp: "Opens a connection to the port and sees whether anything answers.",
|
|
tls: "Reads the certificate the service shows and warns before it runs out.",
|
|
};
|
|
|
|
type State = "waiting" | "up" | "failing" | "down" | "off";
|
|
const STATE_BADGE: Record<State, { label: string; badge: string }> = {
|
|
waiting: { label: "Not asked yet", badge: "bg-secondary-lt text-secondary" },
|
|
up: { label: "Up", badge: "bg-green-lt text-green" },
|
|
failing: { label: "Failing", badge: "bg-yellow-lt text-yellow" },
|
|
down: { label: "Down", badge: "bg-red-lt text-red" },
|
|
off: { label: "Switched off", badge: "bg-secondary-lt text-secondary" },
|
|
};
|
|
const RANK: Record<State, number> = { down: 0, failing: 1, waiting: 2, up: 3, off: 4 };
|
|
|
|
function stateOf(c: EndpointCheck): State {
|
|
if (!c.enabled) return "off";
|
|
if (c.lastOk === null) return "waiting";
|
|
if (c.lastOk) return "up";
|
|
return c.consecutiveFailures >= c.failuresBeforeAlert ? "down" : "failing";
|
|
}
|
|
|
|
const OP_LABELS: Record<EndpointValueOp, string> = { "<": "is below", "<=": "is at most", ">": "is above", ">=": "is at least", "=": "is equal to", "!=": "is anything but", contains: "contains", exists: "is there" };
|
|
const LIMIT_WORDS: Record<EndpointValueOp, string> = { "<": "below", "<=": "at most", ">": "above", ">=": "at least", "=": "equal to", "!=": "anything but", contains: "containing", exists: "there" };
|
|
const NUMERIC = (op: EndpointValueOp) => op === "<" || op === "<=" || op === ">" || op === ">=";
|
|
|
|
/** What a value check wants, in words: "power.now should be below 5000 W". */
|
|
function limitWords(c: EndpointCheck): string {
|
|
if (!c.valuePath || !c.valueOp) return "";
|
|
if (c.valueOp === "exists") return `${c.valuePath} should be there`;
|
|
if (c.valueOp === "contains") return `${c.valuePath} should contain “${c.valueExpected}”`;
|
|
const numeric = NUMERIC(c.valueOp) || (c.valueExpected !== null && c.valueExpected.trim() !== "" && Number.isFinite(Number(c.valueExpected)));
|
|
return `${c.valuePath} should be ${LIMIT_WORDS[c.valueOp]} ${numeric ? c.valueExpected : `“${c.valueExpected}”`}${numeric && c.valueUnit ? ` ${c.valueUnit}` : ""}`;
|
|
}
|
|
|
|
const daysLeft = (iso: string | null) => (iso ? Math.floor((Date.parse(iso) - Date.now()) / 86_400_000) : null);
|
|
|
|
interface Row extends EndpointCheck {
|
|
state: State;
|
|
rank: number;
|
|
certDays: number | null;
|
|
uptime24h: number | null;
|
|
}
|
|
|
|
/** The last results as a row of small ticks: green for an answer, red for none. */
|
|
function Ticks({ recent }: { recent: { at: string; ok: boolean }[] }) {
|
|
if (recent.length === 0) return <span className="text-secondary">—</span>;
|
|
return (
|
|
<span className="d-inline-flex gap-1 align-middle" role="img" aria-label={`The last ${recent.length} checks: ${recent.filter((r) => r.ok).length} answered`}>
|
|
{recent.map((r) => (
|
|
<span key={r.at} title={`${r.at.slice(0, 16).replace("T", " ")} UTC — ${r.ok ? "answered" : "no good answer"}`} style={{ width: 4, height: 14, borderRadius: 1, background: r.ok ? "#2fb344" : "#e05252", display: "inline-block" }} />
|
|
))}
|
|
</span>
|
|
);
|
|
}
|
|
|
|
interface Draft {
|
|
id: number | null;
|
|
name: string;
|
|
kind: EndpointKind;
|
|
target: string;
|
|
port: string;
|
|
expectStatus: string;
|
|
keyword: string;
|
|
valuePath: string;
|
|
valueOp: EndpointValueOp;
|
|
valueExpected: string;
|
|
valueUnit: string;
|
|
headerName: string;
|
|
headerValue: string;
|
|
/** A header is already saved with this check, so its value may be left blank to keep it. */
|
|
hadHeader: boolean;
|
|
insecure: boolean;
|
|
intervalMinutes: string;
|
|
timeoutSeconds: string;
|
|
failuresBeforeAlert: string;
|
|
warnDays: string;
|
|
serverId: string;
|
|
enabled: boolean;
|
|
}
|
|
|
|
const EMPTY: Draft = { id: null, name: "", kind: "http", target: "", port: "", expectStatus: "", keyword: "", valuePath: "", valueOp: "<", valueExpected: "", valueUnit: "", headerName: "", headerValue: "", hadHeader: false, insecure: false, intervalMinutes: "5", timeoutSeconds: "10", failuresBeforeAlert: "2", warnDays: "14", serverId: "", enabled: true };
|
|
|
|
const toDraft = (c: EndpointCheck): Draft => ({
|
|
id: c.id,
|
|
name: c.name,
|
|
kind: c.kind,
|
|
target: c.target,
|
|
port: c.port === null ? "" : String(c.port),
|
|
expectStatus: c.expectStatus ?? "",
|
|
keyword: c.keyword ?? "",
|
|
valuePath: c.valuePath ?? "",
|
|
valueOp: c.valueOp ?? "<",
|
|
valueExpected: c.valueExpected ?? "",
|
|
valueUnit: c.valueUnit ?? "",
|
|
headerName: c.headerName ?? "",
|
|
headerValue: "",
|
|
hadHeader: c.hasHeader,
|
|
insecure: c.insecure,
|
|
intervalMinutes: String(c.intervalMinutes),
|
|
timeoutSeconds: String(c.timeoutSeconds),
|
|
failuresBeforeAlert: String(c.failuresBeforeAlert),
|
|
warnDays: String(c.warnDays),
|
|
serverId: c.serverId === null ? "" : String(c.serverId),
|
|
enabled: c.enabled,
|
|
});
|
|
|
|
const toInput = (d: Draft): EndpointInput => ({
|
|
name: d.name.trim(),
|
|
kind: d.kind,
|
|
target: d.target.trim(),
|
|
port: d.kind === "http" || d.port.trim() === "" ? null : Number(d.port),
|
|
expectStatus: d.kind === "http" && d.expectStatus.trim() ? d.expectStatus.trim() : null,
|
|
keyword: d.kind === "http" && d.keyword ? d.keyword : null,
|
|
valuePath: d.kind === "http" && d.valuePath.trim() ? d.valuePath.trim() : null,
|
|
valueOp: d.kind === "http" && d.valuePath.trim() ? d.valueOp : null,
|
|
valueExpected: d.kind === "http" && d.valuePath.trim() && d.valueOp !== "exists" ? d.valueExpected : null,
|
|
valueUnit: d.kind === "http" && d.valuePath.trim() && d.valueUnit.trim() ? d.valueUnit.trim() : null,
|
|
headerName: d.kind === "http" && d.headerName.trim() ? d.headerName.trim() : null,
|
|
headerValue: d.kind === "http" && d.headerName.trim() && d.headerValue ? d.headerValue : undefined,
|
|
insecure: d.insecure,
|
|
intervalMinutes: Number(d.intervalMinutes),
|
|
timeoutSeconds: Number(d.timeoutSeconds),
|
|
failuresBeforeAlert: Number(d.failuresBeforeAlert),
|
|
warnDays: Number(d.warnDays),
|
|
serverId: d.serverId === "" ? null : Number(d.serverId),
|
|
enabled: d.enabled,
|
|
});
|
|
|
|
/**
|
|
* "Is it up?" for the simple cases: a web address, a TCP port, a certificate. The app asks every few minutes, remembers how it went, and
|
|
* raises an alert (and a notification) when a check keeps failing or a certificate is about to run out. Everyone can look; an administrator
|
|
* sets them up, since each one makes this server connect somewhere.
|
|
*/
|
|
export default function Endpoints({ user }: { user: CurrentUser }) {
|
|
const isAdmin = user.role === "admin";
|
|
const canCheck = user.role === "admin" || user.role === "operator";
|
|
const [checks, setChecks] = useState<EndpointCheck[] | null>(null);
|
|
const [servers, setServers] = useState<{ id: number; name: string }[]>([]);
|
|
const [error, setError] = useState<string | null>(null);
|
|
const [draft, setDraft] = useState<Draft | null>(null);
|
|
const [busy, setBusy] = useState(false);
|
|
const [asking, setAsking] = useState<number | null>(null);
|
|
const [historyFor, setHistoryFor] = useState<{ id: number; name: string } | null>(null);
|
|
|
|
function load() {
|
|
api.endpoints
|
|
.list()
|
|
.then((res) => {
|
|
setChecks(res.checks);
|
|
setServers(res.servers);
|
|
})
|
|
.catch((err) => setError(readableError(err)));
|
|
}
|
|
useEffect(() => {
|
|
load();
|
|
// The results come in on their own every few minutes: look again now and then.
|
|
const t = setInterval(load, 60_000);
|
|
return () => clearInterval(t);
|
|
}, []);
|
|
|
|
const rows: Row[] = (checks ?? []).map((c) => ({ ...c, state: stateOf(c), rank: RANK[stateOf(c)], certDays: daysLeft(c.certExpiresAt), uptime24h: c.stats?.uptime24h ?? null }));
|
|
const tableSearch = useTableSearch(rows);
|
|
const { sorted, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered, "rank", "asc", { url: true });
|
|
const page = usePagination(sorted);
|
|
const down = rows.filter((r) => r.state === "down" || r.state === "failing").length;
|
|
const certs = rows.filter((r) => r.certDays !== null && r.certDays <= r.warnDays).length;
|
|
|
|
async function save(e: React.FormEvent) {
|
|
e.preventDefault();
|
|
if (!draft) return;
|
|
setBusy(true);
|
|
setError(null);
|
|
try {
|
|
if (draft.id === null) await api.endpoints.create(toInput(draft));
|
|
else await api.endpoints.update(draft.id, toInput(draft));
|
|
toast.success(draft.id === null ? `Added ${draft.name}.` : "Saved.");
|
|
setDraft(null);
|
|
load();
|
|
} catch (err) {
|
|
setError(readableError(err));
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
}
|
|
|
|
async function remove(c: EndpointCheck) {
|
|
if (!(await confirmDialog({ title: "Remove a check", message: `Remove "${c.name}" and its history?`, confirmLabel: "Remove", danger: true }))) return;
|
|
try {
|
|
await api.endpoints.remove(c.id);
|
|
load();
|
|
} catch (err) {
|
|
setError(readableError(err));
|
|
}
|
|
}
|
|
|
|
async function askNow(c: EndpointCheck) {
|
|
setAsking(c.id);
|
|
try {
|
|
const { result } = await api.endpoints.check(c.id);
|
|
if (result.ok) toast.success(`${c.name}: ${result.message}`);
|
|
else toast.error(`${c.name}: ${result.message}`);
|
|
load();
|
|
} catch (err) {
|
|
setError(readableError(err));
|
|
} finally {
|
|
setAsking(null);
|
|
}
|
|
}
|
|
|
|
function exportCsv() {
|
|
downloadCsv(
|
|
"endpoint-checks.csv",
|
|
["Name", "Kind", "Target", "Port", "Status", "Last answer", "Value read", "Answer time (ms)", "Uptime 24 h (%)", "Uptime 7 d (%)", "Certificate expires", "Last checked", "Server"],
|
|
(sorted ?? []).map((r) => [r.name, KIND_LABELS[r.kind], r.target, r.port ?? "", STATE_BADGE[r.state].label, r.lastMessage ?? "", r.lastValue ?? "", r.lastResponseMs ?? "", r.stats?.uptime24h ?? "", r.stats?.uptime7d ?? "", r.certExpiresAt?.slice(0, 10) ?? "", r.lastCheckedAt ?? "", r.server?.name ?? ""]),
|
|
);
|
|
}
|
|
|
|
const set = <K extends keyof Draft>(key: K, value: Draft[K]) => setDraft((d) => (d ? { ...d, [key]: value } : d));
|
|
const cards = [
|
|
{ label: "Checks", value: checks ? String(rows.length) : "…", color: "" },
|
|
{ label: "Not answering", value: checks ? String(down) : "…", color: down > 0 ? "text-red" : "text-green" },
|
|
{ label: "Certificates to renew", value: checks ? String(certs) : "…", color: certs > 0 ? "text-yellow" : "" },
|
|
];
|
|
|
|
return (
|
|
<>
|
|
<div className="d-flex align-items-center mb-1">
|
|
<h2 className="page-title mb-0">Endpoints</h2>
|
|
{isAdmin && !draft && (
|
|
<button className="btn btn-primary ms-auto" onClick={() => setDraft({ ...EMPTY })}>
|
|
Add a check
|
|
</button>
|
|
)}
|
|
</div>
|
|
<p className="text-secondary">
|
|
The app asks a web address, a port or a certificate whether it is fine, every few minutes, and says so on the <Link to="/alerts">Alerts</Link> page and in notifications when it keeps failing or a
|
|
certificate is about to run out.
|
|
</p>
|
|
<ErrorNotice error={error} />
|
|
|
|
<div className="row row-cards mb-3">
|
|
{cards.map((c) => (
|
|
<div className="col-6 col-md-4" key={c.label}>
|
|
<div className="card card-sm">
|
|
<div className="card-body">
|
|
<div className={`h2 mb-0 ${c.color}`}>{c.value}</div>
|
|
<div className="text-secondary">{c.label}</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
))}
|
|
</div>
|
|
|
|
{isAdmin && !draft && <EndpointSuggestions onAdded={load} />}
|
|
|
|
{draft && (
|
|
<form className="card mb-3" onSubmit={save}>
|
|
<div className="card-header">
|
|
<h3 className="card-title">{draft.id === null ? "Add a check" : `Edit ${draft.name || "the check"}`}</h3>
|
|
</div>
|
|
<div className="card-body row g-3">
|
|
<div className="col-md-4">
|
|
<label className="form-label" htmlFor="ep-name">
|
|
Name
|
|
</label>
|
|
<input id="ep-name" className="form-control" required maxLength={100} placeholder="e.g. Gitea" value={draft.name} onChange={(e) => set("name", e.target.value)} />
|
|
</div>
|
|
<div className="col-md-4">
|
|
<label className="form-label" htmlFor="ep-kind">
|
|
What to ask
|
|
</label>
|
|
<select id="ep-kind" className="form-select" value={draft.kind} onChange={(e) => set("kind", e.target.value as EndpointKind)}>
|
|
{(Object.keys(KIND_LABELS) as EndpointKind[]).map((k) => (
|
|
<option key={k} value={k}>
|
|
{KIND_LABELS[k]}
|
|
</option>
|
|
))}
|
|
</select>
|
|
<div className="form-hint text-secondary small mt-1">{KIND_HINTS[draft.kind]}</div>
|
|
</div>
|
|
<div className="col-md-4">
|
|
<label className="form-label" htmlFor="ep-server">
|
|
It is about the server
|
|
</label>
|
|
<select id="ep-server" className="form-select" value={draft.serverId} onChange={(e) => set("serverId", e.target.value)}>
|
|
<option value="">— none in particular —</option>
|
|
{servers.map((s) => (
|
|
<option key={s.id} value={s.id}>
|
|
{s.name}
|
|
</option>
|
|
))}
|
|
</select>
|
|
<div className="form-hint text-secondary small mt-1">Maintenance on that server silences this check’s alerts, and its tags can route them.</div>
|
|
</div>
|
|
<div className={draft.kind === "http" ? "col-md-8" : "col-md-5"}>
|
|
<label className="form-label" htmlFor="ep-target">
|
|
{draft.kind === "http" ? "Address" : "Host name or address"}
|
|
</label>
|
|
<input
|
|
id="ep-target"
|
|
className="form-control"
|
|
required
|
|
maxLength={500}
|
|
placeholder={draft.kind === "http" ? "https://git.example.lan/" : "git.example.lan"}
|
|
value={draft.target}
|
|
onChange={(e) => set("target", e.target.value)}
|
|
/>
|
|
</div>
|
|
{draft.kind !== "http" && (
|
|
<div className="col-md-3">
|
|
<label className="form-label" htmlFor="ep-port">
|
|
Port
|
|
</label>
|
|
<input id="ep-port" type="number" min={1} max={65535} className="form-control" required value={draft.port} placeholder={draft.kind === "tls" ? "443" : ""} onChange={(e) => set("port", e.target.value)} />
|
|
</div>
|
|
)}
|
|
{draft.kind === "http" && (
|
|
<>
|
|
<div className="col-md-2">
|
|
<label className="form-label" htmlFor="ep-status">
|
|
Good answers
|
|
</label>
|
|
<input id="ep-status" className="form-control" placeholder="200-399" value={draft.expectStatus} onChange={(e) => set("expectStatus", e.target.value)} />
|
|
</div>
|
|
<div className="col-md-2">
|
|
<label className="form-label" htmlFor="ep-keyword">
|
|
Page contains
|
|
</label>
|
|
<input id="ep-keyword" className="form-control" maxLength={200} value={draft.keyword} onChange={(e) => set("keyword", e.target.value)} />
|
|
</div>
|
|
</>
|
|
)}
|
|
{draft.kind === "http" && (
|
|
<div className="col-12">
|
|
<div className="border rounded p-3">
|
|
<div className="fw-bold mb-1">Judge a value in the answer (optional)</div>
|
|
<div className="text-secondary small mb-2">
|
|
For an answer in JSON: say where the value is and what it should be. For example <code>power.now</code> is below 5000, <code>state</code> is equal to playing, or, for a Prometheus query, <code>data.result[0].value[1]</code> is above 0.
|
|
Use <code>[0]</code> for the first place in a list.
|
|
</div>
|
|
<div className="row g-2">
|
|
<div className="col-md-4">
|
|
<label className="form-label" htmlFor="ep-vpath">
|
|
Where in the answer
|
|
</label>
|
|
<input id="ep-vpath" className="form-control" maxLength={200} placeholder="power.now" value={draft.valuePath} onChange={(e) => set("valuePath", e.target.value)} />
|
|
</div>
|
|
<div className="col-md-3">
|
|
<label className="form-label" htmlFor="ep-vop">
|
|
It should be
|
|
</label>
|
|
<select id="ep-vop" className="form-select" value={draft.valueOp} disabled={draft.valuePath.trim() === ""} onChange={(e) => set("valueOp", e.target.value as EndpointValueOp)}>
|
|
{(Object.keys(OP_LABELS) as EndpointValueOp[]).map((op) => (
|
|
<option key={op} value={op}>
|
|
{OP_LABELS[op]}
|
|
</option>
|
|
))}
|
|
</select>
|
|
</div>
|
|
{draft.valueOp !== "exists" && (
|
|
<div className="col-md-3">
|
|
<label className="form-label" htmlFor="ep-vexp">
|
|
This
|
|
</label>
|
|
<input id="ep-vexp" className="form-control" maxLength={200} disabled={draft.valuePath.trim() === ""} placeholder={NUMERIC(draft.valueOp) ? "5000" : "playing"} value={draft.valueExpected} onChange={(e) => set("valueExpected", e.target.value)} />
|
|
</div>
|
|
)}
|
|
<div className="col-md-2">
|
|
<label className="form-label" htmlFor="ep-vunit">
|
|
Unit
|
|
</label>
|
|
<input id="ep-vunit" className="form-control" maxLength={12} disabled={draft.valuePath.trim() === ""} placeholder="W" value={draft.valueUnit} onChange={(e) => set("valueUnit", e.target.value)} />
|
|
</div>
|
|
</div>
|
|
<div className="row g-2 mt-1">
|
|
<div className="col-md-4">
|
|
<label className="form-label" htmlFor="ep-hname">
|
|
Send a header (optional)
|
|
</label>
|
|
<input id="ep-hname" className="form-control" maxLength={100} placeholder="Authorization" value={draft.headerName} onChange={(e) => set("headerName", e.target.value)} />
|
|
</div>
|
|
<div className="col-md-8">
|
|
<label className="form-label" htmlFor="ep-hvalue">
|
|
Its value
|
|
</label>
|
|
<input
|
|
id="ep-hvalue"
|
|
type="password"
|
|
autoComplete="off"
|
|
className="form-control"
|
|
maxLength={2000}
|
|
disabled={draft.headerName.trim() === ""}
|
|
placeholder={draft.hadHeader ? "Saved — leave blank to keep it" : "Bearer …"}
|
|
value={draft.headerValue}
|
|
onChange={(e) => set("headerValue", e.target.value)}
|
|
/>
|
|
<div className="form-hint text-secondary small mt-1">For an API that wants a token. It is stored encrypted, never shown again, and only sent to this address — not to another host a redirect leads to.</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)}
|
|
<div className="col-md-2">
|
|
<label className="form-label" htmlFor="ep-interval">
|
|
Every
|
|
</label>
|
|
<div className="input-group">
|
|
<input id="ep-interval" type="number" min={1} max={1440} className="form-control" value={draft.intervalMinutes} onChange={(e) => set("intervalMinutes", e.target.value)} />
|
|
<span className="input-group-text">min</span>
|
|
</div>
|
|
</div>
|
|
<div className="col-md-2">
|
|
<label className="form-label" htmlFor="ep-timeout">
|
|
Give up after
|
|
</label>
|
|
<div className="input-group">
|
|
<input id="ep-timeout" type="number" min={1} max={60} className="form-control" value={draft.timeoutSeconds} onChange={(e) => set("timeoutSeconds", e.target.value)} />
|
|
<span className="input-group-text">s</span>
|
|
</div>
|
|
</div>
|
|
<div className="col-md-3">
|
|
<label className="form-label" htmlFor="ep-fails">
|
|
Alert after
|
|
</label>
|
|
<div className="input-group">
|
|
<input id="ep-fails" type="number" min={1} max={20} className="form-control" value={draft.failuresBeforeAlert} onChange={(e) => set("failuresBeforeAlert", e.target.value)} />
|
|
<span className="input-group-text">failures in a row</span>
|
|
</div>
|
|
</div>
|
|
<div className="col-md-3">
|
|
<label className="form-label" htmlFor="ep-warn">
|
|
Warn about the certificate
|
|
</label>
|
|
<div className="input-group">
|
|
<input id="ep-warn" type="number" min={1} max={90} className="form-control" value={draft.warnDays} onChange={(e) => set("warnDays", e.target.value)} />
|
|
<span className="input-group-text">days before</span>
|
|
</div>
|
|
</div>
|
|
<div className="col-12 d-flex flex-wrap gap-4">
|
|
<label className="form-check mb-0">
|
|
<input type="checkbox" className="form-check-input" checked={draft.insecure} onChange={(e) => set("insecure", e.target.checked)} />
|
|
<span className="form-check-label">Accept a certificate that isn’t trusted (self-signed, a private authority). Its expiry is still watched.</span>
|
|
</label>
|
|
<label className="form-check mb-0">
|
|
<input type="checkbox" className="form-check-input" checked={draft.enabled} onChange={(e) => set("enabled", e.target.checked)} />
|
|
<span className="form-check-label">Switched on</span>
|
|
</label>
|
|
</div>
|
|
<div className="col-12 text-secondary small">Only addresses this server may reach are accepted: not itself (loopback) and not the cloud metadata address. Your own network is fine.</div>
|
|
</div>
|
|
<div className="card-footer d-flex gap-2">
|
|
<button type="submit" className="btn btn-primary" disabled={busy || draft.name.trim() === "" || draft.target.trim() === ""}>
|
|
{busy ? "Saving…" : "Save"}
|
|
</button>
|
|
<button type="button" className="btn" onClick={() => setDraft(null)}>
|
|
Cancel
|
|
</button>
|
|
</div>
|
|
</form>
|
|
)}
|
|
|
|
<div className="card">
|
|
<TableToolbar search={tableSearch.query} onSearch={tableSearch.setQuery} placeholder="Search checks…" shown={sorted?.length} total={rows.length} onExport={exportCsv} exportDisabled={!sorted || sorted.length === 0} />
|
|
<div className="table-responsive">
|
|
<table className="table table-vcenter card-table table-stack">
|
|
<thead>
|
|
<tr>
|
|
<SortableTh<Row> label="Check" sortKeyName="name" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
|
<SortableTh<Row> label="Status" sortKeyName="rank" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
|
<SortableTh<Row> label="Answer" sortKeyName="lastResponseMs" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
|
<SortableTh<Row> label="Uptime" sortKeyName="uptime24h" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
|
<SortableTh<Row> label="Certificate" sortKeyName="certDays" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
|
<SortableTh<Row> label="Checked" sortKeyName="lastCheckedAt" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
|
{(canCheck || isAdmin) && <th className="w-1">Actions</th>}
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
{checks === null && !error && (
|
|
<tr>
|
|
<td colSpan={7}>
|
|
<BlockSkeleton lines={3} />
|
|
</td>
|
|
</tr>
|
|
)}
|
|
{page.pageItems?.map((c) => (
|
|
<tr key={c.id}>
|
|
<td className="stack-wide">
|
|
<strong>{c.name}</strong> <span className="badge bg-secondary-lt text-secondary">{KIND_LABELS[c.kind]}</span>
|
|
<div className="text-secondary small text-break">
|
|
{c.target}
|
|
{c.port !== null ? `:${c.port}` : ""}
|
|
</div>
|
|
{c.valuePath && <div className="small text-secondary">{limitWords(c)}</div>}
|
|
{c.server && (
|
|
<div className="small">
|
|
about <Link to={`/servers/${c.server.id}`}>{c.server.name}</Link>
|
|
</div>
|
|
)}
|
|
</td>
|
|
<td>
|
|
<span className={`badge ${STATE_BADGE[c.state].badge}`}>{STATE_BADGE[c.state].label}</span>
|
|
{c.lastOk === false && c.lastMessage && <div className="text-secondary small">{c.lastMessage}</div>}
|
|
{c.lastOk === false && c.state === "failing" && (
|
|
<div className="text-secondary small">
|
|
failed {c.consecutiveFailures} of {c.failuresBeforeAlert}
|
|
</div>
|
|
)}
|
|
</td>
|
|
<td className="stack-label" data-label="Answer">
|
|
{c.lastValue !== null && (
|
|
<div className="fw-bold" title={limitWords(c)}>
|
|
{c.lastValue}
|
|
{c.valueUnit && Number.isFinite(Number(c.lastValue)) ? ` ${c.valueUnit}` : ""}
|
|
</div>
|
|
)}
|
|
{c.lastResponseMs === null ? <span className="text-secondary">—</span> : `${c.lastResponseMs} ms`}
|
|
{c.stats?.avgMs24h != null && <div className="text-secondary small">avg {c.stats.avgMs24h} ms</div>}
|
|
</td>
|
|
<td className="stack-label" data-label="Uptime">
|
|
{c.stats?.uptime24h == null ? (
|
|
<span className="text-secondary">—</span>
|
|
) : (
|
|
<>
|
|
{c.stats.uptime24h}% <span className="text-secondary small">24 h</span>
|
|
<div className="text-secondary small">{c.stats.uptime7d}% 7 d</div>
|
|
</>
|
|
)}
|
|
<div>
|
|
<Ticks recent={c.stats?.recent ?? []} />
|
|
</div>
|
|
<button type="button" className="btn btn-link btn-sm p-0" onClick={() => setHistoryFor({ id: c.id, name: c.name })}>
|
|
History…
|
|
</button>
|
|
</td>
|
|
<td className="stack-label" data-label="Certificate">
|
|
{c.certDays === null ? (
|
|
<span className="text-secondary">—</span>
|
|
) : c.certDays < 0 ? (
|
|
<span className="badge bg-red-lt text-red" title={c.certExpiresAt?.slice(0, 10)}>
|
|
expired {-c.certDays} d ago
|
|
</span>
|
|
) : c.certDays <= c.warnDays ? (
|
|
<span className={`badge ${c.certDays <= 3 ? "bg-red-lt text-red" : "bg-yellow-lt text-yellow"}`} title={c.certExpiresAt?.slice(0, 10)}>
|
|
{c.certDays} d left
|
|
</span>
|
|
) : (
|
|
<span className="text-secondary">{c.certDays} d left</span>
|
|
)}
|
|
</td>
|
|
<td className="text-secondary stack-label" data-label="Checked">
|
|
{c.lastCheckedAt ? <TimeAgo value={c.lastCheckedAt} /> : "—"}
|
|
</td>
|
|
{(canCheck || isAdmin) && (
|
|
<td className="stack-wide">
|
|
<div className="btn-list flex-nowrap">
|
|
{canCheck && (
|
|
<button className="btn btn-sm btn-outline-primary" disabled={asking === c.id} onClick={() => void askNow(c)}>
|
|
{asking === c.id ? "Asking…" : "Check now"}
|
|
</button>
|
|
)}
|
|
{isAdmin && (
|
|
<>
|
|
<button className="btn btn-sm btn-outline-secondary" onClick={() => setDraft(toDraft(c))}>
|
|
Edit
|
|
</button>
|
|
<button className="btn btn-sm btn-outline-danger" onClick={() => void remove(c)}>
|
|
Remove
|
|
</button>
|
|
</>
|
|
)}
|
|
</div>
|
|
</td>
|
|
)}
|
|
</tr>
|
|
))}
|
|
{checks !== null && sorted?.length === 0 && (
|
|
<EmptyRow colSpan={7} {...(tableSearch.active ? { filtered: () => tableSearch.setQuery("") } : { title: "Nothing is being checked yet", hint: "Ask a web address, a port or a certificate every few minutes, and hear about it when it stops answering or a certificate is about to run out.", action: isAdmin ? { label: "Add a check", onClick: () => setDraft({ ...EMPTY }) } : undefined })} />
|
|
)}
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
<Pagination page={page.page} pageCount={page.pageCount} totalCount={page.totalCount} onPageChange={page.setPage} />
|
|
</div>
|
|
{historyFor && <EndpointHistory checkId={historyFor.id} name={historyFor.name} onClose={() => setHistoryFor(null)} />}
|
|
</>
|
|
);
|
|
}
|
|
|