Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Add maintenance-window scheduler to the operator-overrides section

rcourtmanbfa7ba3b5831
diff --git a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
index 288a104fe0..893780d8c3 100644
--- a/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
+++ b/docs/release-control/v6/internal/subsystems/patrol-intelligence.md
@@ -1186,13 +1186,17 @@ The two boolean toggles (`IntentionallyOffline`,
Save/Discard actions; flipping `NeverAutoRemediate` true requires an
explicit confirmation prompt because it's a safety override that
locks the resource against all automated remediation, while flipping
-it false (releasing the lock) is permissive. Maintenance windows are
-displayed read-only this slice — when an active window covers `now`,
-the section badges it; scheduling lives in a separate slice that
-owns the date-picker UX. The section uses `createNonSuspendingQuery`
-rather than `createResource` so the drawer's parent Suspense
-boundary does not flicker the page-level fallback while operator
-state is in flight.
+it false (releasing the lock) is permissive. Maintenance windows have
+their own scheduler (HTML5 datetime-local inputs with 1h / 4h / 24h
+quick presets and a free-form reason field); the section
+distinguishes a future-scheduled window from one that currently covers
+`now` so the operator sees "scheduled" before the window opens,
+"active" while it covers now, and clean state once it ends. Scheduler
+saves preserve the toggle state and toggle saves preserve the window,
+so the two facets stay decoupled — editing one does not lose work on
+the other. The section uses `createNonSuspendingQuery` rather than
+`createResource` so the drawer's parent Suspense boundary does not
+flicker the page-level fallback while operator state is in flight.
The findings store also consumes per-resource operator-set state via
the narrow `ResourceOperatorStateProvider` interface installed by
diff --git a/frontend-modern/src/components/Infrastructure/ResourceOperatorStateSection.tsx b/frontend-modern/src/components/Infrastructure/ResourceOperatorStateSection.tsx
index b0cef411a9..8c011dafab 100644
--- a/frontend-modern/src/components/Infrastructure/ResourceOperatorStateSection.tsx
+++ b/frontend-modern/src/components/Infrastructure/ResourceOperatorStateSection.tsx
@@ -19,9 +19,8 @@ import { formatRelativeTime } from '@/utils/format';
* "X is offline" findings)
* - Lock the resource against automated remediation (action broker
* refuses dispatch with resource_remediation_locked:)
- * - See whether a maintenance window is currently active (read-only;
- * scheduling lives in a follow-up slice that owns the date-picker
- * UX)
+ * - Schedule a maintenance window during which all findings on the
+ * resource get auto-acknowledged with cause=maintenance_window
*
* The section stays compact and out of the way until the operator has
* something to say about the resource — fresh-install resources see a
@@ -64,6 +63,17 @@ export const ResourceOperatorStateSection: Component<ResourceOperatorStateSectio
const [saving, setSaving] = createSignal(false);
const [confirmingLock, setConfirmingLock] = createSignal(false);
+ // Maintenance-window scheduler state. The form is closed by default;
+ // `Schedule maintenance window` opens it pre-filled with sensible
+ // defaults (start = now, end = +1h). Datetime-local inputs use the
+ // browser's local timezone display but the API exchanges ISO 8601
+ // (UTC offset preserved) — formatLocalForInput / parseLocalFromInput
+ // handle the conversion.
+ const [schedulerOpen, setSchedulerOpen] = createSignal(false);
+ const [scheduleStart, setScheduleStart] = createSignal('');
+ const [scheduleEnd, setScheduleEnd] = createSignal('');
+ const [scheduleReason, setScheduleReason] = createSignal('');
+
// Hydrate edit state from persisted record on first load and on resource change.
createEffect(() => {
const current = persisted();
@@ -161,8 +171,9 @@ export const ResourceOperatorStateSection: Component<ResourceOperatorStateSectio
}
};
- // Maintenance window is read-only this slice. Compute whether one is
- // currently active so the section can badge it.
+ // Compute whether a maintenance window covers `now` so the section
+ // can badge it. Distinct from `scheduledMaintenanceWindow` — both
+ // active and future windows are surfaced, with different copy.
const activeMaintenanceWindow = createMemo(() => {
const current = persisted();
if (!current?.maintenanceStartAt || !current?.maintenanceEndAt) return null;
@@ -174,6 +185,136 @@ export const ResourceOperatorStateSection: Component<ResourceOperatorStateSectio
return current;
});
+ // Future-scheduled window — set but not yet started. The section
+ // surfaces this differently from an active window so the operator
+ // sees "scheduled" rather than "active".
+ const scheduledMaintenanceWindow = createMemo(() => {
+ const current = persisted();
+ if (!current?.maintenanceStartAt || !current?.maintenanceEndAt) return null;
+ const now = Date.now();
+ const start = Date.parse(current.maintenanceStartAt);
+ if (Number.isNaN(start)) return null;
+ if (start <= now) return null;
+ return current;
+ });
+
+ const hasAnyMaintenanceWindow = createMemo(
+ () => Boolean(activeMaintenanceWindow() || scheduledMaintenanceWindow()),
+ );
+
+ // Datetime-local input format is "YYYY-MM-DDTHH:mm" in the browser's
+ // local timezone. Both directions convert through Date so the API
+ // round-trip stays in ISO 8601 / UTC offset.
+ const formatLocalForInput = (date: Date): string => {
+ const pad = (n: number) => String(n).padStart(2, '0');
+ return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}`;
+ };
+
+ const parseLocalFromInput = (value: string): Date | null => {
+ if (!value) return null;
+ const parsed = new Date(value);
+ return Number.isNaN(parsed.getTime()) ? null : parsed;
+ };
+
+ const handleOpenScheduler = () => {
+ const now = new Date();
+ const oneHourFromNow = new Date(now.getTime() + 60 * 60 * 1000);
+ const current = persisted();
+ // Pre-fill from the persisted window when one exists; otherwise
+ // default to "starting now, ending in one hour" — the most common
+ // shape for a quick maintenance.
+ if (current?.maintenanceStartAt && current?.maintenanceEndAt) {
+ const start = new Date(current.maintenanceStartAt);
+ const end = new Date(current.maintenanceEndAt);
+ if (!Number.isNaN(start.getTime())) setScheduleStart(formatLocalForInput(start));
+ if (!Number.isNaN(end.getTime())) setScheduleEnd(formatLocalForInput(end));
+ setScheduleReason(current.maintenanceReason ?? '');
+ } else {
+ setScheduleStart(formatLocalForInput(now));
+ setScheduleEnd(formatLocalForInput(oneHourFromNow));
+ setScheduleReason('');
+ }
+ setSchedulerOpen(true);
+ };
+
+ const applyPresetDuration = (hoursFromStart: number) => {
+ const start = parseLocalFromInput(scheduleStart()) ?? new Date();
+ const end = new Date(start.getTime() + hoursFromStart * 60 * 60 * 1000);
+ setScheduleEnd(formatLocalForInput(end));
+ };
+
+ const scheduleValidationError = createMemo(() => {
+ const start = parseLocalFromInput(scheduleStart());
+ const end = parseLocalFromInput(scheduleEnd());
+ if (!start || !end) return 'Both start and end are required.';
+ if (end.getTime() <= start.getTime()) return 'End must be after start.';
+ return null;
+ });
+
+ const handleScheduleSave = async () => {
+ const start = parseLocalFromInput(scheduleStart());
+ const end = parseLocalFromInput(scheduleEnd());
+ if (!start || !end) {
+ notificationStore.error('Both start and end are required.');
+ return;
+ }
+ if (end.getTime() <= start.getTime()) {
+ notificationStore.error('Maintenance end must be strictly after start.');
+ return;
+ }
+ setSaving(true);
+ try {
+ const current = persisted();
+ const input: ResourceOperatorStateInput = {
+ // Keep the toggle state intact when scheduling — operator
+ // editing one facet must not lose work on the other.
+ intentionallyOffline: intentionallyOffline(),
+ neverAutoRemediate: neverAutoRemediate(),
+ maintenanceStartAt: start.toISOString(),
+ maintenanceEndAt: end.toISOString(),
+ maintenanceReason: scheduleReason().trim() || undefined,
+ criticality: current?.criticality,
+ note: current?.note,
+ };
+ await setResourceOperatorState(props.resourceId, input);
+ await query.refetch();
+ setSchedulerOpen(false);
+ notificationStore.success('Maintenance window saved');
+ } catch (err) {
+ notificationStore.error(
+ err instanceof Error ? err.message : 'Failed to save maintenance window',
+ );
+ } finally {
+ setSaving(false);
+ }
+ };
+
+ const handleClearMaintenanceWindow = async () => {
+ setSaving(true);
+ try {
+ const current = persisted();
+ const input: ResourceOperatorStateInput = {
+ intentionallyOffline: intentionallyOffline(),
+ neverAutoRemediate: neverAutoRemediate(),
+ maintenanceStartAt: undefined,
+ maintenanceEndAt: undefined,
+ maintenanceReason: undefined,
+ criticality: current?.criticality,
+ note: current?.note,
+ };
+ await setResourceOperatorState(props.resourceId, input);
+ await query.refetch();
+ setSchedulerOpen(false);
+ notificationStore.success('Maintenance window cleared');
+ } catch (err) {
+ notificationStore.error(
+ err instanceof Error ? err.message : 'Failed to clear maintenance window',
+ );
+ } finally {
+ setSaving(false);
+ }
+ };
+
return (
<section class="rounded-md border border-border bg-surface p-4 space-y-3" aria-label="Operator overrides">
<header class="flex items-center justify-between">
@@ -207,6 +348,159 @@ export const ResourceOperatorStateSection: Component<ResourceOperatorStateSectio
</div>
</Show>
+ <Show when={scheduledMaintenanceWindow() && !activeMaintenanceWindow()}>
+ <div class="rounded border border-blue-200 bg-blue-50 px-3 py-2 text-xs text-blue-800 dark:border-blue-800 dark:bg-blue-900 dark:text-blue-200">
+ <span class="font-semibold">Maintenance window scheduled.</span>{' '}
+ Auto-acknowledgement will start{' '}
+ {formatRelativeTime(scheduledMaintenanceWindow()!.maintenanceStartAt!, { compact: true })}{' '}
+ and end{' '}
+ {formatRelativeTime(scheduledMaintenanceWindow()!.maintenanceEndAt!, { compact: true })}.
+ <Show when={scheduledMaintenanceWindow()!.maintenanceReason}>
+ <span class="block mt-0.5">Reason: {scheduledMaintenanceWindow()!.maintenanceReason}</span>
+ </Show>
+ </div>
+ </Show>
+
+ {/* Maintenance window scheduler. The form is closed by default;
+ opening it pre-fills with sensible defaults (start = now, end
+ = +1h) or with the persisted window when one exists. */}
+ <Show when={!schedulerOpen()}>
+ <div class="flex items-center justify-between gap-3 pt-2 border-t border-border-subtle">
+ <div class="flex-1">
+ <label class="text-sm font-medium text-base-content">Maintenance window</label>
+ <p class="text-[11px] text-muted mt-0.5 leading-tight">
+ Suspend findings on this resource for a defined window. Useful for scheduled
+ upgrades, planned downtime, or reboots where Pulse should stay quiet until the
+ window closes.
+ </p>
+ </div>
+ <Show
+ when={hasAnyMaintenanceWindow()}
+ fallback={
+ <button
+ type="button"
+ onClick={handleOpenScheduler}
+ disabled={saving()}
+ class="px-2.5 py-1 text-xs font-medium text-base-content border border-border rounded hover:bg-surface-hover disabled:opacity-50"
+ >
+ Schedule window
+ </button>
+ }
+ >
+ <div class="flex items-center gap-2">
+ <button
+ type="button"
+ onClick={handleOpenScheduler}
+ disabled={saving()}
+ class="px-2.5 py-1 text-xs font-medium text-base-content border border-border rounded hover:bg-surface-hover disabled:opacity-50"
+ >
+ Edit window
+ </button>
+ <button
+ type="button"
+ onClick={handleClearMaintenanceWindow}
+ disabled={saving()}
+ class="px-2.5 py-1 text-xs font-medium text-amber-700 border border-amber-200 rounded hover:bg-amber-50 dark:text-amber-300 dark:border-amber-800 dark:hover:bg-amber-900 disabled:opacity-50"
+ >
+ Cancel window
+ </button>
+ </div>
+ </Show>
+ </div>
+ </Show>
+
+ <Show when={schedulerOpen()}>
+ <div class="rounded border border-border bg-surface-alt/40 px-3 py-3 space-y-2">
+ <div class="text-xs font-semibold text-base-content">Schedule maintenance window</div>
+ <div class="grid grid-cols-1 sm:grid-cols-2 gap-2">
+ <label class="block">
+ <span class="text-[11px] text-muted">Start</span>
+ <input
+ type="datetime-local"
+ value={scheduleStart()}
+ onInput={(e) => setScheduleStart(e.currentTarget.value)}
+ class="mt-0.5 w-full text-xs rounded border border-border bg-surface px-2 py-1 text-base-content focus:outline-none focus:ring-1 focus:ring-blue-400"
+ disabled={saving()}
+ />
+ </label>
+ <label class="block">
+ <span class="text-[11px] text-muted">End</span>
+ <input
+ type="datetime-local"
+ value={scheduleEnd()}
+ onInput={(e) => setScheduleEnd(e.currentTarget.value)}
+ class="mt-0.5 w-full text-xs rounded border border-border bg-surface px-2 py-1 text-base-content focus:outline-none focus:ring-1 focus:ring-blue-400"
+ disabled={saving()}
+ />
+ </label>
+ </div>
+
+ <div class="flex items-center gap-1 text-[11px]">
+ <span class="text-muted">Quick presets:</span>
+ <button
+ type="button"
+ onClick={() => applyPresetDuration(1)}
+ disabled={saving()}
+ class="px-1.5 py-0.5 rounded border border-border hover:bg-surface-hover disabled:opacity-50"
+ >
+ 1h
+ </button>
+ <button
+ type="button"
+ onClick={() => applyPresetDuration(4)}
+ disabled={saving()}
+ class="px-1.5 py-0.5 rounded border border-border hover:bg-surface-hover disabled:opacity-50"
+ >
+ 4h
+ </button>
+ <button
+ type="button"
+ onClick={() => applyPresetDuration(24)}
+ disabled={saving()}
+ class="px-1.5 py-0.5 rounded border border-border hover:bg-surface-hover disabled:opacity-50"
+ >
+ 24h
+ </button>
+ </div>
+
+ <label class="block">
+ <span class="text-[11px] text-muted">Reason (optional)</span>
+ <input
+ type="text"
+ value={scheduleReason()}
+ onInput={(e) => setScheduleReason(e.currentTarget.value)}
+ placeholder="e.g. Q3 storage upgrade, kernel patch reboot"
+ class="mt-0.5 w-full text-xs rounded border border-border bg-surface px-2 py-1 text-base-content focus:outline-none focus:ring-1 focus:ring-blue-400"
+ disabled={saving()}
+ maxLength={200}
+ />
+ </label>
+
+ <Show when={scheduleValidationError()}>
+ <p class="text-[11px] text-red-700 dark:text-red-400">{scheduleValidationError()}</p>
+ </Show>
+
+ <div class="flex items-center justify-end gap-2 pt-1">
+ <button
+ type="button"
+ onClick={() => setSchedulerOpen(false)}
+ disabled={saving()}
+ class="px-2.5 py-1 text-xs font-medium text-muted hover:bg-surface-hover rounded transition-colors disabled:opacity-50"
+ >
+ Cancel
+ </button>
+ <button
+ type="button"
+ onClick={handleScheduleSave}
+ disabled={saving() || Boolean(scheduleValidationError())}
+ class="px-2.5 py-1 text-xs font-medium text-white bg-blue-600 hover:bg-blue-700 disabled:bg-blue-400 rounded transition-colors"
+ >
+ {saving() ? 'Saving…' : 'Save window'}
+ </button>
+ </div>
+ </div>
+ </Show>
+
<div class="flex items-start justify-between gap-3">
<div class="flex-1">
<label class="text-sm font-medium text-base-content">Intentionally offline</label>
diff --git a/frontend-modern/src/components/Infrastructure/__tests__/ResourceOperatorStateSection.test.ts b/frontend-modern/src/components/Infrastructure/__tests__/ResourceOperatorStateSection.test.ts
index 4ba0b5dce3..1c457b6481 100644
--- a/frontend-modern/src/components/Infrastructure/__tests__/ResourceOperatorStateSection.test.ts
+++ b/frontend-modern/src/components/Infrastructure/__tests__/ResourceOperatorStateSection.test.ts
@@ -49,12 +49,11 @@ describe('ResourceOperatorStateSection', () => {
expect(sectionSource).toContain('if (next && !neverAutoRemediate())');
});
- it('preserves persisted maintenance-window data on save so the toggle slice does not clobber the window slice', () => {
- // This slice owns toggles only; the maintenance-window scheduler
- // lands separately. If save sent only the toggle fields the server
- // would null out the window data on every save (PUT replaces). Pin
- // that the input passed to setResourceOperatorState carries the
- // current window fields through.
+ it('preserves persisted maintenance-window data on toggle save so the two facets stay decoupled', () => {
+ // Toggling intentionallyOffline or neverAutoRemediate must not
+ // clobber a persisted maintenance window. The toggle save path
+ // reads the current persisted window fields and forwards them
+ // through the PUT body (which replaces the whole record).
expect(sectionSource).toContain('maintenanceStartAt: current?.maintenanceStartAt');
expect(sectionSource).toContain('maintenanceEndAt: current?.maintenanceEndAt');
expect(sectionSource).toContain('maintenanceReason: current?.maintenanceReason');
@@ -62,13 +61,67 @@ describe('ResourceOperatorStateSection', () => {
expect(sectionSource).toContain('note: current?.note');
});
+ it('exposes a maintenance-window scheduler with HTML5 datetime-local inputs and quick presets', () => {
+ // The scheduler is the operator's path to setting a maintenance
+ // window without curling the API. Pin the wiring: datetime-local
+ // inputs, validation that end > start, optional reason field, and
+ // 1h/4h/24h quick presets.
+ expect(sectionSource).toContain('schedulerOpen');
+ expect(sectionSource).toContain('handleScheduleSave');
+ expect(sectionSource).toContain('handleClearMaintenanceWindow');
+ expect(sectionSource).toContain('applyPresetDuration');
+ expect(sectionSource).toContain('type="datetime-local"');
+ expect(sectionSource).toContain('scheduleValidationError');
+ // Quick presets — the three most common operator durations.
+ expect(sectionSource).toContain('applyPresetDuration(1)');
+ expect(sectionSource).toContain('applyPresetDuration(4)');
+ expect(sectionSource).toContain('applyPresetDuration(24)');
+ // Both directions of the datetime conversion live in helpers so the
+ // scheduler stays free of inline date arithmetic.
+ expect(sectionSource).toContain('formatLocalForInput');
+ expect(sectionSource).toContain('parseLocalFromInput');
+ });
+
+ it('validates client-side that the scheduled end is strictly after start', () => {
+ // The server validates the same constraint and returns 400 with
+ // operator_state_invalid; pinning client-side validation keeps the
+ // operator out of an avoidable round-trip. The Save button is gated
+ // on the validation memo so a stale form state cannot be submitted.
+ expect(sectionSource).toContain('End must be after start.');
+ expect(sectionSource).toContain('disabled={saving() || Boolean(scheduleValidationError())}');
+ });
+
+ it('distinguishes a future-scheduled window from an active one in the badge surface', () => {
+ // Active: now is within [start, end). Future-scheduled: start > now.
+ // Each surfaces a distinct badge so operators see "scheduled"
+ // before the window opens, "active" while it covers now, and
+ // nothing once it ends.
+ expect(sectionSource).toContain('scheduledMaintenanceWindow');
+ expect(sectionSource).toContain('Maintenance window scheduled.');
+ expect(sectionSource).toContain('Auto-acknowledgement will start');
+ });
+
+ it('exposes Edit window and Cancel window controls when a window exists', () => {
+ // The compact view (form closed) must offer both editing the
+ // window and clearing it without reopening the form. Cancel
+ // window must clear ONLY the window fields, preserving the
+ // toggles.
+ expect(sectionSource).toContain('Schedule window');
+ expect(sectionSource).toContain('Edit window');
+ expect(sectionSource).toContain('Cancel window');
+ // handleClearMaintenanceWindow must preserve toggles by reading
+ // the current edit-state signals rather than nulling everything.
+ expect(sectionSource).toContain('intentionallyOffline: intentionallyOffline()');
+ expect(sectionSource).toContain('neverAutoRemediate: neverAutoRemediate()');
+ expect(sectionSource).toContain('maintenanceStartAt: undefined,');
+ expect(sectionSource).toContain('maintenanceEndAt: undefined,');
+ });
+
it('renders a maintenance-window-active badge when the persisted window covers now', () => {
- // Read-only display of the active window so operators see "this is
- // why findings are quiet right now" without being able to schedule
- // one yet (scheduler is a follow-up slice). The section must gate
- // the badge on the now-falls-within-window check, not just on the
- // presence of a window — a future-scheduled window should not show
- // as active.
+ // The section must gate the active badge on the
+ // now-falls-within-window check, not just on the presence of a
+ // window — a future-scheduled window surfaces under a separate
+ // "scheduled" badge instead.
expect(sectionSource).toContain('activeMaintenanceWindow');
expect(sectionSource).toContain('Maintenance window active.');
expect(sectionSource).toContain('if (now < start || now >= end) return null;');