import { useEffect, useState } from "react"; import ImpactNote from "../components/ImpactNote"; import { api, type CurrentUser, type IntegrationSummary, type MaintenanceAlias, type MaintenanceBulkScope, type MaintenanceTargets, type MaintenanceTargetType, type MaintenanceWindow, type UptimeKumaImportResult, type UptimeKumaSyncResult, } from "../api/client"; import { formatDateTime } from "../utils/date"; import { formatRemaining } from "../utils/duration"; import { readableError } from "../utils/errors"; import { ErrorNotice } from "../components/Notice"; import { toast } from "../utils/toast"; import { confirmDialog } from "../utils/dialogs"; import MaintenanceTimeline from "../components/MaintenanceTimeline"; import RecurringMaintenance from "../components/RecurringMaintenance"; import ExportTableButton from "../components/ExportTableButton"; import { EmptyRow, LoadingRow } from "../components/EmptyState"; import PageIntro from "../components/PageIntro"; import { t } from "../i18n"; const DURATIONS: { minutes: number; label: string }[] = [ { minutes: 30, label: "30 minutes" }, { minutes: 60, label: "1 hour" }, { minutes: 120, label: "2 hours" }, { minutes: 240, label: "4 hours" }, { minutes: 480, label: "8 hours" }, { minutes: 1440, label: "24 hours" }, { minutes: 4320, label: "3 days" }, ]; // Tells the app shell's banner to refetch right away instead of waiting for its next poll. function announceChange() { window.dispatchEvent(new Event("maintenance-changed")); } export default function Maintenance({ user }: { user: CurrentUser }) { const canEdit = user.role === "admin" || user.role === "operator"; const [windows, setWindows] = useState(null); const [upcoming, setUpcoming] = useState([]); const [aliases, setAliases] = useState([]); const [aliasAddress, setAliasAddress] = useState(""); const [aliasTarget, setAliasTarget] = useState(""); const [aliasBusy, setAliasBusy] = useState(false); const [aliasError, setAliasError] = useState(null); const [targets, setTargets] = useState(null); // Whether what depends on the chosen target is silenced along with it (offered once the target is known to have dependents). const [withDependents, setWithDependents] = useState(true); const [error, setError] = useState(null); const [now, setNow] = useState(() => Date.now()); const [target, setTarget] = useState(""); const [minutes, setMinutes] = useState(60); const [reason, setReason] = useState(""); const [busy, setBusy] = useState(false); const [kumaIntegrations, setKumaIntegrations] = useState(null); const [kumaIntegrationId, setKumaIntegrationId] = useState(""); const [kumaMinutes, setKumaMinutes] = useState(60); const [kumaBusy, setKumaBusy] = useState(false); const [kumaError, setKumaError] = useState(null); const [kumaResult, setKumaResult] = useState(null); const [syncBusy, setSyncBusy] = useState(false); const [syncError, setSyncError] = useState(null); const [syncResult, setSyncResult] = useState(null); useEffect(() => { api.integrations .list() .then((res) => { const found = res.integrations.filter((i) => i.type === "uptimekuma"); setKumaIntegrations(found); const firstEnabled = found.find((i) => i.enabled); if (firstEnabled) setKumaIntegrationId(firstEnabled.id); }) .catch(() => setKumaIntegrations([])); }, []); function load() { api.maintenance .list() .then((res) => { setWindows(res.windows); setUpcoming(res.upcoming ?? []); setAliases(res.aliases ?? []); setTargets(res.targets); }) .catch((err) => setError(readableError(err))); } useEffect(() => { load(); const tick = setInterval(() => setNow(Date.now()), 30_000); return () => clearInterval(tick); }, []); async function startBulk(scope: MaintenanceBulkScope) { const words = t(DURATIONS.find((d) => d.minutes === minutes)?.label ?? "{n} minutes", { n: minutes }); // Everything is the one choice that can hide a real outage, so it asks first. if ( scope === "everything" && !(await confirmDialog({ title: t("Silence everything?"), message: `This silences every alert about every server, integration and DNS provider for ${words}. Anything still wrong when it ends alerts then.`, confirmLabel: t("Silence everything"), danger: true, })) ) return; setError(null); setBusy(true); try { const res = await api.maintenance.startBulk({ scope, minutes, reason: reason.trim() || undefined }); setTarget(""); setReason(""); toast.success(`Maintenance started on ${res.total} item${res.total === 1 ? "" : "s"} for ${words}. End them all from the Active list.`); load(); announceChange(); } catch (err) { setError(readableError(err)); } finally { setBusy(false); } } async function endAll() { if (!(await confirmDialog({ title: t("End all maintenance"), message: `End all ${windows?.length ?? 0} windows now? Alerts about them become active again.`, confirmLabel: t("End all"), danger: true }))) return; setError(null); try { const res = await api.maintenance.endAll(); toast.success(`Ended ${res.ended} maintenance window${res.ended === 1 ? "" : "s"}. Alerts are active again.`); load(); announceChange(); } catch (err) { setError(readableError(err)); } } async function start(e: React.FormEvent) { e.preventDefault(); if (target.startsWith("all:")) return startBulk(target.slice(4) as MaintenanceBulkScope); const [targetType, id] = target.split(":"); if (!targetType || !id) return; setError(null); setBusy(true); try { const res = await api.maintenance.start({ targetType: targetType as MaintenanceTargetType, targetId: Number(id), minutes, reason: reason.trim() || undefined, withDependents: withDependents || undefined, }); setTarget(""); setReason(""); const also = res.alsoSilenced?.length ?? 0; toast.success(also > 0 ? `Maintenance started, and on ${also} thing${also === 1 ? "" : "s"} that depend on it. Alerts for them are silenced until it ends.` : t("Maintenance started. Alerts for it are silenced until it ends.")); load(); announceChange(); } catch (err) { setError(readableError(err)); } finally { setBusy(false); } } async function addAlias(e: React.FormEvent) { e.preventDefault(); const [targetType, id] = aliasTarget.split(":"); if (!targetType || !id) return; setAliasError(null); setAliasBusy(true); try { await api.maintenance.addAlias({ address: aliasAddress.trim(), targetType: targetType as MaintenanceTargetType, targetId: Number(id) }); setAliasAddress(""); setAliasTarget(""); load(); } catch (err) { setAliasError(readableError(err)); } finally { setAliasBusy(false); } } async function removeAlias(a: MaintenanceAlias) { setAliasError(null); try { await api.maintenance.removeAlias(a.id); load(); } catch (err) { setAliasError(readableError(err)); } } async function end(w: MaintenanceWindow) { setError(null); try { await api.maintenance.end(w.id); toast.success(w.startedAt > new Date().toISOString() ? t("Scheduled window cancelled.") : t("Maintenance ended. Alerts for it are active again.")); load(); announceChange(); } catch (err) { setError(readableError(err)); } } async function syncFromUptimeKuma() { if (kumaIntegrationId === "") return; setSyncError(null); setSyncResult(null); setSyncBusy(true); try { const result = await api.maintenance.syncUptimeKuma({ integrationId: kumaIntegrationId }); setSyncResult(result); load(); announceChange(); } catch (err) { setSyncError(readableError(err)); } finally { setSyncBusy(false); } } async function importFromUptimeKuma(e: React.FormEvent) { e.preventDefault(); if (kumaIntegrationId === "") return; setKumaError(null); setKumaResult(null); setKumaBusy(true); try { const result = await api.maintenance.importUptimeKuma({ integrationId: kumaIntegrationId, minutes: kumaMinutes }); setKumaResult(result); if (result.imported.length > 0) { load(); announceChange(); } } catch (err) { setKumaError(readableError(err)); } finally { setKumaBusy(false); } } return ( <>

{t("Maintenance")}

Silence alerts about one server or integration while you work on it. Every window ends on its own — anything still wrong when it ends alerts then, so nothing stays hidden. {canEdit && (

{t("Start maintenance")}

setReason(e.target.value)} />
{(target.startsWith("server:") || target.startsWith("integration:")) && (
)}
)} {((windows?.length ?? 0) > 0 || upcoming.length > 0) && } { load(); announceChange(); }} /> {canEdit && kumaIntegrations && kumaIntegrations.length > 0 && (

{t("Import from Uptime Kuma")}

{t("Sync schedule")} copies Uptime Kuma's maintenance windows — the one running now and the next one of each daily, weekly or one-off window — onto the servers their monitors belong to, so they show up under Scheduled below and silence alerts when they start. It needs the login username and password filled in on the integration, and runs by itself every 15 minutes when{" "} {t("Keep maintenance windows in step")} is ticked there.
{t("Import now")} only looks at what is in maintenance this moment: pick a duration — it doesn't have to match Uptime Kuma's own schedule exactly, and importing again later just extends the window instead of stacking a second one.
{kumaIntegrations.length > 1 && (
)}
{syncError && (
{syncError}
)} {syncResult && (
0 ? "alert-success" : "alert-info"} mb-0`}> {syncResult.maintenances.length === 0 ? t("Uptime Kuma has no maintenance windows.") : `Read ${syncResult.maintenances.length} maintenance window${syncResult.maintenances.length === 1 ? "" : "s"} from Uptime Kuma: ${syncResult.started} added, ${syncResult.updated} changed, ${syncResult.removed} removed here.`}
    {syncResult.maintenances.map((m) => (
  • {m.title}{" "} ({m.strategy}, {m.status}) {m.targets.length > 0 ? ` → ${m.targets.map((t) => `${t.name} (${t.type === "dns_provider" ? "DNS provider" : t.type})`).join(", ")}` : m.note ? ` — nothing to schedule: ${m.note}` : ""} {m.unmatched.length > 0 && · nothing here for {m.unmatched.join(", ")}} {m.unmatched.length > 0 && (
    Is one of those yours? Add its address under {t("Address aliases")} below, saying what it belongs to.
    )}
    Covers {m.monitorCount} monitor{m.monitorCount === 1 ? "" : "s"} in Uptime Kuma ·{" "} {m.slots.length === 0 ? t("Uptime Kuma gave no time slot") : m.slots.map((s) => `${formatDateTime(new Date(s.start))} – ${formatDateTime(new Date(s.end))}`).join("; ")}
  • ))}
)} {kumaError && (
{kumaError}
)} {kumaResult && (
{kumaResult.monitorsInMaintenance === 0 ? (
{kumaResult.monitorsChecked === 0 ? t("Uptime Kuma answered, but reported no monitors at all.") : `Read ${kumaResult.monitorsChecked} monitor${kumaResult.monitorsChecked === 1 ? "" : "s"} from Uptime Kuma; none is in maintenance right now.`}{" "} Only a maintenance window that is active at this moment can be imported — one scheduled for later shows up here once it starts.
) : (
{kumaResult.imported.length > 0 ? ( <> {kumaResult.imported.length} window{kumaResult.imported.length === 1 ? "" : "s"}{" "} {kumaResult.imported.every((i) => i.extended) ? "extended" : kumaResult.imported.every((i) => !i.extended) ? "started" : "started or extended"} : {kumaResult.imported.map((i) => `${i.serverName} (${i.extended ? "extended" : "started"})`).join(", ")}. ) : ( "None of the monitors currently in maintenance matched a server." )} {kumaResult.unmatched.length > 0 && (
{kumaResult.unmatched.length} monitor{kumaResult.unmatched.length === 1 ? "" : "s"} in maintenance {" "}couldn't be matched to a server: {kumaResult.unmatched.join(", ")}.
)}
)}
)}
{kumaIntegrationId === "" && ( {t("Every Uptime Kuma integration is disabled — enable one under Integrations.")} )}
)} {canEdit && kumaIntegrations && kumaIntegrations.length > 0 && (

{t("Address aliases")}

Uptime Kuma may watch something by a different address than the one you added it with here — a host added by its LAN address but monitored over Tailscale, for instance. An alias says that an address belongs to a server, integration or DNS provider, so the syncing above puts the maintenance window there. Matching stays exact: only the address you list counts.
setAliasAddress(e.target.value)} />
{aliasError && (
{aliasError}
)}
{aliases.length > 0 && (
{aliases.map((a) => ( ))}
{t("Address")} {t("Belongs to")} {t("Actions")}
{a.address} {a.targetName} · {a.targetKind}
)}
)} {upcoming.length > 0 && (

{t("Scheduled")}

{canEdit && } {upcoming.map((w) => ( {canEdit && ( )} ))}
{t("Target")} {t("Reason")} {t("Starts")} {t("Ends")}{t("Actions")}
{w.targetName} · {w.targetKind} {w.reason ?? "—"} in {formatRemaining(w.startedAt, now)} {formatDateTime(new Date(w.startedAt))} {formatDateTime(new Date(w.endsAt))}
Not silencing anything yet. These start by themselves; the schedule comes from Uptime Kuma and is refreshed every 15 minutes, so a cancelled one stays cancelled but a change in Uptime Kuma is followed.
)}

{t("Active")}

{canEdit && (windows?.length ?? 0) > 1 && ( )}
{canEdit && } {windows?.map((w) => ( {canEdit && ( )} ))} {windows === null && } {windows?.length === 0 && ( )}
{t("Target")} {t("Reason")} {t("Ends")} {t("Started by")}{t("Actions")}
{w.targetName} · {w.targetKind} {w.source?.startsWith("kuma:") && {t("Uptime Kuma")}} {w.reason ?? "—"} {formatRemaining(w.endsAt, now)} left {formatDateTime(new Date(w.endsAt))} {w.createdBy ?? "—"}

{t("What gets silenced")}

{t("Silenced for the target")}
  • {t("Server offline and disk-full alerts (for a server).")}
  • {t("Storage, volume and disk-health alerts (for a Proxmox or Synology integration).")}
  • {t("Backup-failure and uncovered-guest alerts (for a Proxmox integration).")}
  • {t("Backup-verification-failure alerts (for a Proxmox Backup Server integration).")}
  • {t("Failed-run alerts for the Semaphore or Gitea integration you choose.")}
  • "Integration down" alerts for that type of service — these are tracked per type (e.g. all Proxmox), not per instance, so with two Proxmox integrations a failure on the other one is silenced too while a window is open.
{t("Not silenced")}
  • {t("Secret and certificate expiry, Tailscale key expiry, Docker update reminders.")}
  • {t("DNS record change notifications.")}
{t("When a window ends")}
A problem that started during it and is still there alerts on the next check (within 15 minutes). One that was already alerted before it began and has since cleared is reported as cleared; one that started and cleared entirely inside the window is never reported.
); }