Heartbeats, Coming up and suggested checks; Operations menu tidied
Heartbeats: a cron job or script calls /api/heartbeat/<token> (and /start, /fail); the app alerts when the call is late or the job says it failed. Coming up: one agenda of everything dated (expiries, warranties, end of support, planned and recurring maintenance, restore tests, waiting updates), with a dashboard card and an iCalendar feed behind a share link. Suggested checks: web ports and certificates the app already knows about, added with a click. Menu: Incidents become Alerts -> History (old /incidents links redirect); new Monitoring group (Endpoints, Heartbeats, Uptime Kuma); osTicket under Automation, Admin Links under Infrastructure, Generator under Administration. Also makes the restore-test metrics test follow the real clock. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c05c847d17
commit
4e0c6927b2
44 files changed
+7092
-75
No files matched your search
+15
-4
@@ -1,5 +1,5 @@
|
||||
import { useEffect, useState, type ReactNode } from "react";
|
||||
import { Routes, Route, Navigate, useLocation } from "react-router-dom";
|
||||
import { Routes, Route, Navigate, useLocation, useParams } from "react-router-dom";
|
||||
import { api, type CurrentUser, type UserRole, UnauthorizedError } from "./api/client";
|
||||
import Login from "./pages/Login";
|
||||
import Dashboard from "./pages/Dashboard";
|
||||
@@ -29,13 +29,14 @@ import Alerts from "./pages/Alerts";
|
||||
import Generator from "./pages/Generator";
|
||||
import Maintenance from "./pages/Maintenance";
|
||||
import Updates from "./pages/Updates";
|
||||
import Incidents from "./pages/Incidents";
|
||||
import IncidentDetail from "./pages/IncidentDetail";
|
||||
import Inventory from "./pages/Inventory";
|
||||
import InventoryLabels from "./pages/InventoryLabels";
|
||||
import InventoryLifecycle from "./pages/InventoryLifecycle";
|
||||
import Dependencies from "./pages/Dependencies";
|
||||
import Endpoints from "./pages/Endpoints";
|
||||
import Heartbeats from "./pages/Heartbeats";
|
||||
import ComingUp from "./pages/ComingUp";
|
||||
import ChangeLog from "./pages/ChangeLog";
|
||||
import Backups from "./pages/Backups";
|
||||
import Domains from "./pages/Domains";
|
||||
@@ -83,6 +84,12 @@ function RequireRole({
|
||||
return <>{children}</>;
|
||||
}
|
||||
|
||||
/** An old /incidents/<id> link, sent to the same incident under Alerts. */
|
||||
function OldIncidentLink() {
|
||||
const { id } = useParams();
|
||||
return <Navigate to={/^\d+$/.test(id ?? "") ? `/alerts/incidents/${id}` : "/alerts?view=history"} replace />;
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
const [user, setUser] = useState<CurrentUser | null | undefined>(undefined);
|
||||
// A share link's page is for someone who isn't signed in: it asks nothing of the app's own session.
|
||||
@@ -156,6 +163,8 @@ function Shelled({ user }: { user: CurrentUser }) {
|
||||
<Route path="/inventory/lifecycle" element={<InventoryLifecycle />} />
|
||||
<Route path="/dependencies" element={<Dependencies user={user} />} />
|
||||
<Route path="/endpoints" element={<Endpoints user={user} />} />
|
||||
<Route path="/heartbeats" element={<Heartbeats user={user} />} />
|
||||
<Route path="/coming-up" element={<ComingUp user={user} />} />
|
||||
<Route path="/changes" element={user.role === "viewer" ? <Navigate to="/" replace /> : <ChangeLog />} />
|
||||
<Route path="/backups" element={<Backups user={user} />} />
|
||||
<Route path="/docker" element={<Docker user={user} />} />
|
||||
@@ -169,8 +178,10 @@ function Shelled({ user }: { user: CurrentUser }) {
|
||||
<Route path="/osticket" element={<OsTicket user={user} />} />
|
||||
<Route path="/admin-links" element={<AdminLinks user={user} />} />
|
||||
<Route path="/alerts" element={<Alerts user={user} />} />
|
||||
<Route path="/incidents" element={<Incidents />} />
|
||||
<Route path="/incidents/:id" element={<IncidentDetail user={user} />} />
|
||||
<Route path="/alerts/incidents/:id" element={<IncidentDetail user={user} />} />
|
||||
{/* Incidents used to be a page of their own: old links, bookmarks and notifications still arrive. */}
|
||||
<Route path="/incidents" element={<Navigate to="/alerts?view=history" replace />} />
|
||||
<Route path="/incidents/:id" element={<OldIncidentLink />} />
|
||||
<Route
|
||||
path="/users"
|
||||
element={
|
||||
|
||||
+83
-1
@@ -16,7 +16,7 @@ export interface CurrentUser {
|
||||
|
||||
export type ShareLinkDetail = "summary" | "names";
|
||||
|
||||
export type ShareLinkKind = "wall" | "status";
|
||||
export type ShareLinkKind = "wall" | "status" | "calendar";
|
||||
export type StatusItemKind = "server" | "integration" | "monitor";
|
||||
|
||||
/** One thing on a status page, as the editor sees it. */
|
||||
@@ -905,6 +905,74 @@ export interface EndpointInput {
|
||||
enabled?: boolean;
|
||||
}
|
||||
|
||||
/** A check the app could set up for you, from what it already knows. */
|
||||
export interface EndpointSuggestion {
|
||||
key: string;
|
||||
kind: "http" | "tls";
|
||||
name: string;
|
||||
target: string;
|
||||
port: number | null;
|
||||
serverId: number | null;
|
||||
serverName: string | null;
|
||||
reason: string;
|
||||
}
|
||||
|
||||
export type HeartbeatState = "off" | "waiting" | "up" | "running" | "late" | "failed";
|
||||
/** A job that reports in: a cron job or backup script calls its address when it finishes. */
|
||||
export interface Heartbeat {
|
||||
id: number;
|
||||
name: string;
|
||||
periodMinutes: number;
|
||||
graceMinutes: number;
|
||||
serverId: number | null;
|
||||
enabled: boolean;
|
||||
notes: string | null;
|
||||
lastPingAt: string | null;
|
||||
lastStatus: "ok" | "fail" | null;
|
||||
lastMessage: string | null;
|
||||
lastDurationMs: number | null;
|
||||
lastStartAt: string | null;
|
||||
pingCount: number;
|
||||
createdAt: string;
|
||||
/** The address to call, without the host; only administrators are given it. */
|
||||
path: string | null;
|
||||
state: HeartbeatState;
|
||||
/** ISO — when the next call is due by, counting the grace. */
|
||||
dueBy: string;
|
||||
server: { id: number; name: string } | null;
|
||||
recent: { at: string; kind: "ok" | "fail"; durationMs: number | null }[];
|
||||
}
|
||||
export interface HeartbeatInput {
|
||||
name: string;
|
||||
periodMinutes: number;
|
||||
graceMinutes?: number;
|
||||
serverId?: number | null;
|
||||
notes?: string | null;
|
||||
enabled?: boolean;
|
||||
}
|
||||
|
||||
export type AgendaKind = "secret" | "certificate" | "domain" | "tailscale" | "warranty" | "support" | "maintenance" | "restore" | "updates";
|
||||
export interface AgendaItem {
|
||||
id: string;
|
||||
kind: AgendaKind;
|
||||
/** YYYY-MM-DD for a day; an ISO time for maintenance. */
|
||||
at: string;
|
||||
endsAt: string | null;
|
||||
allDay: boolean;
|
||||
title: string;
|
||||
detail: string | null;
|
||||
link: string;
|
||||
serverId: number | null;
|
||||
/** Whole days from today; negative once it has passed. */
|
||||
daysLeft: number;
|
||||
}
|
||||
export interface Agenda {
|
||||
generatedAt: string;
|
||||
today: string;
|
||||
items: AgendaItem[];
|
||||
notes: string[];
|
||||
}
|
||||
|
||||
export type ChangeKind = "servers" | "maintenance" | "alerts" | "settings" | "integrations" | "dependencies" | "inventory" | "backups" | "endpoints" | "other";
|
||||
export interface ChangeEntry {
|
||||
id: string;
|
||||
@@ -1891,6 +1959,20 @@ export const api = {
|
||||
update: (id: number, data: EndpointInput) => request<{ check: EndpointCheck }>(`/api/endpoints/${id}`, { method: "PUT", body: JSON.stringify(data) }),
|
||||
remove: (id: number) => request<void>(`/api/endpoints/${id}`, { method: "DELETE" }),
|
||||
check: (id: number) => request<{ result: { ok: boolean; ms: number | null; message: string } }>(`/api/endpoints/${id}/check`, { method: "POST" }),
|
||||
suggestions: () => request<{ suggestions: EndpointSuggestion[]; dismissed: EndpointSuggestion[] }>("/api/endpoints/suggestions"),
|
||||
addSuggestions: (keys: string[]) => request<{ added: { id: number; name: string }[] }>("/api/endpoints/suggestions/add", { method: "POST", body: JSON.stringify({ keys }) }),
|
||||
dismissSuggestions: (keys: string[]) => request<{ suggestions: EndpointSuggestion[]; dismissed: EndpointSuggestion[] }>("/api/endpoints/suggestions/dismiss", { method: "POST", body: JSON.stringify({ keys }) }),
|
||||
restoreSuggestions: () => request<{ suggestions: EndpointSuggestion[]; dismissed: EndpointSuggestion[] }>("/api/endpoints/suggestions/restore", { method: "POST" }),
|
||||
},
|
||||
heartbeats: {
|
||||
list: () => request<{ heartbeats: Heartbeat[]; servers: { id: number; name: string }[]; baseUrl: string | null }>("/api/heartbeats"),
|
||||
create: (data: HeartbeatInput) => request<{ heartbeat: Heartbeat }>("/api/heartbeats", { method: "POST", body: JSON.stringify(data) }),
|
||||
update: (id: number, data: HeartbeatInput) => request<{ heartbeat: Heartbeat }>(`/api/heartbeats/${id}`, { method: "PUT", body: JSON.stringify(data) }),
|
||||
remove: (id: number) => request<void>(`/api/heartbeats/${id}`, { method: "DELETE" }),
|
||||
newAddress: (id: number) => request<{ path: string }>(`/api/heartbeats/${id}/new-address`, { method: "POST" }),
|
||||
},
|
||||
agenda: {
|
||||
get: (days = 400) => request<Agenda>(`/api/agenda?days=${days}`),
|
||||
},
|
||||
changes: {
|
||||
list: (params: { days?: number; kind?: string; serverId?: number; q?: string; before?: string; limit?: number }) => {
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { api, type EndpointSuggestion } from "../api/client";
|
||||
import { readableError } from "../utils/errors";
|
||||
import { toast } from "../utils/toast";
|
||||
|
||||
/**
|
||||
* Checks the app could set up for you, from what it already knows: a web port a server is listening on (with the name DNS gives it) and a certificate a secret already
|
||||
* reads. One click adds one, a button adds them all; "Not for me" stops one being offered, and they can be brought back. Administrators only, like the checks.
|
||||
*/
|
||||
export default function EndpointSuggestions({ onAdded }: { onAdded: () => void }) {
|
||||
const [offered, setOffered] = useState<EndpointSuggestion[] | null>(null);
|
||||
const [dismissed, setDismissed] = useState<EndpointSuggestion[]>([]);
|
||||
const [open, setOpen] = useState(true);
|
||||
const [busy, setBusy] = useState<string | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
const take = (res: { suggestions: EndpointSuggestion[]; dismissed: EndpointSuggestion[] }) => {
|
||||
setOffered(res.suggestions);
|
||||
setDismissed(res.dismissed);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
api.endpoints
|
||||
.suggestions()
|
||||
.then(take)
|
||||
.catch((err) => setError(readableError(err)));
|
||||
}, []);
|
||||
|
||||
async function add(keys: string[], label: string) {
|
||||
setBusy(label);
|
||||
setError(null);
|
||||
try {
|
||||
const { added } = await api.endpoints.addSuggestions(keys);
|
||||
toast.success(added.length === 1 ? `Added ${added[0].name}. It is asked within a minute.` : `Added ${added.length} checks. They are asked within a minute.`);
|
||||
take(await api.endpoints.suggestions());
|
||||
onAdded();
|
||||
} catch (err) {
|
||||
setError(readableError(err));
|
||||
} finally {
|
||||
setBusy(null);
|
||||
}
|
||||
}
|
||||
|
||||
async function dismiss(keys: string[], label: string) {
|
||||
setBusy(label);
|
||||
try {
|
||||
take(await api.endpoints.dismissSuggestions(keys));
|
||||
} catch (err) {
|
||||
setError(readableError(err));
|
||||
} finally {
|
||||
setBusy(null);
|
||||
}
|
||||
}
|
||||
|
||||
async function bringBack() {
|
||||
setBusy("restore");
|
||||
try {
|
||||
take(await api.endpoints.restoreSuggestions());
|
||||
} catch (err) {
|
||||
setError(readableError(err));
|
||||
} finally {
|
||||
setBusy(null);
|
||||
}
|
||||
}
|
||||
|
||||
if (offered === null) return error ? <div className="alert alert-danger">{error}</div> : null;
|
||||
if (offered.length === 0 && dismissed.length === 0) return null;
|
||||
|
||||
return (
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">
|
||||
{offered.length > 0 ? `Suggested checks (${offered.length})` : "No suggestions right now"}
|
||||
</h3>
|
||||
<div className="card-actions d-flex gap-2">
|
||||
{offered.length > 1 && open && (
|
||||
<button className="btn btn-sm btn-primary" disabled={busy !== null} onClick={() => void add(offered.map((s) => s.key), "all")}>
|
||||
{busy === "all" ? "Adding…" : `Add all ${offered.length}`}
|
||||
</button>
|
||||
)}
|
||||
{offered.length > 0 && (
|
||||
<button className="btn btn-sm btn-outline-secondary" onClick={() => setOpen((o) => !o)} aria-expanded={open}>
|
||||
{open ? "Hide" : "Show"}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
{error && <div className="alert alert-danger m-3 mb-0">{error}</div>}
|
||||
{open && offered.length > 0 && (
|
||||
<>
|
||||
<div className="card-body pb-0 text-secondary">
|
||||
From what the app already knows: web ports your servers are listening on (with the names DNS gives them) and certificates your secrets read. Nothing is asked until you add it.
|
||||
</div>
|
||||
<div className="list-group list-group-flush">
|
||||
{offered.map((s) => (
|
||||
<div className="list-group-item" key={s.key}>
|
||||
<div className="row align-items-center g-2">
|
||||
<div className="col" style={{ minWidth: 0 }}>
|
||||
<div className="text-break">
|
||||
<strong>{s.name}</strong> <span className="badge bg-secondary-lt text-secondary">{s.kind === "http" ? "Web address" : "Certificate"}</span>
|
||||
</div>
|
||||
<div className="text-secondary small text-break">
|
||||
{s.target}
|
||||
{s.port !== null ? `:${s.port}` : ""}
|
||||
</div>
|
||||
<div className="text-secondary small">
|
||||
{s.reason}
|
||||
{s.serverId !== null && s.serverName && (
|
||||
<>
|
||||
{" "}
|
||||
<Link to={`/servers/${s.serverId}`}>{s.serverName}</Link>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-auto">
|
||||
<div className="btn-list flex-nowrap">
|
||||
<button className="btn btn-sm btn-primary" disabled={busy !== null} onClick={() => void add([s.key], s.key)}>
|
||||
{busy === s.key ? "Adding…" : "Add"}
|
||||
</button>
|
||||
<button className="btn btn-sm btn-outline-secondary" disabled={busy !== null} onClick={() => void dismiss([s.key], s.key)}>
|
||||
Not for me
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
{dismissed.length > 0 && (
|
||||
<div className="card-footer text-secondary small d-flex align-items-center gap-2">
|
||||
{dismissed.length} dismissed.
|
||||
<button className="btn btn-sm btn-link p-0" disabled={busy !== null} onClick={() => void bringBack()}>
|
||||
Offer {dismissed.length === 1 ? "it" : "them"} again
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -4,15 +4,15 @@ import { api, type AlertCategory, type IncidentSummary } from "../api/client";
|
||||
import { useSortable } from "../hooks/useSortable";
|
||||
import { useTableSearch } from "../hooks/useTableSearch";
|
||||
import { usePagination } from "../hooks/usePagination";
|
||||
import SortableTh from "../components/SortableTh";
|
||||
import Pagination from "../components/Pagination";
|
||||
import TableToolbar from "../components/TableToolbar";
|
||||
import TimeAgo from "../components/TimeAgo";
|
||||
import { BlockSkeleton } from "../components/Skeleton";
|
||||
import { ErrorNotice } from "../components/Notice";
|
||||
import SortableTh from "./SortableTh";
|
||||
import Pagination from "./Pagination";
|
||||
import TableToolbar from "./TableToolbar";
|
||||
import TimeAgo from "./TimeAgo";
|
||||
import { BlockSkeleton } from "./Skeleton";
|
||||
import { ErrorNotice } from "./Notice";
|
||||
import { downloadCsv } from "../utils/csv";
|
||||
import { readableError } from "../utils/errors";
|
||||
import { EmptyRow } from "../components/EmptyState";
|
||||
import { EmptyRow } from "./EmptyState";
|
||||
|
||||
export const CATEGORY_NAMES: Record<AlertCategory, string> = {
|
||||
offline: "Server down",
|
||||
@@ -39,13 +39,16 @@ export function durationWords(ms: number): string {
|
||||
|
||||
export const SEVERITY_BADGE: Record<string, string> = { critical: "bg-red-lt text-red", warning: "bg-yellow-lt text-yellow", info: "bg-blue-lt text-blue" };
|
||||
|
||||
/** Where one incident's page is: under Alerts, whose History it is part of. */
|
||||
export const incidentPath = (id: number) => `/alerts/incidents/${id}`;
|
||||
|
||||
type Row = IncidentSummary & { where: string; openFirst: number };
|
||||
|
||||
/**
|
||||
* Every time something was raised as an alert and later went away: when it began, how long it lasted, how bad it got. Open ones are on top.
|
||||
* Open one for everything that happened around it.
|
||||
* The History side of the Alerts page: every time something was raised as an alert and later went away — when it began, how long it lasted, how bad it
|
||||
* got. Open ones are on top. Open one for everything that happened around it.
|
||||
*/
|
||||
export default function Incidents() {
|
||||
export default function IncidentHistory() {
|
||||
const [incidents, setIncidents] = useState<IncidentSummary[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [status, setStatus] = useState<"all" | "open" | "resolved">("all");
|
||||
@@ -93,12 +96,9 @@ export default function Incidents() {
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="d-flex align-items-center mb-1">
|
||||
<h2 className="page-title mb-0">Incidents</h2>
|
||||
</div>
|
||||
<p className="text-secondary">
|
||||
Each time an alert was raised and later went away is one incident, kept with when it began and ended. Open one to see everything the app knows about that time — who acknowledged it, the maintenance windows, what was changed, the update runs and the notes people wrote.
|
||||
They are recorded from the <Link to="/alerts">Alerts</Link> every few minutes, so one that comes and goes between two looks may not be here.
|
||||
They are recorded from the current alerts every few minutes, so one that comes and goes between two looks may not be here.
|
||||
</p>
|
||||
<ErrorNotice error={error} />
|
||||
|
||||
@@ -167,7 +167,7 @@ export default function Incidents() {
|
||||
<td>{CATEGORY_NAMES[i.category] ?? i.category}</td>
|
||||
<td>{i.target && i.target.type === "server" ? <Link to={`/servers/${i.target.id}`}>{i.where}</Link> : i.where}</td>
|
||||
<td>
|
||||
<Link to={`/incidents/${i.id}`}>{i.message}</Link>
|
||||
<Link to={incidentPath(i.id)}>{i.message}</Link>
|
||||
{i.causedBy && <span className="badge bg-secondary-lt text-secondary ms-2">caused by {i.causedBy}</span>}
|
||||
{i.notes > 0 && (
|
||||
<span className="text-secondary small ms-2">
|
||||
+17
-8
@@ -15,7 +15,6 @@ import {
|
||||
IconUsers,
|
||||
IconDevices,
|
||||
IconHistory,
|
||||
IconTimeline,
|
||||
IconStethoscope,
|
||||
IconSettings,
|
||||
IconWand,
|
||||
@@ -36,6 +35,8 @@ import {
|
||||
IconExternalLink,
|
||||
IconAlertTriangle,
|
||||
IconSitemap,
|
||||
IconCalendarEvent,
|
||||
IconHeartRateMonitor,
|
||||
} from "@tabler/icons-react";
|
||||
import type { CurrentUser } from "../api/client";
|
||||
|
||||
@@ -80,6 +81,7 @@ export const NAV: NavEntry[] = [
|
||||
{ to: "/map", label: "Map", icon: <IconSitemap size={20} /> },
|
||||
{ to: "/inventory", label: "Inventory", icon: <IconBox size={20} /> },
|
||||
{ to: "/dependencies", label: "Dependencies", icon: <IconHierarchy2 size={20} /> },
|
||||
{ to: "/admin-links", label: "Admin Links", icon: <IconExternalLink size={20} /> },
|
||||
],
|
||||
},
|
||||
{
|
||||
@@ -91,10 +93,19 @@ export const NAV: NavEntry[] = [
|
||||
{ to: "/domains", label: "Domains", icon: <IconWorldWww size={20} /> },
|
||||
{ to: "/ipam", label: "IP Addresses", icon: <IconNetwork size={20} /> },
|
||||
{ to: "/ports", label: "Ports", icon: <IconPlug size={20} /> },
|
||||
{ to: "/endpoints", label: "Endpoints", icon: <IconHeartbeat size={20} /> },
|
||||
{ to: "/consistency", label: "Consistency", icon: <IconListCheck size={20} /> },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "monitoring",
|
||||
label: "Monitoring",
|
||||
icon: <IconHeartbeat size={20} />,
|
||||
items: [
|
||||
{ to: "/endpoints", label: "Endpoints", icon: <IconHeartbeat size={20} /> },
|
||||
{ to: "/heartbeats", label: "Heartbeats", icon: <IconHeartRateMonitor size={20} /> },
|
||||
{ to: "/uptime-kuma", label: "Uptime Kuma", icon: <IconActivityHeartbeat size={20} /> },
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "automation",
|
||||
label: "Automation",
|
||||
@@ -102,6 +113,7 @@ export const NAV: NavEntry[] = [
|
||||
items: [
|
||||
{ to: "/semaphore", label: "Semaphore", icon: <IconPlayerPlay size={20} /> },
|
||||
{ to: "/gitea", label: "Gitea", icon: <IconBrandGit size={20} /> },
|
||||
{ to: "/osticket", label: "osTicket", icon: <IconTicket size={20} /> },
|
||||
],
|
||||
},
|
||||
{ to: "/secrets", label: "Secrets", icon: <IconKey size={20} /> },
|
||||
@@ -111,14 +123,10 @@ export const NAV: NavEntry[] = [
|
||||
icon: <IconTool size={20} />,
|
||||
items: [
|
||||
{ to: "/alerts", label: "Alerts", icon: <IconAlertTriangle size={20} /> },
|
||||
{ to: "/incidents", label: "Incidents", icon: <IconTimeline size={20} /> },
|
||||
{ to: "/changes", label: "Change log", icon: <IconGitCommit size={20} />, minRole: "operator" },
|
||||
{ to: "/maintenance", label: "Maintenance", icon: <IconTool size={20} /> },
|
||||
{ to: "/updates", label: "Updates", icon: <IconDownload size={20} /> },
|
||||
{ to: "/uptime-kuma", label: "Uptime Kuma", icon: <IconActivityHeartbeat size={20} /> },
|
||||
{ to: "/osticket", label: "osTicket", icon: <IconTicket size={20} /> },
|
||||
{ to: "/admin-links", label: "Admin Links", icon: <IconExternalLink size={20} /> },
|
||||
{ to: "/generator", label: "Generator", icon: <IconWand size={20} /> },
|
||||
{ to: "/coming-up", label: "Coming up", icon: <IconCalendarEvent size={20} /> },
|
||||
{ to: "/changes", label: "Change log", icon: <IconGitCommit size={20} />, minRole: "operator" },
|
||||
],
|
||||
},
|
||||
{
|
||||
@@ -127,6 +135,7 @@ export const NAV: NavEntry[] = [
|
||||
icon: <IconSettings size={20} />,
|
||||
items: [
|
||||
{ to: "/integrations", label: "Integrations", icon: <IconPlugConnected size={20} /> },
|
||||
{ to: "/generator", label: "Generator", icon: <IconWand size={20} /> },
|
||||
{ to: "/users", label: "Users", icon: <IconUsers size={20} />, minRole: "admin" },
|
||||
{ to: "/sessions", label: "Sessions", icon: <IconDevices size={20} />, minRole: "admin" },
|
||||
{ to: "/audit-log", label: "Audit Log", icon: <IconHistory size={20} />, minRole: "operator" },
|
||||
|
||||
@@ -18,6 +18,7 @@ import AckDrawer, { ackWords } from "../components/AckDrawer";
|
||||
import { useAlertsReport } from "../hooks/useAlertsReport";
|
||||
import { summariseAlerts } from "../utils/alertSummary";
|
||||
import { EmptyRow } from "../components/EmptyState";
|
||||
import IncidentHistory, { incidentPath } from "../components/IncidentHistory";
|
||||
|
||||
const SEVERITY: Record<AlertSeverity, { label: string; badge: string; rank: number }> = {
|
||||
critical: { label: "Critical", badge: "bg-red-lt text-red", rank: 0 },
|
||||
@@ -40,7 +41,41 @@ const CATEGORY_LABELS: Record<AlertCategory, string> = {
|
||||
|
||||
type Row = AlertItem & { rank: number };
|
||||
|
||||
/** Now and History: what is wrong right now, and every time something was raised and went away. The same page, switched by `?view=history`. */
|
||||
function ViewTabs({ view }: { view: "now" | "history" }) {
|
||||
return (
|
||||
<ul className="nav nav-tabs mb-3" aria-label="Alerts view">
|
||||
<li className="nav-item">
|
||||
<Link to="/alerts" className={`nav-link ${view === "now" ? "active" : ""}`} aria-current={view === "now" ? "page" : undefined}>
|
||||
Now
|
||||
</Link>
|
||||
</li>
|
||||
<li className="nav-item">
|
||||
<Link to="/alerts?view=history" className={`nav-link ${view === "history" ? "active" : ""}`} aria-current={view === "history" ? "page" : undefined}>
|
||||
History
|
||||
</Link>
|
||||
</li>
|
||||
</ul>
|
||||
);
|
||||
}
|
||||
|
||||
export default function Alerts({ user }: { user: CurrentUser }) {
|
||||
const [params] = useSearchParams();
|
||||
if (params.get("view") === "history") {
|
||||
return (
|
||||
<>
|
||||
<div className="d-flex align-items-center mb-2">
|
||||
<h2 className="page-title mb-0">Alerts</h2>
|
||||
</div>
|
||||
<ViewTabs view="history" />
|
||||
<IncidentHistory />
|
||||
</>
|
||||
);
|
||||
}
|
||||
return <AlertsNow user={user} tabs={<ViewTabs view="now" />} />;
|
||||
}
|
||||
|
||||
function AlertsNow({ user, tabs }: { user: CurrentUser; tabs: React.ReactNode }) {
|
||||
const canSilence = user.role === "admin" || user.role === "operator";
|
||||
// The count beside Alerts in the menu is a shared one on its own timer; after an acknowledgement it should change at once.
|
||||
const { reload: reloadBadge } = useAlertsReport();
|
||||
@@ -162,6 +197,7 @@ export default function Alerts({ user }: { user: CurrentUser }) {
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{tabs}
|
||||
<div className="text-secondary mb-3">
|
||||
What's wrong right now across your servers and integrations — full disks, servers that stopped reporting, failed backups, updates waiting,
|
||||
things about to expire. It runs the same checks that send notifications, whether or not those notifications are switched on.
|
||||
@@ -356,7 +392,7 @@ export default function Alerts({ user }: { user: CurrentUser }) {
|
||||
)}
|
||||
{a.incidentId != null && (
|
||||
<div className="small">
|
||||
<Link to={`/incidents/${a.incidentId}`}>Timeline</Link>
|
||||
<Link to={incidentPath(a.incidentId)}>Timeline</Link>
|
||||
</div>
|
||||
)}
|
||||
{a.target && (
|
||||
|
||||
@@ -0,0 +1,318 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { Link, useSearchParams } from "react-router-dom";
|
||||
import { api, type Agenda, type AgendaItem, type AgendaKind, type CurrentUser } from "../api/client";
|
||||
import { ErrorNotice } from "../components/Notice";
|
||||
import { BlockSkeleton } from "../components/Skeleton";
|
||||
import EmptyState from "../components/EmptyState";
|
||||
import { downloadCsv } from "../utils/csv";
|
||||
import { formatDate, formatTime } from "../utils/date";
|
||||
import { readableError } from "../utils/errors";
|
||||
|
||||
const KINDS: { id: AgendaKind; label: string }[] = [
|
||||
{ id: "secret", label: "Secrets" },
|
||||
{ id: "certificate", label: "Certificates" },
|
||||
{ id: "domain", label: "Domains" },
|
||||
{ id: "tailscale", label: "Tailscale keys" },
|
||||
{ id: "warranty", label: "Warranties" },
|
||||
{ id: "support", label: "End of support" },
|
||||
{ id: "maintenance", label: "Maintenance" },
|
||||
{ id: "restore", label: "Restore tests" },
|
||||
{ id: "updates", label: "Updates waiting" },
|
||||
];
|
||||
const KIND_LABEL = Object.fromEntries(KINDS.map((k) => [k.id, k.label])) as Record<AgendaKind, string>;
|
||||
|
||||
const RANGES: { days: number; label: string }[] = [
|
||||
{ days: 30, label: "Next 30 days" },
|
||||
{ days: 90, label: "Next 3 months" },
|
||||
{ days: 180, label: "Next 6 months" },
|
||||
{ days: 400, label: "Next year" },
|
||||
];
|
||||
|
||||
/** "today", "tomorrow", "in 5 days", "3 days ago". */
|
||||
function relative(daysLeft: number): string {
|
||||
if (daysLeft === 0) return "today";
|
||||
if (daysLeft === 1) return "tomorrow";
|
||||
if (daysLeft === -1) return "yesterday";
|
||||
return daysLeft > 0 ? `in ${daysLeft} days` : `${-daysLeft} days ago`;
|
||||
}
|
||||
|
||||
/** A day as the app's date format writes it (the string is a plain day, so it is read as one, not shifted by the viewer's zone). */
|
||||
const dayOf = (ymd: string) => {
|
||||
const [y, m, d] = ymd.split("-").map(Number);
|
||||
return new Date(y, m - 1, d);
|
||||
};
|
||||
const weekday = (ymd: string) => dayOf(ymd).toLocaleDateString(undefined, { weekday: "short" });
|
||||
|
||||
interface Section {
|
||||
id: string;
|
||||
title: string;
|
||||
hint?: string;
|
||||
items: AgendaItem[];
|
||||
}
|
||||
|
||||
function sectionsOf(items: AgendaItem[]): Section[] {
|
||||
const now = items.filter((i) => i.daysLeft < 0 || i.kind === "updates");
|
||||
const rest = items.filter((i) => !(i.daysLeft < 0 || i.kind === "updates"));
|
||||
return [
|
||||
{ id: "now", title: "Needs attention now", hint: "Already past its date, or waiting", items: now },
|
||||
{ id: "today", title: "Today", items: rest.filter((i) => i.daysLeft === 0) },
|
||||
{ id: "week", title: "This week", items: rest.filter((i) => i.daysLeft >= 1 && i.daysLeft <= 7) },
|
||||
{ id: "month", title: "The rest of the month", hint: "8 to 30 days away", items: rest.filter((i) => i.daysLeft >= 8 && i.daysLeft <= 30) },
|
||||
{ id: "later", title: "Further ahead", items: rest.filter((i) => i.daysLeft > 30) },
|
||||
].filter((s) => s.items.length > 0);
|
||||
}
|
||||
|
||||
function When({ item }: { item: AgendaItem }) {
|
||||
if (item.allDay) {
|
||||
return (
|
||||
<>
|
||||
<div>
|
||||
{weekday(item.at)} {formatDate(dayOf(item.at))}
|
||||
</div>
|
||||
{item.kind !== "updates" && <div className="text-secondary small">{relative(item.daysLeft)}</div>}
|
||||
</>
|
||||
);
|
||||
}
|
||||
const start = new Date(item.at);
|
||||
const end = item.endsAt ? new Date(item.endsAt) : null;
|
||||
return (
|
||||
<>
|
||||
<div>
|
||||
{start.toLocaleDateString(undefined, { weekday: "short" })} {formatDate(start)}
|
||||
</div>
|
||||
<div className="text-secondary small">
|
||||
{formatTime(start, false)}
|
||||
{end ? `–${formatTime(end, false)}` : ""} · {relative(item.daysLeft)}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Everything with a date ahead in one list: secrets, domains and certificates that expire, Tailscale keys, warranties, end of support, planned and recurring
|
||||
* maintenance, restore tests that are due, and updates that have been waiting — nearest first. Narrow it by kind, by how far ahead, or by server. The same list
|
||||
* can be put in a phone's calendar (Settings → Share links → a calendar feed).
|
||||
*/
|
||||
export default function ComingUp({ user }: { user: CurrentUser }) {
|
||||
const [params, setParams] = useSearchParams();
|
||||
const days = RANGES.some((r) => r.days === Number(params.get("days"))) ? Number(params.get("days")) : 90;
|
||||
const chosen = useMemo(() => new Set((params.get("kinds") ?? "").split(",").filter((k): k is AgendaKind => KINDS.some((x) => x.id === k))), [params]);
|
||||
const serverId = /^\d+$/.test(params.get("server") ?? "") ? Number(params.get("server")) : null;
|
||||
|
||||
const [everyOccurrence, setEveryOccurrence] = useState(false);
|
||||
const [agenda, setAgenda] = useState<Agenda | null>(null);
|
||||
const [servers, setServers] = useState<Map<number, string>>(new Map());
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
const load = () =>
|
||||
api.agenda
|
||||
.get(400)
|
||||
.then((res) => alive && (setAgenda(res), setError(null)))
|
||||
.catch((err) => alive && setError(readableError(err)));
|
||||
load();
|
||||
api.servers
|
||||
.list()
|
||||
.then((res) => alive && setServers(new Map(res.servers.map((s) => [s.id, s.name]))))
|
||||
.catch(() => {});
|
||||
const t = setInterval(load, 5 * 60_000);
|
||||
return () => {
|
||||
alive = false;
|
||||
clearInterval(t);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const setParam = (key: string, value: string | null) =>
|
||||
setParams(
|
||||
(prev) => {
|
||||
const next = new URLSearchParams(prev);
|
||||
if (value) next.set(key, value);
|
||||
else next.delete(key);
|
||||
return next;
|
||||
},
|
||||
{ replace: true },
|
||||
);
|
||||
const toggleKind = (id: AgendaKind) => {
|
||||
const next = new Set(chosen);
|
||||
if (next.has(id)) next.delete(id);
|
||||
else next.add(id);
|
||||
setParam("kinds", [...next].join(",") || null);
|
||||
};
|
||||
|
||||
const withinRange = useMemo(() => (agenda?.items ?? []).filter((i) => i.kind === "updates" || i.daysLeft <= days), [agenda, days]);
|
||||
// A schedule that happens every week would take a line a week: by default only its next time is listed, and the rest can be asked for.
|
||||
const { inRange, hiddenRecurring } = useMemo(() => {
|
||||
if (everyOccurrence) return { inRange: withinRange, hiddenRecurring: 0 };
|
||||
const seen = new Set<string>();
|
||||
let hidden = 0;
|
||||
const kept = withinRange.filter((i) => {
|
||||
const schedule = /^schedule:(\d+):/.exec(i.id)?.[1];
|
||||
if (!schedule) return true;
|
||||
if (seen.has(schedule)) {
|
||||
hidden++;
|
||||
return false;
|
||||
}
|
||||
seen.add(schedule);
|
||||
return true;
|
||||
});
|
||||
return { inRange: kept, hiddenRecurring: hidden };
|
||||
}, [withinRange, everyOccurrence]);
|
||||
const counts = useMemo(() => {
|
||||
const out = new Map<AgendaKind, number>();
|
||||
for (const i of inRange) out.set(i.kind, (out.get(i.kind) ?? 0) + 1);
|
||||
return out;
|
||||
}, [inRange]);
|
||||
const serversWithItems = useMemo(() => [...new Set(inRange.map((i) => i.serverId).filter((s): s is number => s !== null))].sort((a, b) => (servers.get(a) ?? "").localeCompare(servers.get(b) ?? "")), [inRange, servers]);
|
||||
const shown = inRange.filter((i) => (chosen.size === 0 || chosen.has(i.kind)) && (serverId === null || i.serverId === serverId));
|
||||
const sections = sectionsOf(shown);
|
||||
const filtered = chosen.size > 0 || serverId !== null;
|
||||
|
||||
const needNow = inRange.filter((i) => i.daysLeft < 0 && i.kind !== "updates").length;
|
||||
const thisWeek = inRange.filter((i) => i.daysLeft >= 0 && i.daysLeft <= 7 && i.kind !== "updates").length;
|
||||
const cards = [
|
||||
{ label: "Past their date", value: agenda ? String(needNow) : "…", color: needNow > 0 ? "text-red" : "text-green" },
|
||||
{ label: "In the next 7 days", value: agenda ? String(thisWeek) : "…", color: thisWeek > 0 ? "text-yellow" : "" },
|
||||
{ label: "In the list", value: agenda ? String(shown.length) : "…", color: "" },
|
||||
];
|
||||
|
||||
function exportCsv() {
|
||||
downloadCsv(
|
||||
"coming-up.csv",
|
||||
["Date", "Ends", "What", "Kind", "Details", "Days from today", "Page"],
|
||||
shown.map((i) => [i.at, i.endsAt ?? "", i.title, KIND_LABEL[i.kind], i.detail ?? "", i.daysLeft, i.link]),
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="d-flex flex-wrap align-items-center gap-2 mb-1">
|
||||
<h2 className="page-title mb-0">Coming up</h2>
|
||||
<button className="btn btn-outline-secondary ms-auto" onClick={exportCsv} disabled={shown.length === 0}>
|
||||
Export CSV
|
||||
</button>
|
||||
</div>
|
||||
<p className="text-secondary">
|
||||
What is about to need attention, nearest first: things that expire, hardware that ages out, planned maintenance, restore tests that are due. Each also raises its own alert when it gets close.
|
||||
{user.role === "admin" ? (
|
||||
<>
|
||||
{" "}
|
||||
To have it in your phone’s calendar, make a <Link to="/settings/share">calendar feed</Link>.
|
||||
</>
|
||||
) : (
|
||||
" An administrator can make a calendar feed of it for your phone."
|
||||
)}
|
||||
</p>
|
||||
<ErrorNotice error={error} />
|
||||
{agenda && agenda.notes.length > 0 && (
|
||||
<div className="alert alert-warning" role="status">
|
||||
Something couldn’t be read, so this list may be missing entries: {agenda.notes.join(" · ")}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<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>
|
||||
|
||||
<div className="card mb-3">
|
||||
<div className="card-body">
|
||||
<div className="d-flex flex-wrap gap-2 align-items-center mb-2">
|
||||
<select className="form-select w-auto" aria-label="How far ahead" value={days} onChange={(e) => setParam("days", e.target.value === "90" ? null : e.target.value)}>
|
||||
{RANGES.map((r) => (
|
||||
<option key={r.days} value={r.days}>
|
||||
{r.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
{serversWithItems.length > 0 && (
|
||||
<select className="form-select w-auto" aria-label="Server" value={serverId ?? ""} onChange={(e) => setParam("server", e.target.value || null)}>
|
||||
<option value="">Every server</option>
|
||||
{serversWithItems.map((id) => (
|
||||
<option key={id} value={id}>
|
||||
{servers.get(id) ?? `Server ${id}`}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
)}
|
||||
{(hiddenRecurring > 0 || everyOccurrence) && (
|
||||
<label className="form-check mb-0 ms-2">
|
||||
<input type="checkbox" className="form-check-input" checked={everyOccurrence} onChange={(e) => setEveryOccurrence(e.target.checked)} />
|
||||
<span className="form-check-label">Every time a recurring maintenance happens{hiddenRecurring > 0 ? ` (${hiddenRecurring} more)` : ""}</span>
|
||||
</label>
|
||||
)}
|
||||
{filtered && (
|
||||
<button className="btn btn-sm btn-link" onClick={() => setParams(new URLSearchParams(days === 90 ? {} : { days: String(days) }), { replace: true })}>
|
||||
Clear filters
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<div className="d-flex flex-wrap gap-2" role="group" aria-label="Kinds of things">
|
||||
{KINDS.map((k) => {
|
||||
const n = counts.get(k.id) ?? 0;
|
||||
const on = chosen.has(k.id);
|
||||
return (
|
||||
<button key={k.id} type="button" className={`btn btn-sm ${on ? "btn-primary" : "btn-outline-secondary"}`} aria-pressed={on} disabled={n === 0 && !on} onClick={() => toggleKind(k.id)}>
|
||||
{k.label} <span className={`ms-1 ${on ? "" : "text-secondary"}`}>{n}</span>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{agenda === null && !error && <BlockSkeleton lines={5} />}
|
||||
{agenda !== null && sections.length === 0 && (
|
||||
<div className="card">
|
||||
{filtered ? (
|
||||
<EmptyState filtered title="Nothing matches that" hint="Nothing with a date fits the kinds and server chosen. Try a longer range, or fewer filters." action={{ label: "Clear filters", onClick: () => setParams(new URLSearchParams(days === 90 ? {} : { days: String(days) }), { replace: true }) }} />
|
||||
) : (
|
||||
<EmptyState title="Nothing is coming up" hint={`Nothing expires, ends or is planned in the next ${days} days. Dates come from Secrets, Domains, Inventory (warranty and end of support), Maintenance and the endpoint checks' certificates.`} />
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{sections.map((s) => (
|
||||
<div className="card mb-3" key={s.id}>
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">{s.title}</h3>
|
||||
<div className="card-subtitle text-secondary ms-2">{s.hint ?? ""}</div>
|
||||
</div>
|
||||
<div className="list-group list-group-flush">
|
||||
{s.items.map((i) => (
|
||||
<div className="list-group-item" key={i.id}>
|
||||
<div className="row align-items-center g-2">
|
||||
<div className="col-5 col-md-3 col-lg-2">
|
||||
<When item={i} />
|
||||
</div>
|
||||
<div className="col" style={{ minWidth: 0 }}>
|
||||
<div className="text-break">
|
||||
<Link to={i.link}>{i.title}</Link>
|
||||
{i.serverId !== null && servers.has(i.serverId) && (
|
||||
<span className="text-secondary small">
|
||||
{" "}
|
||||
· <Link to={`/servers/${i.serverId}`}>{servers.get(i.serverId)}</Link>
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
{i.detail && <div className="text-secondary small text-break">{i.detail}</div>}
|
||||
</div>
|
||||
<div className="col-auto">
|
||||
<span className={`badge ${i.daysLeft < 0 && i.kind !== "updates" ? "bg-red-lt text-red" : i.daysLeft <= 7 && i.kind !== "maintenance" && i.kind !== "updates" ? "bg-yellow-lt text-yellow" : "bg-secondary-lt text-secondary"}`}>{KIND_LABEL[i.kind]}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -23,6 +23,7 @@ import StatusStrip from "../components/StatusStrip";
|
||||
import SetupGuide, { type SetupStep } from "../components/SetupGuide";
|
||||
import { ErrorNotice } from "../components/Notice";
|
||||
import { WidgetSkeleton } from "../components/Skeleton";
|
||||
import type { Agenda, Heartbeat } from "../api/client";
|
||||
|
||||
const DNS_TYPE_COLORS: Record<string, string> = {
|
||||
A: "#60a5fa",
|
||||
@@ -364,6 +365,8 @@ export default function Dashboard({ user }: { user: CurrentUser }) {
|
||||
const [serverError, setServerError] = useState<string | null>(null);
|
||||
const [domainList, setDomainList] = useState<DomainList | null>(null);
|
||||
const [endpointChecks, setEndpointChecks] = useState<EndpointCheck[] | null>(null);
|
||||
const [agenda, setAgenda] = useState<Agenda | null>(null);
|
||||
const [heartbeatList, setHeartbeatList] = useState<Heartbeat[] | null>(null);
|
||||
const [domainError, setDomainError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -371,6 +374,14 @@ export default function Dashboard({ user }: { user: CurrentUser }) {
|
||||
.list()
|
||||
.then((res) => setEndpointChecks(res.checks))
|
||||
.catch(() => setEndpointChecks([]));
|
||||
api.agenda
|
||||
.get(30)
|
||||
.then(setAgenda)
|
||||
.catch(() => setAgenda({ generatedAt: "", today: "", items: [], notes: [] }));
|
||||
api.heartbeats
|
||||
.list()
|
||||
.then((res) => setHeartbeatList(res.heartbeats))
|
||||
.catch(() => setHeartbeatList([]));
|
||||
api.domains
|
||||
.list()
|
||||
.then(setDomainList)
|
||||
@@ -614,11 +625,28 @@ export default function Dashboard({ user }: { user: CurrentUser }) {
|
||||
const endpointsDown = (endpointChecks ?? []).filter((c) => c.enabled && c.lastOk === false && c.consecutiveFailures >= c.failuresBeforeAlert);
|
||||
const endpointCerts = (endpointChecks ?? []).filter((c) => c.enabled && c.certExpiresAt && Math.floor((Date.parse(c.certExpiresAt) - Date.now()) / 86_400_000) <= c.warnDays).length;
|
||||
|
||||
// What is coming up: the nearest dated things (not "updates waiting", which has its own card), and whether any has already passed.
|
||||
// A schedule that repeats weekly is one line (its next time), not one a week.
|
||||
const seenSchedules = new Set<string>();
|
||||
const soon = (agenda?.items ?? []).filter((i) => {
|
||||
if (i.kind === "updates") return false;
|
||||
const schedule = /^schedule:(\d+):/.exec(i.id)?.[1];
|
||||
if (!schedule) return true;
|
||||
if (seenSchedules.has(schedule)) return false;
|
||||
seenSchedules.add(schedule);
|
||||
return true;
|
||||
});
|
||||
const soonPast = soon.filter((i) => i.daysLeft < 0).length;
|
||||
const soonWeek = soon.filter((i) => i.daysLeft >= 0 && i.daysLeft <= 7).length;
|
||||
// The jobs that report in: late, or said they failed.
|
||||
const beatsWrong = (heartbeatList ?? []).filter((h) => h.state === "late" || h.state === "failed");
|
||||
|
||||
// What has nothing set up yet. These get one list at the bottom instead of a grey "Not configured" card each.
|
||||
const notSetUp: { label: string; to: string; what: string }[] = [];
|
||||
if (dnsStats?.totalProviders === 0) notSetUp.push({ label: "DNS", to: "/dns", what: "connect a DNS provider to see zones and records" });
|
||||
if (secrets !== null && totalSecrets === 0) notSetUp.push({ label: "Secrets", to: "/secrets", what: "track when a token, certificate or password expires" });
|
||||
if (serverSummary?.total === 0) notSetUp.push({ label: "Servers", to: "/servers", what: "add a server and install its agent" });
|
||||
if (heartbeatList !== null && heartbeatList.length === 0) notSetUp.push({ label: "Heartbeats", to: "/heartbeats", what: "have a backup or cron job report in, so you hear when it doesn't run" });
|
||||
if (endpointChecks !== null && endpointChecks.length === 0) notSetUp.push({ label: "Endpoints", to: "/endpoints", what: "ask a web address, a port or a certificate whether it is fine" });
|
||||
if (domainList !== null && domains.length === 0) notSetUp.push({ label: "Domains", to: "/domains", what: "appear after a DNS zone is added and the daily check has run" });
|
||||
if (integrations !== null) {
|
||||
@@ -984,6 +1012,80 @@ export default function Dashboard({ user }: { user: CurrentUser }) {
|
||||
</>
|
||||
)}
|
||||
</WidgetCard>
|
||||
|
||||
<WidgetCard
|
||||
label="Coming up"
|
||||
badge={
|
||||
!agenda ? undefined : soonPast > 0 ? (
|
||||
<span className="badge bg-red-lt text-red">{soonPast} past their date</span>
|
||||
) : soonWeek > 0 ? (
|
||||
<span className="badge bg-yellow-lt text-yellow">{soonWeek} this week</span>
|
||||
) : (
|
||||
<span className="badge bg-green-lt text-green">Nothing soon</span>
|
||||
)
|
||||
}
|
||||
>
|
||||
{!agenda ? (
|
||||
<WidgetSkeleton />
|
||||
) : soon.length === 0 ? (
|
||||
<div className="text-secondary small">Nothing expires, ends or is planned in the next 30 days.</div>
|
||||
) : (
|
||||
<>
|
||||
{soon.slice(0, 5).map((i) => (
|
||||
<div key={i.id} className="d-flex gap-2 small mb-1">
|
||||
<span className={`flex-shrink-0 ${i.daysLeft < 0 ? "text-red" : i.daysLeft <= 7 ? "text-yellow" : "text-secondary"}`} style={{ minWidth: "5.5rem" }}>
|
||||
{i.daysLeft === 0 ? "today" : i.daysLeft === 1 ? "tomorrow" : i.daysLeft === -1 ? "yesterday" : i.daysLeft > 0 ? `in ${i.daysLeft} days` : `${-i.daysLeft} days ago`}
|
||||
</span>
|
||||
<Link to={i.link} className="text-break">
|
||||
{i.title}
|
||||
</Link>
|
||||
</div>
|
||||
))}
|
||||
{soon.length > 5 && <div className="text-secondary small">+{soon.length - 5} more</div>}
|
||||
</>
|
||||
)}
|
||||
<div className="text-secondary small mt-2">
|
||||
<Link to="/coming-up">Everything coming up</Link>
|
||||
</div>
|
||||
</WidgetCard>
|
||||
|
||||
<WidgetCard
|
||||
label="Heartbeats"
|
||||
hide={heartbeatList !== null && heartbeatList.length === 0}
|
||||
badge={
|
||||
!heartbeatList ? undefined : beatsWrong.length > 0 ? (
|
||||
<span className="badge bg-red-lt text-red">{beatsWrong.length} not reporting</span>
|
||||
) : (
|
||||
<span className="badge bg-green-lt text-green">All reporting</span>
|
||||
)
|
||||
}
|
||||
>
|
||||
{!heartbeatList ? (
|
||||
<WidgetSkeleton />
|
||||
) : (
|
||||
<>
|
||||
<div className="row g-2 mb-3">
|
||||
<div className="col-4">
|
||||
<MiniStat label="Jobs" value={heartbeatList.filter((h) => h.enabled).length} />
|
||||
</div>
|
||||
<div className="col-4">
|
||||
<MiniStat label="On time" value={heartbeatList.filter((h) => h.state === "up" || h.state === "running").length} />
|
||||
</div>
|
||||
<div className="col-4">
|
||||
<MiniStat label="Late or failed" value={beatsWrong.length} accent={beatsWrong.length > 0 ? "#ef4444" : undefined} />
|
||||
</div>
|
||||
</div>
|
||||
{beatsWrong.slice(0, 3).map((h) => (
|
||||
<div key={h.id} className="text-red small">
|
||||
{h.name} — {h.state === "failed" ? `said it failed${h.lastMessage ? `: ${h.lastMessage}` : ""}` : "hasn't reported in time"}
|
||||
</div>
|
||||
))}
|
||||
<div className="text-secondary small mt-2">
|
||||
<Link to="/heartbeats">All heartbeats</Link>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</WidgetCard>
|
||||
</div>
|
||||
|
||||
<SectionHeader
|
||||
|
||||
@@ -15,6 +15,7 @@ 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";
|
||||
|
||||
const KIND_LABELS: Record<EndpointKind, string> = { http: "Web address", tcp: "Port", tls: "Certificate" };
|
||||
const KIND_HINTS: Record<EndpointKind, string> = {
|
||||
@@ -237,6 +238,8 @@ export default function Endpoints({ user }: { user: CurrentUser }) {
|
||||
))}
|
||||
</div>
|
||||
|
||||
{isAdmin && !draft && <EndpointSuggestions onAdded={load} />}
|
||||
|
||||
{draft && (
|
||||
<form className="card mb-3" onSubmit={save}>
|
||||
<div className="card-header">
|
||||
|
||||
@@ -0,0 +1,424 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { api, type CurrentUser, type Heartbeat, type HeartbeatInput, type HeartbeatState } from "../api/client";
|
||||
import CopyButton from "../components/CopyButton";
|
||||
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 { EmptyRow } from "../components/EmptyState";
|
||||
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 { formatDateTime } from "../utils/date";
|
||||
import { readableError } from "../utils/errors";
|
||||
import { toast } from "../utils/toast";
|
||||
|
||||
const STATE_BADGE: Record<HeartbeatState, { label: string; badge: string }> = {
|
||||
waiting: { label: "Waiting for the first call", badge: "bg-secondary-lt text-secondary" },
|
||||
up: { label: "On time", badge: "bg-green-lt text-green" },
|
||||
running: { label: "Running", badge: "bg-blue-lt text-blue" },
|
||||
late: { label: "Late", badge: "bg-yellow-lt text-yellow" },
|
||||
failed: { label: "Said it failed", badge: "bg-red-lt text-red" },
|
||||
off: { label: "Switched off", badge: "bg-secondary-lt text-secondary" },
|
||||
};
|
||||
const RANK: Record<HeartbeatState, number> = { failed: 0, late: 1, waiting: 2, running: 3, up: 4, off: 5 };
|
||||
|
||||
type Unit = "minutes" | "hours" | "days";
|
||||
const UNIT_MINUTES: Record<Unit, number> = { minutes: 1, hours: 60, days: 1440 };
|
||||
|
||||
/** "every 24 hours", "every day", "every 90 minutes". */
|
||||
function every(minutes: number): string {
|
||||
if (minutes % 1440 === 0) return minutes === 1440 ? "every day" : `every ${minutes / 1440} days`;
|
||||
if (minutes % 60 === 0) return minutes === 60 ? "every hour" : `every ${minutes / 60} hours`;
|
||||
return minutes === 1 ? "every minute" : `every ${minutes} minutes`;
|
||||
}
|
||||
|
||||
/** The biggest unit that divides a period evenly, so 1440 is edited as "1 day". */
|
||||
function splitPeriod(minutes: number): { value: string; unit: Unit } {
|
||||
if (minutes % 1440 === 0) return { value: String(minutes / 1440), unit: "days" };
|
||||
if (minutes % 60 === 0) return { value: String(minutes / 60), unit: "hours" };
|
||||
return { value: String(minutes), unit: "minutes" };
|
||||
}
|
||||
|
||||
function duration(ms: number | null): string | null {
|
||||
if (ms === null) return null;
|
||||
if (ms < 1000) return `${ms} ms`;
|
||||
const s = Math.round(ms / 1000);
|
||||
return s < 120 ? `${s} s` : s < 7200 ? `${Math.round(s / 60)} min` : `${(s / 3600).toFixed(1)} h`;
|
||||
}
|
||||
|
||||
interface Row extends Heartbeat {
|
||||
rank: number;
|
||||
}
|
||||
|
||||
/** The last runs as a row of small ticks: green for a success, red for a failure. */
|
||||
function Ticks({ recent }: { recent: Heartbeat["recent"] }) {
|
||||
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} runs: ${recent.filter((r) => r.kind === "ok").length} reported success`}>
|
||||
{recent.map((r) => (
|
||||
<span key={r.at} title={`${r.at.slice(0, 16).replace("T", " ")} UTC — ${r.kind === "ok" ? "reported success" : "reported a failure"}${r.durationMs !== null ? `, took ${duration(r.durationMs)}` : ""}`} style={{ width: 4, height: 14, borderRadius: 1, background: r.kind === "ok" ? "#2fb344" : "#e05252", display: "inline-block" }} />
|
||||
))}
|
||||
</span>
|
||||
);
|
||||
}
|
||||
|
||||
interface Draft {
|
||||
id: number | null;
|
||||
name: string;
|
||||
every: string;
|
||||
unit: Unit;
|
||||
grace: string;
|
||||
serverId: string;
|
||||
notes: string;
|
||||
enabled: boolean;
|
||||
}
|
||||
const EMPTY: Draft = { id: null, name: "", every: "1", unit: "days", grace: "30", serverId: "", notes: "", enabled: true };
|
||||
|
||||
const toDraft = (h: Heartbeat): Draft => ({ id: h.id, ...(({ value, unit }) => ({ every: value, unit }))(splitPeriod(h.periodMinutes)), name: h.name, grace: String(h.graceMinutes), serverId: h.serverId === null ? "" : String(h.serverId), notes: h.notes ?? "", enabled: h.enabled });
|
||||
const toInput = (d: Draft): HeartbeatInput => ({ name: d.name.trim(), periodMinutes: Math.round(Number(d.every) * UNIT_MINUTES[d.unit]), graceMinutes: Number(d.grace), serverId: d.serverId === "" ? null : Number(d.serverId), notes: d.notes.trim() || null, enabled: d.enabled });
|
||||
|
||||
/** What to put in the job: the address, and the three ways to call it. */
|
||||
function HowToCall({ url, onClose, name }: { url: string; onClose: () => void; name: string }) {
|
||||
const cron = `0 3 * * * /usr/local/bin/backup.sh && curl -fsS -m 10 --retry 3 -o /dev/null ${url}`;
|
||||
const script = `curl -fsS -m 10 -o /dev/null ${url}/start # it began (optional: gives the run time)
|
||||
./backup.sh && curl -fsS -m 10 -o /dev/null ${url} \\
|
||||
|| curl -fsS -m 10 -o /dev/null --data-raw "exit code $?" ${url}/fail`;
|
||||
return (
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Address for {name}</h3>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
<p className="text-secondary">
|
||||
Have the job call this address when it finishes. Anyone with it can say “I’m alive” for the job — and nothing else — so keep it between the job and you. If it gets out, give the heartbeat a new address.
|
||||
</p>
|
||||
<div className="input-group mb-3">
|
||||
<input className="form-control" readOnly value={url} aria-label="The address to call" onFocus={(e) => e.currentTarget.select()} />
|
||||
<CopyButton text={url} />
|
||||
</div>
|
||||
<div className="mb-1 fw-bold">In cron, after the job:</div>
|
||||
<div className="input-group mb-3">
|
||||
<pre className="form-control mb-0 small text-break" style={{ whiteSpace: "pre-wrap" }}>{cron}</pre>
|
||||
<CopyButton text={cron} />
|
||||
</div>
|
||||
<div className="mb-1 fw-bold">In a script, with a start and a failure:</div>
|
||||
<div className="input-group mb-2">
|
||||
<pre className="form-control mb-0 small text-break" style={{ whiteSpace: "pre-wrap" }}>{script}</pre>
|
||||
<CopyButton text={script} />
|
||||
</div>
|
||||
<div className="text-secondary small">
|
||||
Anything sent with the call (<code>--data-raw "3.2 GB copied"</code>, or <code>?msg=…</code>) is kept as a note, up to 200 characters. <code>/fail</code> raises an alert at once;
|
||||
<code> /start</code> lets the next call say how long the run took.
|
||||
</div>
|
||||
</div>
|
||||
<div className="card-footer">
|
||||
<button className="btn" onClick={onClose}>
|
||||
Done
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* "Did my 3 a.m. job actually run?" A cron job or backup script calls an address when it finishes; the app writes down that it did and speaks up — an alert and a
|
||||
* notification — when the call doesn't come in time, or when the job says it failed. Everyone can see how the jobs are doing; an administrator sets them up and
|
||||
* holds the addresses.
|
||||
*/
|
||||
export default function Heartbeats({ user }: { user: CurrentUser }) {
|
||||
const isAdmin = user.role === "admin";
|
||||
const [items, setItems] = useState<Heartbeat[] | null>(null);
|
||||
const [servers, setServers] = useState<{ id: number; name: string }[]>([]);
|
||||
const [baseUrl, setBaseUrl] = useState<string | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [draft, setDraft] = useState<Draft | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [showing, setShowing] = useState<{ name: string; path: string } | null>(null);
|
||||
|
||||
function load() {
|
||||
api.heartbeats
|
||||
.list()
|
||||
.then((res) => {
|
||||
setItems(res.heartbeats);
|
||||
setServers(res.servers);
|
||||
setBaseUrl(res.baseUrl);
|
||||
})
|
||||
.catch((err) => setError(readableError(err)));
|
||||
}
|
||||
useEffect(() => {
|
||||
load();
|
||||
// Calls come in on their own: look again now and then.
|
||||
const t = setInterval(load, 60_000);
|
||||
return () => clearInterval(t);
|
||||
}, []);
|
||||
|
||||
const urlOf = (path: string) => `${baseUrl ?? window.location.origin}${path}`;
|
||||
const rows: Row[] = (items ?? []).map((h) => ({ ...h, rank: RANK[h.state] }));
|
||||
const tableSearch = useTableSearch(rows);
|
||||
const { sorted, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered, "rank", "asc", { url: true });
|
||||
const page = usePagination(sorted);
|
||||
const wrong = rows.filter((r) => r.state === "late" || r.state === "failed").length;
|
||||
const waiting = rows.filter((r) => r.state === "waiting").length;
|
||||
|
||||
async function save(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
if (!draft) return;
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
const input = toInput(draft);
|
||||
if (draft.id === null) {
|
||||
const { heartbeat } = await api.heartbeats.create(input);
|
||||
toast.success(`Added ${heartbeat.name}.`);
|
||||
// A new one is useless until the job calls it: go straight to showing how.
|
||||
if (heartbeat.path) setShowing({ name: heartbeat.name, path: heartbeat.path });
|
||||
} else {
|
||||
await api.heartbeats.update(draft.id, input);
|
||||
toast.success("Saved.");
|
||||
}
|
||||
setDraft(null);
|
||||
load();
|
||||
} catch (err) {
|
||||
setError(readableError(err));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function remove(h: Heartbeat) {
|
||||
if (!(await confirmDialog({ title: "Remove a heartbeat", message: `Remove "${h.name}" and its history? The job's calls to its address will get "not found".`, confirmLabel: "Remove", danger: true }))) return;
|
||||
try {
|
||||
await api.heartbeats.remove(h.id);
|
||||
load();
|
||||
} catch (err) {
|
||||
setError(readableError(err));
|
||||
}
|
||||
}
|
||||
|
||||
async function newAddress(h: Heartbeat) {
|
||||
if (!(await confirmDialog({ title: "Give it a new address", message: `The old address for "${h.name}" stops working at once, and the job has to be changed to call the new one. Do this if the old one got out.`, confirmLabel: "Make a new address", danger: true }))) return;
|
||||
try {
|
||||
const { path } = await api.heartbeats.newAddress(h.id);
|
||||
setShowing({ name: h.name, path });
|
||||
load();
|
||||
} catch (err) {
|
||||
setError(readableError(err));
|
||||
}
|
||||
}
|
||||
|
||||
function exportCsv() {
|
||||
downloadCsv(
|
||||
"heartbeats.csv",
|
||||
["Name", "Expected", "Grace (min)", "Status", "Last call", "Last result", "Note", "Run time (ms)", "Due by", "Calls", "Server"],
|
||||
(sorted ?? []).map((r) => [r.name, every(r.periodMinutes), r.graceMinutes, STATE_BADGE[r.state].label, r.lastPingAt ?? "", r.lastStatus ?? "", r.lastMessage ?? "", r.lastDurationMs ?? "", r.dueBy, r.pingCount, r.server?.name ?? ""]),
|
||||
);
|
||||
}
|
||||
|
||||
const set = <K extends keyof Draft>(key: K, value: Draft[K]) => setDraft((d) => (d ? { ...d, [key]: value } : d));
|
||||
const cards = [
|
||||
{ label: "Heartbeats", value: items ? String(rows.length) : "…", color: "" },
|
||||
{ label: "Late or failed", value: items ? String(wrong) : "…", color: wrong > 0 ? "text-red" : "text-green" },
|
||||
{ label: "Waiting for a first call", value: items ? String(waiting) : "…", color: waiting > 0 ? "text-yellow" : "" },
|
||||
];
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="d-flex align-items-center mb-1">
|
||||
<h2 className="page-title mb-0">Heartbeats</h2>
|
||||
{isAdmin && !draft && (
|
||||
<button className="btn btn-primary ms-auto" onClick={() => setDraft({ ...EMPTY })}>
|
||||
Add a heartbeat
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
<p className="text-secondary">
|
||||
For jobs that should run on their own — a backup, a sync, a cleanup. The job calls an address when it finishes; if the call doesn’t come in time, or the job says it failed, it appears on the{" "}
|
||||
<Link to="/alerts">Alerts</Link> page and in notifications.
|
||||
</p>
|
||||
<ErrorNotice error={error} />
|
||||
|
||||
{showing && <HowToCall name={showing.name} url={urlOf(showing.path)} onClose={() => setShowing(null)} />}
|
||||
|
||||
<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>
|
||||
|
||||
{draft && (
|
||||
<form className="card mb-3" onSubmit={save}>
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">{draft.id === null ? "Add a heartbeat" : `Edit ${draft.name || "the heartbeat"}`}</h3>
|
||||
</div>
|
||||
<div className="card-body row g-3">
|
||||
<div className="col-md-4">
|
||||
<label className="form-label" htmlFor="hb-name">
|
||||
Name
|
||||
</label>
|
||||
<input id="hb-name" className="form-control" required maxLength={100} placeholder="e.g. Nightly backup of the NAS" value={draft.name} onChange={(e) => set("name", e.target.value)} />
|
||||
</div>
|
||||
<div className="col-md-4">
|
||||
<label className="form-label" htmlFor="hb-every">
|
||||
It should report every
|
||||
</label>
|
||||
<div className="input-group">
|
||||
<input id="hb-every" type="number" min={1} step="any" className="form-control" required value={draft.every} onChange={(e) => set("every", e.target.value)} />
|
||||
<select className="form-select" aria-label="Unit" value={draft.unit} onChange={(e) => set("unit", e.target.value as Unit)} style={{ maxWidth: "7rem" }}>
|
||||
<option value="minutes">minutes</option>
|
||||
<option value="hours">hours</option>
|
||||
<option value="days">days</option>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-md-4">
|
||||
<label className="form-label" htmlFor="hb-grace">
|
||||
and may be late by
|
||||
</label>
|
||||
<div className="input-group">
|
||||
<input id="hb-grace" type="number" min={0} max={1440} className="form-control" value={draft.grace} onChange={(e) => set("grace", e.target.value)} />
|
||||
<span className="input-group-text">min</span>
|
||||
</div>
|
||||
<div className="form-hint text-secondary small mt-1">An alert comes once this much time has passed after it was due.</div>
|
||||
</div>
|
||||
<div className="col-md-4">
|
||||
<label className="form-label" htmlFor="hb-server">
|
||||
It runs on the server
|
||||
</label>
|
||||
<select id="hb-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 heartbeat’s alerts, and its tags can route them.</div>
|
||||
</div>
|
||||
<div className="col-md-5">
|
||||
<label className="form-label" htmlFor="hb-notes">
|
||||
Notes <span className="text-secondary">(optional)</span>
|
||||
</label>
|
||||
<input id="hb-notes" className="form-control" maxLength={500} placeholder="Where the job lives, who to ask" value={draft.notes} onChange={(e) => set("notes", e.target.value)} />
|
||||
</div>
|
||||
<div className="col-md-3 d-flex align-items-end">
|
||||
<label className="form-check mb-2">
|
||||
<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>
|
||||
<div className="card-footer d-flex gap-2">
|
||||
<button type="submit" className="btn btn-primary" disabled={busy || draft.name.trim() === "" || !(Number(draft.every) > 0)}>
|
||||
{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 heartbeats…" 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="Job" sortKeyName="name" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<SortableTh<Row> label="Status" sortKeyName="rank" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<SortableTh<Row> label="Last call" sortKeyName="lastPingAt" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<SortableTh<Row> label="Due by" sortKeyName="dueBy" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
|
||||
<th>Recent runs</th>
|
||||
{isAdmin && <th className="w-1">Actions</th>}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{items === null && !error && (
|
||||
<tr>
|
||||
<td colSpan={6}>
|
||||
<BlockSkeleton lines={3} />
|
||||
</td>
|
||||
</tr>
|
||||
)}
|
||||
{page.pageItems?.map((h) => (
|
||||
<tr key={h.id}>
|
||||
<td className="stack-wide">
|
||||
<strong>{h.name}</strong> <span className="badge bg-secondary-lt text-secondary">{every(h.periodMinutes)}</span>
|
||||
{h.notes && <div className="text-secondary small text-break">{h.notes}</div>}
|
||||
{h.server && (
|
||||
<div className="small">
|
||||
runs on <Link to={`/servers/${h.server.id}`}>{h.server.name}</Link>
|
||||
</div>
|
||||
)}
|
||||
</td>
|
||||
<td>
|
||||
<span className={`badge ${STATE_BADGE[h.state].badge}`}>{STATE_BADGE[h.state].label}</span>
|
||||
{h.state === "failed" && h.lastMessage && <div className="text-secondary small text-break">{h.lastMessage}</div>}
|
||||
</td>
|
||||
<td className="stack-label" data-label="Last call">
|
||||
{h.lastPingAt ? (
|
||||
<>
|
||||
<TimeAgo value={h.lastPingAt} />
|
||||
{duration(h.lastDurationMs) && <div className="text-secondary small">took {duration(h.lastDurationMs)}</div>}
|
||||
{h.state !== "failed" && h.lastMessage && <div className="text-secondary small text-break">{h.lastMessage}</div>}
|
||||
</>
|
||||
) : (
|
||||
<span className="text-secondary">never</span>
|
||||
)}
|
||||
</td>
|
||||
<td className="stack-label" data-label="Due by">
|
||||
{h.enabled ? (
|
||||
<span className={h.state === "late" ? "text-yellow" : "text-secondary"}>{formatDateTime(new Date(h.dueBy))}</span>
|
||||
) : (
|
||||
<span className="text-secondary">—</span>
|
||||
)}
|
||||
</td>
|
||||
<td className="stack-label" data-label="Recent runs">
|
||||
<Ticks recent={h.recent} />
|
||||
</td>
|
||||
{isAdmin && (
|
||||
<td className="stack-wide">
|
||||
<div className="btn-list flex-nowrap">
|
||||
{h.path && (
|
||||
<button className="btn btn-sm btn-outline-primary" onClick={() => setShowing({ name: h.name, path: h.path! })}>
|
||||
Address
|
||||
</button>
|
||||
)}
|
||||
<button className="btn btn-sm btn-outline-secondary" onClick={() => setDraft(toDraft(h))}>
|
||||
Edit
|
||||
</button>
|
||||
<button className="btn btn-sm btn-outline-secondary" onClick={() => void newAddress(h)}>
|
||||
New address
|
||||
</button>
|
||||
<button className="btn btn-sm btn-outline-danger" onClick={() => void remove(h)}>
|
||||
Remove
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
)}
|
||||
</tr>
|
||||
))}
|
||||
{items !== null && sorted?.length === 0 && (
|
||||
<EmptyRow colSpan={6} {...(tableSearch.active ? { filtered: () => tableSearch.setQuery("") } : { title: "No job is reporting in yet", hint: "Add a heartbeat for a backup, a sync or any job that should run on its own; it calls an address when it finishes, and you hear about it when it doesn't.", action: isAdmin ? { label: "Add a heartbeat", onClick: () => setDraft({ ...EMPTY }) } : undefined })} />
|
||||
)}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<Pagination page={page.page} pageCount={page.pageCount} totalCount={page.totalCount} onPageChange={page.setPage} />
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -11,7 +11,8 @@ import { confirmDialog } from "../utils/dialogs";
|
||||
import { formatDateTime } from "../utils/date";
|
||||
import { readableError } from "../utils/errors";
|
||||
import { toast } from "../utils/toast";
|
||||
import { CATEGORY_NAMES, durationWords, SEVERITY_BADGE } from "./Incidents";
|
||||
import { CATEGORY_NAMES, durationWords, incidentPath, SEVERITY_BADGE } from "../components/IncidentHistory";
|
||||
import { useBreadcrumbTail } from "../utils/breadcrumb";
|
||||
|
||||
const KIND_ICON: Record<TimelineKind, JSX.Element> = {
|
||||
alert: <IconAlertTriangle size={16} />,
|
||||
@@ -35,6 +36,8 @@ export default function IncidentDetail({ user }: { user: CurrentUser }) {
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [missing, setMissing] = useState(false);
|
||||
const [note, setNote] = useState("");
|
||||
// Under Alerts in the breadcrumb: "Operations › Alerts › Incident".
|
||||
useBreadcrumbTail("Incident");
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
const load = useCallback(() => {
|
||||
@@ -93,7 +96,7 @@ export default function IncidentDetail({ user }: { user: CurrentUser }) {
|
||||
return (
|
||||
<div className="card">
|
||||
<div className="card-body text-secondary">
|
||||
There is no incident like that (it may be old enough to have been removed). <Link to="/incidents">All incidents</Link>.
|
||||
There is no incident like that (it may be old enough to have been removed). <Link to="/alerts?view=history">All incidents</Link>.
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
@@ -113,8 +116,8 @@ export default function IncidentDetail({ user }: { user: CurrentUser }) {
|
||||
return (
|
||||
<>
|
||||
<div className="mb-2">
|
||||
<Link to="/incidents" className="text-secondary">
|
||||
← Incidents
|
||||
<Link to="/alerts?view=history" className="text-secondary">
|
||||
← Alerts · History
|
||||
</Link>
|
||||
</div>
|
||||
<div className="d-flex flex-wrap align-items-center gap-2 mb-1">
|
||||
@@ -203,7 +206,7 @@ export default function IncidentDetail({ user }: { user: CurrentUser }) {
|
||||
</span>
|
||||
<div className="flex-fill">
|
||||
<div className="d-flex flex-wrap gap-2 align-items-baseline">
|
||||
<strong>{e.incidentId ? <Link to={`/incidents/${e.incidentId}`}>{e.title}</Link> : e.title}</strong>
|
||||
<strong>{e.incidentId ? <Link to={incidentPath(e.incidentId)}>{e.title}</Link> : e.title}</strong>
|
||||
<span className="text-secondary small" title={formatDateTime(new Date(e.at))}>
|
||||
{formatDateTime(new Date(e.at))}
|
||||
</span>
|
||||
|
||||
@@ -242,7 +242,7 @@ export default function NameSettings() {
|
||||
</div>
|
||||
<div className="card-body">
|
||||
<div className="text-secondary small mb-3">
|
||||
Operations → Generator picks server names from these lists. A name is letters, digits and hyphens (å, ä and ö become a, a and o), so
|
||||
Administration → Generator picks server names from these lists. A name is letters, digits and hyphens (å, ä and ö become a, a and o), so
|
||||
it works as a hostname. Changes apply when you save.
|
||||
</div>
|
||||
{drafts.length === 0 ? (
|
||||
|
||||
@@ -82,7 +82,7 @@ export default function ShareSettings() {
|
||||
<>
|
||||
<h3 className="mb-3">Share links</h3>
|
||||
<p className="text-secondary">
|
||||
A share link opens a page <strong>without signing in</strong>: the <strong>wall display</strong> — how things are, on one screen, for a TV in the hall — or a <strong>status page</strong> — whether each of the things you choose is working, with names people at home will recognise, for family or housemates who only want to know "is the movie server up?". It can only look; it can't change anything.
|
||||
A share link opens a page <strong>without signing in</strong>: the <strong>wall display</strong> — how things are, on one screen, for a TV in the hall — or a <strong>status page</strong> — whether each of the things you choose is working, with names people at home will recognise, for family or housemates who only want to know "is the movie server up?" — or a <strong>calendar feed</strong> — what is coming up (expiries, planned maintenance …), for a phone's calendar to subscribe to. It can only look; it can't change anything.
|
||||
</p>
|
||||
<div className="alert alert-warning">
|
||||
Anyone who has the address can open it, so treat it like a password: give it only to people and screens you trust, and remove it when it isn't needed. The address is shown once, when you make it.
|
||||
@@ -128,16 +128,26 @@ export default function ShareSettings() {
|
||||
<select id="share-kind" className="form-select" value={kind} onChange={(e) => setKind(e.target.value as ShareLinkKind)}>
|
||||
<option value="wall">The wall display — how things are</option>
|
||||
<option value="status">A status page — is each thing I choose working</option>
|
||||
<option value="calendar">A calendar feed — what is coming up, for a phone's calendar</option>
|
||||
</select>
|
||||
</div>
|
||||
{kind === "wall" && (
|
||||
{(kind === "wall" || kind === "calendar") && (
|
||||
<div className="col-md-4">
|
||||
<label className="form-label" htmlFor="share-detail">
|
||||
How much it shows
|
||||
</label>
|
||||
<select id="share-detail" className="form-select" value={detail} onChange={(e) => setDetail(e.target.value as ShareLinkDetail)}>
|
||||
<option value="summary">Numbers only — servers online, alerts, maintenance</option>
|
||||
<option value="names">With names — also what is wrong, and the integrations</option>
|
||||
{kind === "wall" ? (
|
||||
<>
|
||||
<option value="summary">Numbers only — servers online, alerts, maintenance</option>
|
||||
<option value="names">With names — also what is wrong, and the integrations</option>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<option value="summary">Kinds only — "A secret expires", no names</option>
|
||||
<option value="names">With names — which secret, domain, server …</option>
|
||||
</>
|
||||
)}
|
||||
</select>
|
||||
</div>
|
||||
)}
|
||||
@@ -170,7 +180,9 @@ export default function ShareSettings() {
|
||||
</select>
|
||||
</div>
|
||||
<div className="col-12 text-secondary small">
|
||||
{kind === "wall"
|
||||
{kind === "calendar"
|
||||
? "Each secret, domain, certificate, Tailscale key, warranty, end of support, planned or recurring maintenance and restore test that is due becomes an event, refreshed by the calendar app every few hours. “Kinds only” leaves the names out, so the feed can go on a shared calendar without saying what is in the homelab; “with names” also gives the name and a link back to this app. Paste the address into your calendar app under “add a calendar from a URL” (Google Calendar, Apple Calendar, Outlook and Thunderbird all do)."
|
||||
: kind === "wall"
|
||||
? "“Numbers only” never shows a name. “With names” shows the text of the alerts (which can mention server names, disks and secrets), what is in maintenance, and the names of your integrations — never addresses, tokens or settings."
|
||||
: "A status page shows only the name you give each thing and whether it is working, being worked on, or can't be told — and, where known, how it has done over 30 days. Never an address, an alert, or what the thing really is. You choose what is on it right after making it."}
|
||||
</div>
|
||||
@@ -208,7 +220,7 @@ export default function ShareSettings() {
|
||||
<td>
|
||||
{l.label} <span className="text-secondary small">{l.tokenPrefix}…</span>
|
||||
</td>
|
||||
<td>{l.kind === "status" ? "Status page · " + l.itemCount + (l.itemCount === 1 ? " thing" : " things") : "Wall · " + DETAIL_WORDS[l.detail].toLowerCase()}</td>
|
||||
<td>{l.kind === "status" ? "Status page · " + l.itemCount + (l.itemCount === 1 ? " thing" : " things") : l.kind === "calendar" ? "Calendar · " + (l.detail === "names" ? "with names" : "kinds only") : "Wall · " + DETAIL_WORDS[l.detail].toLowerCase()}</td>
|
||||
<td className="text-secondary">
|
||||
{l.createdBy ?? "—"}, <TimeAgo value={l.createdAt} fromDb />
|
||||
</td>
|
||||
@@ -229,7 +241,7 @@ export default function ShareSettings() {
|
||||
</tr>
|
||||
))}
|
||||
{links?.length === 0 && (
|
||||
<EmptyRow colSpan={6} title="No share links yet" hint="A link lets a wall display or a status page be seen without signing in. Make one with the form above." />
|
||||
<EmptyRow colSpan={6} title="No share links yet" hint="A link lets a wall display, a status page or a calendar feed be used without signing in. Make one with the form above." />
|
||||
)}
|
||||
{links === null && !error && (
|
||||
<tr>
|
||||
|
||||
Reference in new issue
Block a user