Patch plans, a monthly report and new-port alerts
Patch plans (Updates -> Patch plans): updates on a schedule, one server at a time, each by an ordinary update run, stopping at the first failure by default, silencing what depends on a server while it is updated, with one message at the end. Monthly report (Operations -> Monthly report, and optionally a message on a day of the month): availability, incidents, updates, restore tests, backups and renewals for a calendar month, printable. Backed by daily endpoint figures and a record of renewals. New ports: the first report with ports is the baseline; a TCP port that begins listening later and is not noted on the server's Ports card is a warning, cleared by Mark as expected. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ddd0aa622a
commit
be6c5552bd
46 files changed
+7836
-26
No files matched your search
@@ -33,6 +33,7 @@ import InventoryLifecycle from "./pages/InventoryLifecycle";
|
||||
import Endpoints from "./pages/Endpoints";
|
||||
import Heartbeats from "./pages/Heartbeats";
|
||||
import ComingUp from "./pages/ComingUp";
|
||||
import MonthlyReport from "./pages/MonthlyReport";
|
||||
import ChangeLog from "./pages/ChangeLog";
|
||||
import Backups from "./pages/Backups";
|
||||
import Consistency from "./pages/Consistency";
|
||||
@@ -158,6 +159,7 @@ function Shelled({ user }: { user: CurrentUser }) {
|
||||
<Route path="/endpoints" element={<Endpoints user={user} />} />
|
||||
<Route path="/heartbeats" element={<Heartbeats user={user} />} />
|
||||
<Route path="/coming-up" element={<ComingUp user={user} />} />
|
||||
<Route path="/reports" element={<MonthlyReport 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} />} />
|
||||
|
||||
@@ -508,6 +508,17 @@ export interface HealthCheckSettings {
|
||||
backupStaleHours: number;
|
||||
/** A restore test older than this many days is a problem; 0 = off (a failed test always is). */
|
||||
restoreTestDays: number;
|
||||
/** A server that starts listening on a TCP port it did not at first, and that is not noted on its Ports card, is a warning. */
|
||||
newPortAlerts: boolean;
|
||||
}
|
||||
|
||||
/** The monthly report: last month's availability, incidents, updates and renewals, in one message on a day of the month. */
|
||||
export interface MonthlyReportSettings {
|
||||
enabled: boolean;
|
||||
/** Day of the month, 1–28, in the notification time zone. */
|
||||
day: number;
|
||||
/** "HH:MM", in the notification time zone. */
|
||||
time: string;
|
||||
}
|
||||
|
||||
export interface QuietHoursSettings {
|
||||
@@ -543,6 +554,7 @@ export interface AppSettings {
|
||||
digest: DigestSettings;
|
||||
signIn: SignInSettings;
|
||||
profilePictures: ProfilePictureSettings;
|
||||
monthlyReport: MonthlyReportSettings;
|
||||
}
|
||||
|
||||
export type AppSettingsPatch = { [K in keyof AppSettings]?: Partial<AppSettings[K]> };
|
||||
@@ -905,6 +917,94 @@ export interface EndpointInput {
|
||||
enabled?: boolean;
|
||||
}
|
||||
|
||||
export type PatchPlanItemStatus = "pending" | "running" | "done" | "failed" | "skipped";
|
||||
export interface PatchPlanItem {
|
||||
serverId: number;
|
||||
name: string;
|
||||
status: PatchPlanItemStatus;
|
||||
updateRunId: number | null;
|
||||
message: string | null;
|
||||
}
|
||||
export interface PatchPlanRun {
|
||||
id: number;
|
||||
planId: number;
|
||||
planName: string;
|
||||
trigger: "schedule" | "manual";
|
||||
startedBy: string | null;
|
||||
status: "running" | "done" | "failed" | "cancelled";
|
||||
message: string | null;
|
||||
startedAt: string;
|
||||
finishedAt: string | null;
|
||||
items: PatchPlanItem[];
|
||||
}
|
||||
/** Updates on a schedule, one server at a time. */
|
||||
export interface PatchPlan {
|
||||
id: number;
|
||||
name: string;
|
||||
enabled: boolean;
|
||||
/** 0 = Sunday … 6 = Saturday. */
|
||||
days: number[];
|
||||
startTime: string;
|
||||
timezone: string;
|
||||
tags: string[];
|
||||
serverIds: number[];
|
||||
integrationId: number;
|
||||
projectId: number;
|
||||
templateId: number;
|
||||
templateName: string;
|
||||
limitFrom: "name" | "hostname";
|
||||
stopOnFailure: boolean;
|
||||
onlyWithUpdates: boolean;
|
||||
silenceDependents: boolean;
|
||||
windowMinutes: number;
|
||||
createdBy: string | null;
|
||||
/** The servers it covers right now. */
|
||||
servers: { id: number; name: string }[];
|
||||
/** ISO — its next times. */
|
||||
next: string[];
|
||||
running: boolean;
|
||||
}
|
||||
export type PatchPlanInput = Omit<PatchPlan, "id" | "createdBy" | "servers" | "next" | "running">;
|
||||
|
||||
export interface AvailabilityRow {
|
||||
id: number;
|
||||
name: string;
|
||||
percent: number | null;
|
||||
downMinutes: number;
|
||||
}
|
||||
export interface MonthlyReport {
|
||||
month: string;
|
||||
label: string;
|
||||
from: string;
|
||||
to: string;
|
||||
partial: boolean;
|
||||
timezone: string;
|
||||
servers: AvailabilityRow[];
|
||||
integrations: AvailabilityRow[];
|
||||
endpoints: { id: number; name: string; percent: number | null; avgMs: number | null; checks: number }[];
|
||||
incidents: {
|
||||
began: number;
|
||||
resolved: number;
|
||||
stillOpen: number;
|
||||
totalMinutes: number;
|
||||
averageMinutes: number | null;
|
||||
longest: { id: number; message: string; minutes: number } | null;
|
||||
byCategory: { category: string; count: number }[];
|
||||
list: { id: number; message: string; where: string; severity: string; openedAt: string; resolvedAt: string | null; minutes: number }[];
|
||||
};
|
||||
updates: {
|
||||
runs: number;
|
||||
done: number;
|
||||
failed: number;
|
||||
installed: number;
|
||||
byServer: { name: string; runs: number; failed: number; installed: number }[];
|
||||
planRuns: { runs: number; done: number; failed: number };
|
||||
};
|
||||
restoreTests: { label: string; testedAt: string; result: string; note: string | null }[];
|
||||
backups: { ok: number; stale: number; failed: number; none: number; unknown: number; total: number; asOf: string } | null;
|
||||
renewals: { kind: string; subject: string; at: string; fromDate: string; toDate: string }[];
|
||||
}
|
||||
|
||||
/** A check the app could set up for you, from what it already knows. */
|
||||
export interface EndpointSuggestion {
|
||||
key: string;
|
||||
@@ -1322,6 +1422,8 @@ export interface PortEntry {
|
||||
lastSeenOpenAt: string | null;
|
||||
agent: { addresses: string[]; process: string | null; localOnly: boolean } | null;
|
||||
state: "open" | "reserved";
|
||||
/** Began listening after the first report and nobody has noted it: a "new port" alert is on. */
|
||||
isNew: boolean;
|
||||
}
|
||||
|
||||
export interface PortScanSummary {
|
||||
@@ -1947,6 +2049,19 @@ export const api = {
|
||||
start: (data: UpdateRunInput) => request<{ run: UpdateRun }>("/api/update-runs", { method: "POST", body: JSON.stringify(data) }),
|
||||
cancel: (id: number) => request<{ status: string }>(`/api/update-runs/${id}/cancel`, { method: "POST" }),
|
||||
},
|
||||
patchPlans: {
|
||||
list: () => request<{ plans: PatchPlan[]; runs: PatchPlanRun[]; servers: { id: number; name: string; tags: string[] }[]; tags: string[] }>("/api/patch-plans"),
|
||||
create: (data: PatchPlanInput) => request<{ plan: PatchPlan }>("/api/patch-plans", { method: "POST", body: JSON.stringify(data) }),
|
||||
update: (id: number, data: PatchPlanInput) => request<{ plan: PatchPlan }>(`/api/patch-plans/${id}`, { method: "PUT", body: JSON.stringify(data) }),
|
||||
remove: (id: number) => request<void>(`/api/patch-plans/${id}`, { method: "DELETE" }),
|
||||
run: (id: number) => request<{ run: PatchPlanRun }>(`/api/patch-plans/${id}/run`, { method: "POST" }),
|
||||
cancel: (runId: number) => request<{ run: PatchPlanRun }>(`/api/patch-plans/runs/${runId}/cancel`, { method: "POST" }),
|
||||
},
|
||||
reports: {
|
||||
monthly: (month?: string) => request<{ report: MonthlyReport; months: { id: string; label: string }[] }>(`/api/reports/monthly${month ? `?month=${month}` : ""}`),
|
||||
monthlyText: (month?: string) => request<{ title: string; message: string }>(`/api/reports/monthly?format=text${month ? `&month=${month}` : ""}`),
|
||||
sendMonthly: (month?: string) => request<{ sent: boolean }>("/api/reports/monthly/send", { method: "POST", body: JSON.stringify({ month }) }),
|
||||
},
|
||||
backups: {
|
||||
coverage: (staleDays: number, refresh = false) => request<BackupCoverage>(`/api/backups/coverage?staleDays=${staleDays}${refresh ? "&refresh=1" : ""}`),
|
||||
restoreTests: () => request<{ limitDays: number; tests: RestoreTestEntry[]; custom: (RestoreInfo & { key: string; label: string })[] }>("/api/backups/restore-tests"),
|
||||
|
||||
@@ -0,0 +1,495 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { Link } from "react-router-dom";
|
||||
import { api, type CurrentUser, type IntegrationSummary, type PatchPlan, type PatchPlanInput, type PatchPlanItemStatus, type PatchPlanRun, type SemaphoreTemplate } from "../api/client";
|
||||
import TimeAgo from "./TimeAgo";
|
||||
import EmptyState from "./EmptyState";
|
||||
import { ErrorNotice } from "./Notice";
|
||||
import { BlockSkeleton } from "./Skeleton";
|
||||
import { confirmDialog } from "../utils/dialogs";
|
||||
import { formatDateTime } from "../utils/date";
|
||||
import { readableError } from "../utils/errors";
|
||||
import { toast } from "../utils/toast";
|
||||
|
||||
const WEEK: { day: number; label: string }[] = [
|
||||
{ day: 1, label: "Mon" },
|
||||
{ day: 2, label: "Tue" },
|
||||
{ day: 3, label: "Wed" },
|
||||
{ day: 4, label: "Thu" },
|
||||
{ day: 5, label: "Fri" },
|
||||
{ day: 6, label: "Sat" },
|
||||
{ day: 0, label: "Sun" },
|
||||
];
|
||||
const LONG_DAY = ["Sundays", "Mondays", "Tuesdays", "Wednesdays", "Thursdays", "Fridays", "Saturdays"];
|
||||
|
||||
const ITEM_BADGE: Record<PatchPlanItemStatus, { label: string; badge: string }> = {
|
||||
pending: { label: "Waiting its turn", badge: "bg-secondary-lt text-secondary" },
|
||||
running: { label: "Updating", badge: "bg-blue-lt text-blue" },
|
||||
done: { label: "Updated", badge: "bg-green-lt text-green" },
|
||||
failed: { label: "Failed", badge: "bg-red-lt text-red" },
|
||||
skipped: { label: "Left alone", badge: "bg-secondary-lt text-secondary" },
|
||||
};
|
||||
const RUN_BADGE: Record<PatchPlanRun["status"], { label: string; badge: string }> = {
|
||||
running: { label: "Running", badge: "bg-blue-lt text-blue" },
|
||||
done: { label: "Finished", badge: "bg-green-lt text-green" },
|
||||
failed: { label: "Didn't finish cleanly", badge: "bg-red-lt text-red" },
|
||||
cancelled: { label: "Stopped", badge: "bg-secondary-lt text-secondary" },
|
||||
};
|
||||
|
||||
/** "Sundays at 02:00", "Mondays to Fridays at 03:30" is too clever — the days are just listed. */
|
||||
function whenWords(days: number[], time: string): string {
|
||||
const sorted = [...days].sort((a, b) => ((a + 6) % 7) - ((b + 6) % 7));
|
||||
return `${sorted.map((d) => LONG_DAY[d]).join(", ")} at ${time}`;
|
||||
}
|
||||
|
||||
const WINDOWS = [
|
||||
{ minutes: 45, label: "45 minutes" },
|
||||
{ minutes: 90, label: "1½ hours" },
|
||||
{ minutes: 180, label: "3 hours" },
|
||||
{ minutes: 360, label: "6 hours" },
|
||||
];
|
||||
|
||||
const zones = (): string[] => {
|
||||
try {
|
||||
return (Intl as unknown as { supportedValuesOf?: (k: string) => string[] }).supportedValuesOf?.("timeZone") ?? ["UTC"];
|
||||
} catch {
|
||||
return ["UTC"];
|
||||
}
|
||||
};
|
||||
const browserZone = () => {
|
||||
try {
|
||||
return Intl.DateTimeFormat().resolvedOptions().timeZone || "UTC";
|
||||
} catch {
|
||||
return "UTC";
|
||||
}
|
||||
};
|
||||
|
||||
interface Template {
|
||||
key: string;
|
||||
integration: IntegrationSummary;
|
||||
template: SemaphoreTemplate;
|
||||
label: string;
|
||||
}
|
||||
|
||||
interface Draft {
|
||||
id: number | null;
|
||||
name: string;
|
||||
enabled: boolean;
|
||||
days: number[];
|
||||
startTime: string;
|
||||
timezone: string;
|
||||
tags: string[];
|
||||
serverIds: number[];
|
||||
template: string;
|
||||
limitFrom: "name" | "hostname";
|
||||
stopOnFailure: boolean;
|
||||
onlyWithUpdates: boolean;
|
||||
silenceDependents: boolean;
|
||||
windowMinutes: number;
|
||||
}
|
||||
|
||||
const EMPTY: Draft = { id: null, name: "", enabled: true, days: [0], startTime: "02:00", timezone: browserZone(), tags: [], serverIds: [], template: "", limitFrom: "name", stopOnFailure: true, onlyWithUpdates: true, silenceDependents: true, windowMinutes: 90 };
|
||||
|
||||
function Progress({ run, canStop, onStop }: { run: PatchPlanRun; canStop: boolean; onStop: () => void }) {
|
||||
return (
|
||||
<div className="list-group-item">
|
||||
<div className="d-flex flex-wrap align-items-center gap-2">
|
||||
<strong>{run.planName}</strong>
|
||||
<span className={`badge ${RUN_BADGE[run.status].badge}`}>{RUN_BADGE[run.status].label}</span>
|
||||
<span className="text-secondary small">
|
||||
started <TimeAgo value={run.startedAt} /> {run.trigger === "schedule" ? "by its schedule" : `by ${run.startedBy ?? "someone"}`}
|
||||
</span>
|
||||
{run.status === "running" && canStop && (
|
||||
<button className="btn btn-sm btn-outline-danger ms-auto" onClick={onStop}>
|
||||
Stop
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{run.message && <div className="text-secondary small mt-1">{run.message}</div>}
|
||||
<div className="mt-2 d-flex flex-column gap-1">
|
||||
{run.items.map((i) => (
|
||||
<div key={i.serverId} className="d-flex flex-wrap gap-2 align-items-baseline small">
|
||||
<span className={`badge ${ITEM_BADGE[i.status].badge}`} style={{ minWidth: "7rem" }}>
|
||||
{ITEM_BADGE[i.status].label}
|
||||
</span>
|
||||
<Link to={`/servers/${i.serverId}`}>{i.name}</Link>
|
||||
{i.message && <span className="text-secondary text-break">{i.message}</span>}
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Patch plans: "Sundays at 02:00, the servers tagged lab, one at a time, stop at the first failure." A plan updates each server with an ordinary update run — the
|
||||
* server is put under maintenance, the playbook runs for it alone, the app waits for it to report again — and goes on to the next only when that one is over. What
|
||||
* depends on a server is silenced while it is updated. Everyone can see the plans and how they went; an administrator makes them; an operator can run one now or stop it.
|
||||
*/
|
||||
export default function PatchPlans({ user }: { user: CurrentUser }) {
|
||||
const isAdmin = user.role === "admin";
|
||||
const canRun = isAdmin || user.role === "operator";
|
||||
const [data, setData] = useState<{ plans: PatchPlan[]; runs: PatchPlanRun[]; servers: { id: number; name: string; tags: string[] }[]; tags: string[] } | null>(null);
|
||||
const [templates, setTemplates] = useState<Template[] | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [draft, setDraft] = useState<Draft | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
function load() {
|
||||
api.patchPlans
|
||||
.list()
|
||||
.then((res) => {
|
||||
setData(res);
|
||||
setError(null);
|
||||
})
|
||||
.catch((err) => setError(readableError(err)));
|
||||
}
|
||||
const running = data?.runs.some((r) => r.status === "running") ?? false;
|
||||
useEffect(() => {
|
||||
load();
|
||||
}, []);
|
||||
// A run that is going is looked at every few seconds; otherwise now and then.
|
||||
useEffect(() => {
|
||||
const t = setInterval(load, running ? 10_000 : 60_000);
|
||||
return () => clearInterval(t);
|
||||
}, [running]);
|
||||
|
||||
// The playbooks to choose from, asked for only when somebody starts making a plan.
|
||||
useEffect(() => {
|
||||
if (!draft || templates !== null) return;
|
||||
let alive = true;
|
||||
api.integrations
|
||||
.list()
|
||||
.then(async (res) => {
|
||||
const sems = res.integrations.filter((i) => i.type === "semaphore" && i.enabled);
|
||||
const all = await Promise.all(sems.map((integration) => api.integrations.semaphore.templates(integration.id).then((r) => r.templates.map((template): Template => ({ key: `${integration.id}:${template.projectId}:${template.id}`, integration, template, label: `${template.name} — ${template.projectName}${sems.length > 1 ? ` (${integration.name})` : ""}` }))).catch((): Template[] => [])));
|
||||
if (alive) setTemplates(all.flat());
|
||||
})
|
||||
.catch(() => alive && setTemplates([]));
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, [draft, templates]);
|
||||
|
||||
const covered = useMemo(() => {
|
||||
if (!draft || !data) return [];
|
||||
return data.servers.filter((s) => draft.serverIds.includes(s.id) || s.tags.some((t) => draft.tags.includes(t)));
|
||||
}, [draft, data]);
|
||||
|
||||
function edit(p: PatchPlan) {
|
||||
setDraft({ id: p.id, name: p.name, enabled: p.enabled, days: p.days, startTime: p.startTime, timezone: p.timezone, tags: p.tags, serverIds: p.serverIds, template: `${p.integrationId}:${p.projectId}:${p.templateId}`, limitFrom: p.limitFrom, stopOnFailure: p.stopOnFailure, onlyWithUpdates: p.onlyWithUpdates, silenceDependents: p.silenceDependents, windowMinutes: p.windowMinutes });
|
||||
}
|
||||
|
||||
async function save(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
if (!draft) return;
|
||||
// Editing a plan whose playbook was not looked up still keeps what it has.
|
||||
const picked = templates?.find((t) => t.key === draft.template);
|
||||
const existing = draft.id !== null ? data?.plans.find((p) => p.id === draft.id) : undefined;
|
||||
const input: PatchPlanInput | null = picked
|
||||
? { name: draft.name.trim(), enabled: draft.enabled, days: draft.days, startTime: draft.startTime, timezone: draft.timezone, tags: draft.tags, serverIds: draft.serverIds, integrationId: picked.integration.id, projectId: picked.template.projectId, templateId: picked.template.id, templateName: picked.template.name, limitFrom: draft.limitFrom, stopOnFailure: draft.stopOnFailure, onlyWithUpdates: draft.onlyWithUpdates, silenceDependents: draft.silenceDependents, windowMinutes: draft.windowMinutes }
|
||||
: existing && draft.template === `${existing.integrationId}:${existing.projectId}:${existing.templateId}`
|
||||
? { name: draft.name.trim(), enabled: draft.enabled, days: draft.days, startTime: draft.startTime, timezone: draft.timezone, tags: draft.tags, serverIds: draft.serverIds, integrationId: existing.integrationId, projectId: existing.projectId, templateId: existing.templateId, templateName: existing.templateName, limitFrom: draft.limitFrom, stopOnFailure: draft.stopOnFailure, onlyWithUpdates: draft.onlyWithUpdates, silenceDependents: draft.silenceDependents, windowMinutes: draft.windowMinutes }
|
||||
: null;
|
||||
if (!input) {
|
||||
setError("Choose the playbook that applies updates.");
|
||||
return;
|
||||
}
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
if (draft.id === null) await api.patchPlans.create(input);
|
||||
else await api.patchPlans.update(draft.id, input);
|
||||
toast.success(draft.id === null ? `Added ${draft.name}.` : "Saved.");
|
||||
setDraft(null);
|
||||
load();
|
||||
} catch (err) {
|
||||
setError(readableError(err));
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
}
|
||||
|
||||
async function runNow(p: PatchPlan) {
|
||||
const names = p.servers.map((s) => s.name);
|
||||
if (!(await confirmDialog({ title: `Run ${p.name} now?`, message: `It updates ${names.length === 1 ? names[0] : `${names.length} servers (${names.slice(0, 5).join(", ")}${names.length > 5 ? " …" : ""})`}, one at a time${p.stopOnFailure ? ", and stops at the first failure" : ""}. ${p.onlyWithUpdates ? "Servers with nothing waiting are left alone. " : ""}Each is put under maintenance while it is updated and may restart.`, confirmLabel: "Run it now" }))) return;
|
||||
try {
|
||||
await api.patchPlans.run(p.id);
|
||||
toast.success(`Started ${p.name}.`);
|
||||
load();
|
||||
} catch (err) {
|
||||
setError(readableError(err));
|
||||
}
|
||||
}
|
||||
|
||||
async function stop(run: PatchPlanRun) {
|
||||
if (!(await confirmDialog({ title: "Stop this run?", message: "The servers not yet started are left alone. A playbook that has already started keeps running in Semaphore; the app only stops following it.", confirmLabel: "Stop", danger: true }))) return;
|
||||
try {
|
||||
await api.patchPlans.cancel(run.id);
|
||||
load();
|
||||
} catch (err) {
|
||||
setError(readableError(err));
|
||||
}
|
||||
}
|
||||
|
||||
async function remove(p: PatchPlan) {
|
||||
if (!(await confirmDialog({ title: "Remove a plan", message: `Remove "${p.name}" and its history?`, confirmLabel: "Remove", danger: true }))) return;
|
||||
try {
|
||||
await api.patchPlans.remove(p.id);
|
||||
load();
|
||||
} catch (err) {
|
||||
setError(readableError(err));
|
||||
}
|
||||
}
|
||||
|
||||
const set = <K extends keyof Draft>(key: K, value: Draft[K]) => setDraft((d) => (d ? { ...d, [key]: value } : d));
|
||||
const toggle = <T,>(list: T[], v: T) => (list.includes(v) ? list.filter((x) => x !== v) : [...list, v]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<p className="text-secondary">
|
||||
Updates on a schedule: <em>Sundays at 02:00, the servers tagged lab, one at a time, stop at the first failure.</em> Each server is updated by an ordinary update run — put under maintenance, the playbook run for it
|
||||
alone, the app waits for it to report again — and the plan goes on to the next only when that one is over. What depends on a server is silenced while it is updated. A message at the end says how each went.
|
||||
</p>
|
||||
<ErrorNotice error={error} />
|
||||
|
||||
{data && data.runs.length > 0 && (
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Recent runs</h3>
|
||||
</div>
|
||||
<div className="list-group list-group-flush">
|
||||
{data.runs.slice(0, running ? 15 : 5).map((r) => (
|
||||
<Progress key={r.id} run={r} canStop={canRun} onStop={() => void stop(r)} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{draft && data && (
|
||||
<form className="card mb-3" onSubmit={save}>
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">{draft.id === null ? "Make a patch plan" : `Edit ${draft.name || "the plan"}`}</h3>
|
||||
</div>
|
||||
<div className="card-body row g-3">
|
||||
<div className="col-md-5">
|
||||
<label className="form-label" htmlFor="pp-name">
|
||||
Name
|
||||
</label>
|
||||
<input id="pp-name" className="form-control" required maxLength={100} placeholder="e.g. Lab on Sunday nights" value={draft.name} onChange={(e) => set("name", e.target.value)} />
|
||||
</div>
|
||||
<div className="col-md-7">
|
||||
<div className="form-label">Days</div>
|
||||
<div className="d-flex flex-wrap gap-2">
|
||||
{WEEK.map((d) => (
|
||||
<label key={d.day} className={`btn btn-sm ${draft.days.includes(d.day) ? "btn-primary" : "btn-outline-secondary"} mb-0`}>
|
||||
<input type="checkbox" className="d-none" checked={draft.days.includes(d.day)} onChange={() => set("days", toggle(draft.days, d.day))} />
|
||||
{d.label}
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-md-3">
|
||||
<label className="form-label" htmlFor="pp-time">
|
||||
Starts at
|
||||
</label>
|
||||
<input id="pp-time" type="time" className="form-control" required value={draft.startTime} onChange={(e) => set("startTime", e.target.value)} />
|
||||
</div>
|
||||
<div className="col-md-5">
|
||||
<label className="form-label" htmlFor="pp-zone">
|
||||
On the clock of
|
||||
</label>
|
||||
<input id="pp-zone" className="form-control" list="pp-zones" required value={draft.timezone} onChange={(e) => set("timezone", e.target.value)} />
|
||||
<datalist id="pp-zones">
|
||||
{zones().map((z) => (
|
||||
<option key={z} value={z} />
|
||||
))}
|
||||
</datalist>
|
||||
<div className="form-hint text-secondary small mt-1">A name like Europe/Stockholm, so 02:00 stays 02:00 in summer and winter.</div>
|
||||
</div>
|
||||
<div className="col-md-4">
|
||||
<label className="form-label" htmlFor="pp-window">
|
||||
Each server may be under maintenance for
|
||||
</label>
|
||||
<select id="pp-window" className="form-select" value={draft.windowMinutes} onChange={(e) => set("windowMinutes", Number(e.target.value))}>
|
||||
{WINDOWS.map((w) => (
|
||||
<option key={w.minutes} value={w.minutes}>
|
||||
{w.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<div className="form-hint text-secondary small mt-1">It ends sooner when that server's update does.</div>
|
||||
</div>
|
||||
|
||||
<div className="col-12">
|
||||
<div className="form-label">Which servers</div>
|
||||
{data.tags.length === 0 ? (
|
||||
<div className="text-secondary small mb-2">No server has a tag yet — tag servers on their pages (for example “lab”), or name them below.</div>
|
||||
) : (
|
||||
<div className="d-flex flex-wrap gap-2 mb-2">
|
||||
{data.tags.map((t) => (
|
||||
<label key={t} className={`btn btn-sm ${draft.tags.includes(t) ? "btn-primary" : "btn-outline-secondary"} mb-0`}>
|
||||
<input type="checkbox" className="d-none" checked={draft.tags.includes(t)} onChange={() => set("tags", toggle(draft.tags, t))} />
|
||||
{t}
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
<details>
|
||||
<summary className="text-secondary small">Or name servers one by one{draft.serverIds.length > 0 ? ` (${draft.serverIds.length})` : ""}</summary>
|
||||
<div className="d-flex flex-wrap gap-3 mt-2">
|
||||
{data.servers.map((s) => (
|
||||
<label key={s.id} className="form-check mb-0">
|
||||
<input type="checkbox" className="form-check-input" checked={draft.serverIds.includes(s.id)} onChange={() => set("serverIds", toggle(draft.serverIds, s.id))} />
|
||||
<span className="form-check-label">{s.name}</span>
|
||||
</label>
|
||||
))}
|
||||
</div>
|
||||
</details>
|
||||
<div className="form-hint mt-2">{covered.length === 0 ? "No server is covered yet." : <>It would update {covered.length} server{covered.length === 1 ? "" : "s"}, by name: {covered.map((s) => s.name).join(", ")}.</>}</div>
|
||||
</div>
|
||||
|
||||
<div className="col-md-8">
|
||||
<label className="form-label" htmlFor="pp-template">
|
||||
Playbook that applies updates
|
||||
</label>
|
||||
{templates === null ? (
|
||||
<BlockSkeleton lines={1} />
|
||||
) : templates.length === 0 && draft.id === null ? (
|
||||
<div className="text-secondary">
|
||||
There is no Semaphore connected, or it has no templates. Add one under <Link to="/integrations">Integrations</Link>.
|
||||
</div>
|
||||
) : (
|
||||
<select id="pp-template" className="form-select" value={draft.template} onChange={(e) => set("template", e.target.value)} required>
|
||||
<option value="">Choose a template…</option>
|
||||
{draft.id !== null && !templates.some((t) => t.key === draft.template) && <option value={draft.template}>{data.plans.find((p) => p.id === draft.id)?.templateName ?? "the current one"} (as it is now)</option>}
|
||||
{templates.map((t) => (
|
||||
<option key={t.key} value={t.key}>
|
||||
{t.label}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
)}
|
||||
</div>
|
||||
<div className="col-md-4">
|
||||
<label className="form-label" htmlFor="pp-limit">
|
||||
Run it on each server by its
|
||||
</label>
|
||||
<select id="pp-limit" className="form-select" value={draft.limitFrom} onChange={(e) => set("limitFrom", e.target.value as "name" | "hostname")}>
|
||||
<option value="name">name here</option>
|
||||
<option value="hostname">host name it reports</option>
|
||||
</select>
|
||||
<div className="form-hint text-secondary small mt-1">Must match the host name in the Semaphore inventory.</div>
|
||||
</div>
|
||||
|
||||
<div className="col-12 d-flex flex-column gap-2">
|
||||
<label className="form-check mb-0">
|
||||
<input type="checkbox" className="form-check-input" checked={draft.stopOnFailure} onChange={(e) => set("stopOnFailure", e.target.checked)} />
|
||||
<span className="form-check-label">Stop at the first failure, and leave the servers after it alone</span>
|
||||
</label>
|
||||
<label className="form-check mb-0">
|
||||
<input type="checkbox" className="form-check-input" checked={draft.onlyWithUpdates} onChange={(e) => set("onlyWithUpdates", e.target.checked)} />
|
||||
<span className="form-check-label">Leave a server alone when it has no updates waiting</span>
|
||||
</label>
|
||||
<label className="form-check mb-0">
|
||||
<input type="checkbox" className="form-check-input" checked={draft.silenceDependents} onChange={(e) => set("silenceDependents", e.target.checked)} />
|
||||
<span className="form-check-label">Silence what depends on a server while it is updated (a guest that runs on it, a service that needs it)</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>
|
||||
<div className="card-footer d-flex gap-2">
|
||||
<button type="submit" className="btn btn-primary" disabled={busy || draft.name.trim() === "" || draft.days.length === 0 || (draft.tags.length === 0 && draft.serverIds.length === 0)}>
|
||||
{busy ? "Saving…" : "Save"}
|
||||
</button>
|
||||
<button type="button" className="btn" onClick={() => setDraft(null)}>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
)}
|
||||
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Plans</h3>
|
||||
{isAdmin && !draft && (
|
||||
<div className="card-actions">
|
||||
<button className="btn btn-primary" onClick={() => setDraft({ ...EMPTY, timezone: browserZone() })}>
|
||||
Make a plan
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{data === null && !error && <BlockSkeleton lines={3} />}
|
||||
{data && data.plans.length === 0 && (
|
||||
<EmptyState
|
||||
title="No patch plans yet"
|
||||
hint="A plan updates a group of servers on a schedule, one at a time, and stops if one fails. Tag the servers (for example “lab”), then make a plan for that tag."
|
||||
action={isAdmin ? { label: "Make a plan", onClick: () => setDraft({ ...EMPTY, timezone: browserZone() }) } : undefined}
|
||||
/>
|
||||
)}
|
||||
{data && data.plans.length > 0 && (
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter card-table table-stack">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Plan</th>
|
||||
<th>When</th>
|
||||
<th>Servers</th>
|
||||
<th>Next</th>
|
||||
{(canRun || isAdmin) && <th className="w-1">Actions</th>}
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{data.plans.map((p) => (
|
||||
<tr key={p.id}>
|
||||
<td className="stack-wide">
|
||||
<strong>{p.name}</strong> {!p.enabled && <span className="badge bg-secondary-lt text-secondary">Switched off</span>} {p.running && <span className="badge bg-blue-lt text-blue">Running</span>}
|
||||
<div className="text-secondary small">
|
||||
{p.templateName} · {p.stopOnFailure ? "stops at the first failure" : "carries on after a failure"}
|
||||
</div>
|
||||
</td>
|
||||
<td className="stack-label" data-label="When">
|
||||
{whenWords(p.days, p.startTime)}
|
||||
<div className="text-secondary small">{p.timezone}</div>
|
||||
</td>
|
||||
<td className="stack-label" data-label="Servers">
|
||||
{p.servers.length === 0 ? <span className="text-yellow">none match</span> : p.servers.map((s) => s.name).join(", ")}
|
||||
<div className="text-secondary small">{[...p.tags.map((t) => `tag ${t}`), p.serverIds.length > 0 ? `${p.serverIds.length} named` : null].filter(Boolean).join(" · ")}</div>
|
||||
</td>
|
||||
<td className="stack-label" data-label="Next">
|
||||
{p.enabled && p.next[0] ? formatDateTime(new Date(p.next[0])) : <span className="text-secondary">—</span>}
|
||||
</td>
|
||||
{(canRun || isAdmin) && (
|
||||
<td className="stack-wide">
|
||||
<div className="btn-list flex-nowrap">
|
||||
{canRun && (
|
||||
<button className="btn btn-sm btn-outline-primary" disabled={p.running || p.servers.length === 0} onClick={() => void runNow(p)}>
|
||||
Run now
|
||||
</button>
|
||||
)}
|
||||
{isAdmin && (
|
||||
<>
|
||||
<button className="btn btn-sm btn-outline-secondary" onClick={() => edit(p)}>
|
||||
Edit
|
||||
</button>
|
||||
<button className="btn btn-sm btn-outline-danger" disabled={p.running} onClick={() => void remove(p)}>
|
||||
Remove
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</td>
|
||||
)}
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -37,6 +37,11 @@ function StatusBadges({ entry }: { entry: PortEntry }) {
|
||||
if (entry.state === "reserved") return <span className="badge bg-secondary-lt text-secondary">Reserved</span>;
|
||||
return (
|
||||
<div className="d-flex flex-wrap gap-1">
|
||||
{entry.isNew && (
|
||||
<span className="badge bg-yellow-lt text-yellow" title="It began listening after this server's first report and nobody has said it is expected. It is on the Alerts page until you note it or it stops listening.">
|
||||
New
|
||||
</span>
|
||||
)}
|
||||
{entry.scanOpen && (
|
||||
<span className="badge bg-green-lt text-green" title="A scan from this app connected to it">
|
||||
Reachable
|
||||
@@ -187,6 +192,17 @@ export default function ServerPorts({
|
||||
}
|
||||
}
|
||||
|
||||
/** "This is expected": a note on the port ends the new-port alert. */
|
||||
async function markExpected(entry: PortEntry) {
|
||||
setError(null);
|
||||
try {
|
||||
const res = await api.servers.ports.save(serverId, { port: entry.port, protocol: entry.protocol, label: "Expected", comment: "" });
|
||||
setData((prev) => (prev ? { ...prev, ports: res.ports } : prev));
|
||||
} catch (err) {
|
||||
setError(readableError(err));
|
||||
}
|
||||
}
|
||||
|
||||
async function removeNote(entry: PortEntry) {
|
||||
if (entry.id === null) return;
|
||||
const what = entry.state === "reserved" ? `Remove the reservation for ${entry.protocol}/${entry.port}?` : `Clear the note on ${entry.protocol}/${entry.port}?`;
|
||||
@@ -482,6 +498,11 @@ export default function ServerPorts({
|
||||
{canEdit && (
|
||||
<td>
|
||||
<div className="btn-list flex-nowrap">
|
||||
{p.isNew && (
|
||||
<button className="btn btn-sm btn-outline-primary" onClick={() => void markExpected(p)} title="Notes it as expected, so there is no alert for it">
|
||||
Mark as expected
|
||||
</button>
|
||||
)}
|
||||
<button className="btn btn-sm btn-outline-secondary" onClick={() => editEntry(p)}>
|
||||
{p.label || p.comment ? "Edit" : "Add note"}
|
||||
</button>
|
||||
|
||||
@@ -32,6 +32,7 @@ import {
|
||||
IconSitemap,
|
||||
IconCalendarEvent,
|
||||
IconHeartRateMonitor,
|
||||
IconReportAnalytics,
|
||||
} from "@tabler/icons-react";
|
||||
import type { CurrentUser } from "../api/client";
|
||||
|
||||
@@ -126,6 +127,7 @@ export const NAV: NavEntry[] = [
|
||||
{ to: "/maintenance", label: "Maintenance", icon: <IconTool size={20} /> },
|
||||
{ to: "/updates", label: "Updates", icon: <IconDownload size={20} /> },
|
||||
{ to: "/coming-up", label: "Coming up", icon: <IconCalendarEvent size={20} /> },
|
||||
{ to: "/reports", label: "Monthly report", icon: <IconReportAnalytics size={20} /> },
|
||||
{ to: "/changes", label: "Change log", icon: <IconGitCommit size={20} />, minRole: "operator" },
|
||||
],
|
||||
},
|
||||
|
||||
@@ -147,7 +147,8 @@ export default function ComingUp({ user }: { user: CurrentUser }) {
|
||||
const seen = new Set<string>();
|
||||
let hidden = 0;
|
||||
const kept = withinRange.filter((i) => {
|
||||
const schedule = /^schedule:(\d+):/.exec(i.id)?.[1];
|
||||
const m = /^(schedule|plan):(\d+):/.exec(i.id);
|
||||
const schedule = m ? `${m[1]}:${m[2]}` : null;
|
||||
if (!schedule) return true;
|
||||
if (seen.has(schedule)) {
|
||||
hidden++;
|
||||
|
||||
@@ -630,7 +630,8 @@ export default function Dashboard({ user }: { user: CurrentUser }) {
|
||||
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];
|
||||
const m = /^(schedule|plan):(\d+):/.exec(i.id);
|
||||
const schedule = m ? `${m[1]}:${m[2]}` : null;
|
||||
if (!schedule) return true;
|
||||
if (seenSchedules.has(schedule)) return false;
|
||||
seenSchedules.add(schedule);
|
||||
|
||||
@@ -0,0 +1,413 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { Link, useSearchParams } from "react-router-dom";
|
||||
import { IconPrinter } from "@tabler/icons-react";
|
||||
import { api, type AvailabilityRow, type CurrentUser, type MonthlyReport as Report } from "../api/client";
|
||||
import { ErrorNotice } from "../components/Notice";
|
||||
import { BlockSkeleton } from "../components/Skeleton";
|
||||
import { CATEGORY_NAMES, incidentPath, SEVERITY_BADGE } from "../components/IncidentHistory";
|
||||
import { formatDate, formatDateTime } from "../utils/date";
|
||||
import { readableError } from "../utils/errors";
|
||||
import { toast } from "../utils/toast";
|
||||
|
||||
/** "2 h 40 min", "35 min", "3 d 4 h". */
|
||||
function span(minutes: number): string {
|
||||
const m = Math.max(1, Math.round(minutes));
|
||||
if (m < 60) return `${m} min`;
|
||||
const h = Math.floor(m / 60);
|
||||
if (h < 24) return m % 60 && h < 10 ? `${h} h ${m % 60} min` : `${h} h`;
|
||||
const d = Math.floor(h / 24);
|
||||
return h % 24 ? `${d} d ${h % 24} h` : `${d} d`;
|
||||
}
|
||||
|
||||
const RESULT_WORDS: Record<string, { label: string; badge: string }> = {
|
||||
ok: { label: "Passed", badge: "bg-green-lt text-green" },
|
||||
partial: { label: "Partly worked", badge: "bg-yellow-lt text-yellow" },
|
||||
failed: { label: "Failed", badge: "bg-red-lt text-red" },
|
||||
not_needed: { label: "Not needed", badge: "bg-secondary-lt text-secondary" },
|
||||
};
|
||||
|
||||
const average = (rows: { percent: number | null }[]) => {
|
||||
const known = rows.filter((r) => r.percent !== null);
|
||||
return known.length === 0 ? null : Math.round((known.reduce((n, r) => n + (r.percent as number), 0) / known.length) * 10) / 10;
|
||||
};
|
||||
|
||||
const percentBadge = (p: number | null) => (p === null ? "text-secondary" : p >= 99.9 ? "text-green" : p >= 99 ? "" : p >= 95 ? "text-yellow" : "text-red");
|
||||
|
||||
function Availability({ title, rows, hint }: { title: string; rows: AvailabilityRow[]; hint?: string }) {
|
||||
if (rows.length === 0) return null;
|
||||
return (
|
||||
<div className="mb-3">
|
||||
<h4 className="mb-1">{title}</h4>
|
||||
{hint && <div className="text-secondary small mb-2">{hint}</div>}
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter table-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th className="text-end">Up</th>
|
||||
<th className="text-end">Down for</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{rows.map((r) => (
|
||||
<tr key={r.id}>
|
||||
<td>{r.name}</td>
|
||||
<td className={`text-end ${percentBadge(r.percent)}`}>{r.percent === null ? "—" : `${r.percent}%`}</td>
|
||||
<td className="text-end text-secondary">{r.downMinutes > 0 ? span(r.downMinutes) : "—"}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* How a month went, in one page that can be read, printed or sent: how available the servers and endpoints were, the incidents and how long they took, the
|
||||
* updates applied, restore tests and the state of the backups, and what was renewed. The same report can be sent on a day of the month (Settings →
|
||||
* Notifications → Monthly report).
|
||||
*/
|
||||
export default function MonthlyReport({ user }: { user: CurrentUser }) {
|
||||
const [params, setParams] = useSearchParams();
|
||||
const month = params.get("month") ?? undefined;
|
||||
const [data, setData] = useState<{ report: Report; months: { id: string; label: string }[] } | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let alive = true;
|
||||
setData(null);
|
||||
api.reports
|
||||
.monthly(month)
|
||||
.then((res) => {
|
||||
if (!alive) return;
|
||||
setData(res);
|
||||
setError(null);
|
||||
})
|
||||
.catch((err) => alive && setError(readableError(err)));
|
||||
return () => {
|
||||
alive = false;
|
||||
};
|
||||
}, [month]);
|
||||
|
||||
async function copyText() {
|
||||
try {
|
||||
const t = await api.reports.monthlyText(data?.report.month);
|
||||
await navigator.clipboard.writeText(`${t.title}\n\n${t.message}`);
|
||||
toast.success("Copied the report as text.");
|
||||
} catch (err) {
|
||||
toast.error(readableError(err));
|
||||
}
|
||||
}
|
||||
|
||||
const r = data?.report;
|
||||
const serverAvg = r ? average(r.servers) : null;
|
||||
const endpointAvg = r ? average(r.endpoints) : null;
|
||||
const cards = r
|
||||
? [
|
||||
{ label: "Servers up, on average", value: serverAvg === null ? "—" : `${serverAvg}%`, color: percentBadge(serverAvg) },
|
||||
{ label: "Endpoints answering", value: endpointAvg === null ? "—" : `${endpointAvg}%`, color: percentBadge(endpointAvg) },
|
||||
{ label: "Incidents began", value: String(r.incidents.began), color: r.incidents.began > 0 ? "text-yellow" : "text-green" },
|
||||
{ label: "Update runs", value: String(r.updates.runs), color: r.updates.failed > 0 ? "text-yellow" : "" },
|
||||
{ label: "Renewed", value: String(r.renewals.length), color: "" },
|
||||
]
|
||||
: [];
|
||||
|
||||
return (
|
||||
<div className="report-page">
|
||||
<div className="d-flex flex-wrap align-items-center gap-2 mb-1">
|
||||
<h2 className="page-title mb-0">Monthly report</h2>
|
||||
<div className="ms-auto d-flex flex-wrap gap-2 no-print">
|
||||
{data && (
|
||||
<select className="form-select w-auto" aria-label="Month" value={r?.month ?? ""} onChange={(e) => setParams(e.target.value === data.months[1]?.id ? {} : { month: e.target.value }, { replace: true })}>
|
||||
{data.months.map((m) => (
|
||||
<option key={m.id} value={m.id}>
|
||||
{m.label}
|
||||
{m.id === data.months[0].id ? " (so far)" : ""}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
)}
|
||||
<button className="btn btn-outline-secondary" onClick={() => void copyText()} disabled={!r}>
|
||||
Copy as text
|
||||
</button>
|
||||
<button className="btn btn-outline-secondary d-inline-flex align-items-center gap-1" onClick={() => window.print()} disabled={!r}>
|
||||
<IconPrinter size={16} aria-hidden="true" /> Print
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<p className="text-secondary no-print">
|
||||
How the month went, in one page: availability, incidents and how long they took, updates applied, restore tests and backups, and what was renewed.
|
||||
{user.role === "admin" ? (
|
||||
<>
|
||||
{" "}
|
||||
It can be sent on a day of the month: <Link to="/settings/notifications">Settings → Notifications</Link>.
|
||||
</>
|
||||
) : null}
|
||||
</p>
|
||||
<ErrorNotice error={error} />
|
||||
{!data && !error && <BlockSkeleton lines={6} />}
|
||||
|
||||
{r && (
|
||||
<>
|
||||
<h3 className="mb-1">{r.label}</h3>
|
||||
<div className="text-secondary mb-3">
|
||||
{formatDate(new Date(r.from))} – {formatDate(new Date(r.to))}
|
||||
{r.partial ? " · the month is not over, so this is the month so far" : ""} · time zone {r.timezone}
|
||||
</div>
|
||||
|
||||
<div className="row row-cards mb-3">
|
||||
{cards.map((c) => (
|
||||
<div className="col-6 col-md" 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-header">
|
||||
<h3 className="card-title">Availability</h3>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
{r.servers.length === 0 && r.endpoints.length === 0 && r.integrations.length === 0 ? (
|
||||
<div className="text-secondary">Nothing was measured for this month. Servers are measured from when their agent first reported, endpoints from when they were first checked.</div>
|
||||
) : (
|
||||
<>
|
||||
<Availability title="Servers" rows={r.servers} hint="From when each stopped reporting and reported again; the worst first." />
|
||||
{r.endpoints.length > 0 && (
|
||||
<div className="mb-3">
|
||||
<h4 className="mb-1">Endpoints</h4>
|
||||
<div className="text-secondary small mb-2">From every check's answers, day by day (the days are UTC days).</div>
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter table-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Check</th>
|
||||
<th className="text-end">Answered</th>
|
||||
<th className="text-end">Average answer</th>
|
||||
<th className="text-end">Times asked</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{r.endpoints.map((e) => (
|
||||
<tr key={e.id}>
|
||||
<td>{e.name}</td>
|
||||
<td className={`text-end ${percentBadge(e.percent)}`}>{e.percent === null ? "—" : `${e.percent}%`}</td>
|
||||
<td className="text-end text-secondary">{e.avgMs === null ? "—" : `${e.avgMs} ms`}</td>
|
||||
<td className="text-end text-secondary">{e.checks}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
<Availability title="Integrations" rows={r.integrations} hint="How often the calls to each kind of integration worked." />
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Incidents</h3>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
{r.incidents.began === 0 && r.incidents.resolved === 0 && r.incidents.stillOpen === 0 ? (
|
||||
<div className="text-secondary">No incident began or ended this month.</div>
|
||||
) : (
|
||||
<>
|
||||
<p>
|
||||
<strong>{r.incidents.began}</strong> began, <strong>{r.incidents.resolved}</strong> ended{r.incidents.stillOpen > 0 ? <>, <strong>{r.incidents.stillOpen}</strong> {r.partial ? "open" : "still open at the end of the month"}</> : null}.
|
||||
{r.incidents.averageMinutes !== null && <> One that began and ended in the month took {span(r.incidents.averageMinutes)} on average, {span(r.incidents.totalMinutes)} in all.</>}
|
||||
</p>
|
||||
{r.incidents.byCategory.length > 0 && (
|
||||
<div className="mb-3 d-flex flex-wrap gap-2">
|
||||
{r.incidents.byCategory.map((c) => (
|
||||
<span key={c.category} className="badge bg-secondary-lt text-secondary">
|
||||
{CATEGORY_NAMES[c.category as keyof typeof CATEGORY_NAMES] ?? c.category} · {c.count}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter table-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Began</th>
|
||||
<th>Where</th>
|
||||
<th>What</th>
|
||||
<th>Worst</th>
|
||||
<th className="text-end">Lasted</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{r.incidents.list.map((i) => (
|
||||
<tr key={i.id}>
|
||||
<td className="text-nowrap">{formatDateTime(new Date(i.openedAt))}</td>
|
||||
<td>{i.where}</td>
|
||||
<td>
|
||||
<Link to={incidentPath(i.id)}>{i.message}</Link>
|
||||
</td>
|
||||
<td>
|
||||
<span className={`badge ${SEVERITY_BADGE[i.severity] ?? ""}`}>{i.severity}</span>
|
||||
</td>
|
||||
<td className="text-end text-nowrap">
|
||||
{span(i.minutes)}
|
||||
{!i.resolvedAt && <span className="text-secondary small"> and open</span>}
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
{r.incidents.began > r.incidents.list.length && <div className="text-secondary small">The {r.incidents.list.length} longest of {r.incidents.began}. All are under Alerts → History.</div>}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Updates</h3>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
{r.updates.runs === 0 && r.updates.planRuns.runs === 0 ? (
|
||||
<div className="text-secondary">No update run was made from here this month.</div>
|
||||
) : (
|
||||
<>
|
||||
<p>
|
||||
<strong>{r.updates.runs}</strong> update run{r.updates.runs === 1 ? "" : "s"}: {r.updates.done} done{r.updates.failed > 0 ? `, ${r.updates.failed} failed` : ""}
|
||||
{r.updates.installed > 0 ? ` — ${r.updates.installed} update${r.updates.installed === 1 ? "" : "s"} installed` : ""}.
|
||||
{r.updates.planRuns.runs > 0 && (
|
||||
<>
|
||||
{" "}
|
||||
Patch plans ran {r.updates.planRuns.runs} time{r.updates.planRuns.runs === 1 ? "" : "s"}
|
||||
{r.updates.planRuns.failed > 0 ? `, ${r.updates.planRuns.failed} not cleanly` : ", all cleanly"}.
|
||||
</>
|
||||
)}
|
||||
</p>
|
||||
{r.updates.byServer.length > 0 && (
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter table-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Server</th>
|
||||
<th className="text-end">Runs</th>
|
||||
<th className="text-end">Failed</th>
|
||||
<th className="text-end">Installed</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{r.updates.byServer.map((s) => (
|
||||
<tr key={s.name}>
|
||||
<td>{s.name}</td>
|
||||
<td className="text-end">{s.runs}</td>
|
||||
<td className={`text-end ${s.failed > 0 ? "text-red" : "text-secondary"}`}>{s.failed || "—"}</td>
|
||||
<td className="text-end">{s.installed || "—"}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Backups and restore tests</h3>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
{r.restoreTests.length === 0 ? (
|
||||
<p className="text-secondary">No restore test was recorded this month.</p>
|
||||
) : (
|
||||
<div className="table-responsive mb-2">
|
||||
<table className="table table-vcenter table-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Tested</th>
|
||||
<th>What</th>
|
||||
<th>Result</th>
|
||||
<th>Note</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{r.restoreTests.map((t, i) => (
|
||||
<tr key={`${t.label}-${i}`}>
|
||||
<td className="text-nowrap">{t.testedAt}</td>
|
||||
<td>{t.label}</td>
|
||||
<td>
|
||||
<span className={`badge ${RESULT_WORDS[t.result]?.badge ?? ""}`}>{RESULT_WORDS[t.result]?.label ?? t.result}</span>
|
||||
</td>
|
||||
<td className="text-secondary">{t.note ?? ""}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
{r.backups ? (
|
||||
<p className="mb-0">
|
||||
Backups as they are now (<span title={formatDateTime(new Date(r.backups.asOf))}>read {formatDate(new Date(r.backups.asOf))}</span>): <strong>{r.backups.ok}</strong> of {r.backups.total} guest{r.backups.total === 1 ? "" : "s"} have a recent one
|
||||
{r.backups.failed + r.backups.stale + r.backups.none + r.backups.unknown > 0 && (
|
||||
<>
|
||||
; {r.backups.failed} failed, {r.backups.stale} stale, {r.backups.none} without any{r.backups.unknown > 0 ? `, ${r.backups.unknown} unknown` : ""}
|
||||
</>
|
||||
)}
|
||||
. See <Link to="/backups">Backup coverage</Link>.
|
||||
</p>
|
||||
) : (
|
||||
<p className="text-secondary mb-0">The backups have not been read since this app started, so their state is not shown here. Open Backup coverage to read them.</p>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Renewed</h3>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
{r.renewals.length === 0 ? (
|
||||
<div className="text-secondary">No certificate or domain was seen to be renewed this month.</div>
|
||||
) : (
|
||||
<div className="table-responsive">
|
||||
<table className="table table-vcenter table-sm">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Seen</th>
|
||||
<th>What</th>
|
||||
<th>Was good until</th>
|
||||
<th>Is good until</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{r.renewals.map((x, i) => (
|
||||
<tr key={`${x.subject}-${i}`}>
|
||||
<td className="text-nowrap">{formatDate(new Date(x.at))}</td>
|
||||
<td>
|
||||
{x.kind === "domain" ? "Domain" : "Certificate"} {x.subject}
|
||||
</td>
|
||||
<td className="text-secondary">{x.fromDate}</td>
|
||||
<td>{x.toDate}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
)}
|
||||
<div className="text-secondary small mt-2">Renewals are noticed when the app re-reads an expiry date, so only those since it began watching are here.</div>
|
||||
</div>
|
||||
</div>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { useEffect, useState, type ReactNode } from "react";
|
||||
import { Link, useSearchParams } from "react-router-dom";
|
||||
import { api, type AgentLatest, type CurrentUser, type DockhandContainer, type UpdatesServer } from "../api/client";
|
||||
import { agentState, agentVersionWords } from "../utils/agent";
|
||||
@@ -15,6 +15,8 @@ import { readableError } from "../utils/errors";
|
||||
import ExportTableButton from "../components/ExportTableButton";
|
||||
import UpdateRunDrawer from "../components/UpdateRunDrawer";
|
||||
import UpdateRunsCard from "../components/UpdateRunsCard";
|
||||
import ViewTabs from "../components/ViewTabs";
|
||||
import PatchPlans from "../components/PatchPlans";
|
||||
import { EmptyRow } from "../components/EmptyState";
|
||||
|
||||
interface Row {
|
||||
@@ -56,7 +58,34 @@ const DAY_MS = 86_400_000;
|
||||
* whether a restart is due, and how long they have been waiting) and the Docker containers that have a newer image. It only looks —
|
||||
* nothing here installs anything.
|
||||
*/
|
||||
const updateTabs = (view: "waiting" | "plans") => (
|
||||
<ViewTabs
|
||||
label="Updates view"
|
||||
tabs={[
|
||||
{ to: "/updates", label: "Waiting now", active: view === "waiting" },
|
||||
{ to: "/updates?view=plans", label: "Patch plans", active: view === "plans" },
|
||||
]}
|
||||
/>
|
||||
);
|
||||
|
||||
/** What is waiting to be installed, and — as patch plans — updating on a schedule, one server at a time (`?view=plans`). */
|
||||
export default function Updates({ user }: { user: CurrentUser }) {
|
||||
const [params] = useSearchParams();
|
||||
if (params.get("view") === "plans") {
|
||||
return (
|
||||
<>
|
||||
<div className="d-flex align-items-center mb-2">
|
||||
<h2 className="page-title mb-0">Updates</h2>
|
||||
</div>
|
||||
{updateTabs("plans")}
|
||||
<PatchPlans user={user} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
return <WaitingNow user={user} tabs={updateTabs("waiting")} />;
|
||||
}
|
||||
|
||||
function WaitingNow({ user, tabs }: { user: CurrentUser; tabs: ReactNode }) {
|
||||
const canRun = user.role === "admin" || user.role === "operator";
|
||||
// The server being updated now (its drawer is open), and a counter that makes the runs card look again after one was started.
|
||||
const [updating, setUpdating] = useState<UpdatesServer | null>(null);
|
||||
@@ -154,9 +183,10 @@ export default function Updates({ user }: { user: CurrentUser }) {
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="d-flex align-items-center mb-3">
|
||||
<div className="d-flex align-items-center mb-2">
|
||||
<h2 className="page-title mb-0">Updates</h2>
|
||||
</div>
|
||||
{tabs}
|
||||
<p className="text-secondary">
|
||||
What the agents say is waiting to be installed on each server, and the Docker containers that have a newer image. {canRun ? "Update… applies a server's updates through a Semaphore playbook: it silences the server, runs the playbook, waits for the server to report again and tells you what is left." : "Operators can apply a server's updates from here."}
|
||||
</p>
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
type EscalationSettings,
|
||||
type NotificationEvents,
|
||||
type DigestSettings,
|
||||
type MonthlyReportSettings,
|
||||
type QuietHoursSettings,
|
||||
type HealthCheckSettings,
|
||||
} from "../../api/client";
|
||||
@@ -81,7 +82,8 @@ const DIGEST_DAYS: { value: number; label: string }[] = [
|
||||
{ value: 6, label: "Saturday" },
|
||||
{ value: 0, label: "Sunday" },
|
||||
];
|
||||
const DEFAULT_HEALTH_CHECKS: HealthCheckSettings = { serverOfflineMinutes: 60, diskUsagePercent: 90, domainWarnDays: 30, diskForecastDays: 14, backupStaleHours: 48, restoreTestDays: 0 };
|
||||
const DEFAULT_HEALTH_CHECKS: HealthCheckSettings = { serverOfflineMinutes: 60, diskUsagePercent: 90, domainWarnDays: 30, diskForecastDays: 14, backupStaleHours: 48, restoreTestDays: 0, newPortAlerts: true };
|
||||
const DEFAULT_MONTHLY: MonthlyReportSettings = { enabled: false, day: 1, time: "08:00" };
|
||||
|
||||
type TestResult = { ok: boolean; message: string } | null;
|
||||
type EventKey = { [K in keyof NotificationEvents]: NotificationEvents[K] extends boolean ? K : never }[keyof NotificationEvents];
|
||||
@@ -240,6 +242,10 @@ export default function NotificationSettings() {
|
||||
const [digestPreview, setDigestPreview] = useState<{ title: string; message: string } | null>(null);
|
||||
const [digestBusy, setDigestBusy] = useState<"preview" | "send" | null>(null);
|
||||
const [digestResult, setDigestResult] = useState<TestResult>(null);
|
||||
const [monthly, setMonthly] = useState<MonthlyReportSettings>(DEFAULT_MONTHLY);
|
||||
const [monthlyPreview, setMonthlyPreview] = useState<{ title: string; message: string } | null>(null);
|
||||
const [monthlyBusy, setMonthlyBusy] = useState<"preview" | "send" | null>(null);
|
||||
const [monthlyResult, setMonthlyResult] = useState<TestResult>(null);
|
||||
const [queuedCount, setQueuedCount] = useState<number | null>(null);
|
||||
const [flushing, setFlushing] = useState(false);
|
||||
const [flushResult, setFlushResult] = useState<string | null>(null);
|
||||
@@ -253,7 +259,7 @@ export default function NotificationSettings() {
|
||||
const [testingWebhook, setTestingWebhook] = useState(false);
|
||||
const [testWebhookResult, setTestWebhookResult] = useState<TestResult>(null);
|
||||
|
||||
const snapshot = JSON.stringify({ gotify, ntfy, smtp, webhook, webPush, routing, escalation, notifications, quietHours, healthChecks, digest });
|
||||
const snapshot = JSON.stringify({ gotify, ntfy, smtp, webhook, webPush, routing, escalation, notifications, quietHours, healthChecks, digest, monthlyReport: monthly });
|
||||
const dirty = baseline !== null && snapshot !== baseline;
|
||||
|
||||
useEffect(() => {
|
||||
@@ -277,7 +283,9 @@ export default function NotificationSettings() {
|
||||
setHealthChecks(s.healthChecks);
|
||||
const d = s.digest ?? DEFAULT_DIGEST;
|
||||
setDigest(d);
|
||||
setBaseline(JSON.stringify({ gotify: s.gotify, ntfy: s.ntfy, smtp: s.smtp, webhook: s.webhook, webPush: wp, routing: rt, escalation: es, notifications: s.notifications, quietHours: s.quietHours, healthChecks: s.healthChecks, digest: d }));
|
||||
const mo = s.monthlyReport ?? DEFAULT_MONTHLY;
|
||||
setMonthly(mo);
|
||||
setBaseline(JSON.stringify({ gotify: s.gotify, ntfy: s.ntfy, smtp: s.smtp, webhook: s.webhook, webPush: wp, routing: rt, escalation: es, notifications: s.notifications, quietHours: s.quietHours, healthChecks: s.healthChecks, digest: d, monthlyReport: mo }));
|
||||
})
|
||||
.catch((err) => setLoadError(err instanceof Error ? err.message : String(err)))
|
||||
.finally(() => setLoading(false));
|
||||
@@ -324,7 +332,7 @@ export default function NotificationSettings() {
|
||||
setSaveError(null);
|
||||
setSaved(false);
|
||||
try {
|
||||
await api.settings.update({ gotify, ntfy, smtp, webhook, webPush, routing, escalation, notifications, quietHours, healthChecks, digest });
|
||||
await api.settings.update({ gotify, ntfy, smtp, webhook, webPush, routing, escalation, notifications, quietHours, healthChecks, digest, monthlyReport: monthly });
|
||||
setBaseline(snapshot);
|
||||
setWebPushSaved(webPush.enabled);
|
||||
setSaved(true);
|
||||
@@ -362,6 +370,31 @@ export default function NotificationSettings() {
|
||||
}
|
||||
}
|
||||
|
||||
async function handleMonthlyPreview() {
|
||||
setMonthlyBusy("preview");
|
||||
setMonthlyResult(null);
|
||||
try {
|
||||
setMonthlyPreview(await api.reports.monthlyText());
|
||||
} catch (err) {
|
||||
setMonthlyResult({ ok: false, message: readableError(err) });
|
||||
} finally {
|
||||
setMonthlyBusy(null);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleMonthlySend() {
|
||||
setMonthlyBusy("send");
|
||||
setMonthlyResult(null);
|
||||
try {
|
||||
await api.reports.sendMonthly();
|
||||
setMonthlyResult({ ok: true, message: "Sent through the channels that are on." });
|
||||
} catch (err) {
|
||||
setMonthlyResult({ ok: false, message: readableError(err) });
|
||||
} finally {
|
||||
setMonthlyBusy(null);
|
||||
}
|
||||
}
|
||||
|
||||
async function handleFlushNow() {
|
||||
setFlushing(true);
|
||||
setFlushResult(null);
|
||||
@@ -702,6 +735,16 @@ export default function NotificationSettings() {
|
||||
hint="From each agent server's own history, shown on the Alerts page and dashboard (not sent as a notification). Needs a few days of steady growth to say anything. 0 turns it off."
|
||||
onChange={(v) => setHealthChecks((h) => ({ ...h, diskForecastDays: v }))}
|
||||
/>
|
||||
<label className="form-check mt-3 mb-0">
|
||||
<input type="checkbox" className="form-check-input" checked={healthChecks.newPortAlerts} onChange={(e) => setHealthChecks((h) => ({ ...h, newPortAlerts: e.target.checked }))} />
|
||||
<span className="form-check-label">
|
||||
Warn when a server starts listening on a new port
|
||||
<span className="form-hint d-block">
|
||||
The first report from each agent says what is normal; a TCP port that appears later (not UDP, not 49152 and up, not localhost only) is on the Alerts page until it is marked as
|
||||
expected on the server’s Ports card or stops listening. Sent with the server offline and disk messages.
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -893,6 +936,62 @@ export default function NotificationSettings() {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="col-12">
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">Monthly report</h3>
|
||||
</div>
|
||||
<div className="card-body">
|
||||
<p className="text-secondary">
|
||||
One message a month with last month in numbers: how available the servers and endpoints were, the incidents and how long they took, updates applied (by hand and by patch plans),
|
||||
restore tests, and what was renewed. The same report is on the <a href="/reports">Monthly report</a> page, to read and print. Quiet hours hold it like any other notification.
|
||||
</p>
|
||||
<label className="form-check mb-3">
|
||||
<input type="checkbox" className="form-check-input" checked={monthly.enabled} onChange={(e) => setMonthly((m) => ({ ...m, enabled: e.target.checked }))} />
|
||||
<span className="form-check-label">Send the monthly report</span>
|
||||
</label>
|
||||
<div className="row g-2 mb-3" style={{ maxWidth: 420 }}>
|
||||
<div className="col-6">
|
||||
<label className="form-label" htmlFor="monthly-day">
|
||||
Day of the month
|
||||
</label>
|
||||
<select id="monthly-day" className="form-select" value={monthly.day} disabled={!monthly.enabled} onChange={(e) => setMonthly((m) => ({ ...m, day: Number(e.target.value) }))}>
|
||||
{Array.from({ length: 28 }, (_, i) => i + 1).map((d) => (
|
||||
<option key={d} value={d}>
|
||||
{d}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
</div>
|
||||
<div className="col-6">
|
||||
<label className="form-label" htmlFor="monthly-time">
|
||||
Time
|
||||
</label>
|
||||
<input id="monthly-time" type="time" className="form-control" value={monthly.time} disabled={!monthly.enabled} onChange={(e) => setMonthly((m) => ({ ...m, time: e.target.value }))} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="btn-list">
|
||||
<button type="button" className="btn btn-outline-secondary" onClick={handleMonthlyPreview} disabled={monthlyBusy !== null}>
|
||||
{monthlyBusy === "preview" ? "Gathering…" : "Preview last month"}
|
||||
</button>
|
||||
<button type="button" className="btn btn-outline-secondary" onClick={handleMonthlySend} disabled={monthlyBusy !== null}>
|
||||
{monthlyBusy === "send" ? "Sending…" : "Send last month now"}
|
||||
</button>
|
||||
</div>
|
||||
<div className="form-hint mt-2">The day and time are saved with the Save button; the preview and "send now" don't depend on them. The day is at most the 28th, so every month has it.</div>
|
||||
<TestBadge result={monthlyResult} />
|
||||
{monthlyPreview && (
|
||||
<div className="mt-3">
|
||||
<div className="fw-bold">{monthlyPreview.title}</div>
|
||||
<pre className="border rounded p-2 mt-1 mb-0" style={{ whiteSpace: "pre-wrap", fontSize: "0.8125rem" }}>
|
||||
{monthlyPreview.message}
|
||||
</pre>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="col-12">
|
||||
<div className="card">
|
||||
<div className="card-header">
|
||||
|
||||
+18
-1
@@ -1549,10 +1549,27 @@ html[data-density="roomy"] .table > :not(caption) > * > * {
|
||||
|
||||
@media print {
|
||||
.no-print,
|
||||
.navbar-vertical {
|
||||
.navbar-vertical,
|
||||
.navbar-toggler,
|
||||
.breadcrumb,
|
||||
.toast-stack {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
/* The monthly report: each section stays whole on a page, in plain black on white. */
|
||||
.report-page .card {
|
||||
break-inside: avoid;
|
||||
border: 1px solid #ccc;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.report-page,
|
||||
.report-page .card,
|
||||
.report-page .text-secondary {
|
||||
color: #000 !important;
|
||||
background: #fff !important;
|
||||
}
|
||||
|
||||
.page-wrapper {
|
||||
margin: 0 !important;
|
||||
padding: 0 !important;
|
||||
|
||||
Reference in new issue
Block a user