import { useEffect, useState } from "react"; import { api, type AppSettings, type GotifySettings, type NtfySettings, type SmtpSettings, type WebhookSettings, type NotificationEvents, type DigestSettings, type QuietHoursSettings, type HealthCheckSettings, } from "../../api/client"; import { readableError } from "../../utils/errors"; import { ErrorNotice } from "../../components/Notice"; import { PageSkeleton } from "../../components/Skeleton"; const TIMEZONES = [ "UTC", "Europe/Stockholm", "Europe/London", "Europe/Berlin", "Europe/Paris", "Europe/Oslo", "Europe/Helsinki", "Europe/Amsterdam", "Europe/Copenhagen", "America/New_York", "America/Chicago", "America/Denver", "America/Los_Angeles", "America/Toronto", "America/Sao_Paulo", "Asia/Tokyo", "Asia/Shanghai", "Asia/Singapore", "Asia/Dubai", "Australia/Sydney", ]; const DEFAULT_GOTIFY: GotifySettings = { enabled: false, url: "", token: "", priority: 5 }; const DEFAULT_NTFY: NtfySettings = { enabled: false, url: "https://ntfy.sh", topic: "", token: "", priority: 3 }; const DEFAULT_SMTP: SmtpSettings = { enabled: false, host: "", port: 587, secure: false, username: "", password: "", from: "", to: "" }; const DEFAULT_WEBHOOK: WebhookSettings = { enabled: false, url: "", secret: "" }; const DEFAULT_NOTIFICATIONS: NotificationEvents = { dnsAdd: true, dnsUpdate: true, dnsDelete: true, secretCheck: true, tailscaleKeyCheck: true, dockerUpdateCheck: true, proxmoxBackupCheck: true, pbsVerificationCheck: true, healthAlerts: true, automationAlerts: true, domainExpiryCheck: true, secretCheckTime: "08:00", timezone: "UTC", integrationFailureAlerts: true, integrationFailureThreshold: 3, }; const DEFAULT_QUIET_HOURS: QuietHoursSettings = { enabled: false, start: "22:00", end: "07:00" }; const DEFAULT_DIGEST: DigestSettings = { enabled: false, day: 1, time: "08:00" }; // Monday first, as a week reads; the numbers are what the server keeps (0 = Sunday). const DIGEST_DAYS: { value: number; label: string }[] = [ { value: 1, label: "Monday" }, { value: 2, label: "Tuesday" }, { value: 3, label: "Wednesday" }, { value: 4, label: "Thursday" }, { value: 5, label: "Friday" }, { value: 6, label: "Saturday" }, { value: 0, label: "Sunday" }, ]; const DEFAULT_HEALTH_CHECKS: HealthCheckSettings = { serverOfflineMinutes: 60, diskUsagePercent: 90, domainWarnDays: 30, diskForecastDays: 14 }; type TestResult = { ok: boolean; message: string } | null; function TestBadge({ result }: { result: TestResult }) { if (!result) return null; return (
{result.ok ? "✓" : "✕"} {result.message}
); } export default function NotificationSettings() { const [loading, setLoading] = useState(true); const [loadError, setLoadError] = useState(null); const [saving, setSaving] = useState(false); const [saved, setSaved] = useState(false); const [saveError, setSaveError] = useState(null); const [gotify, setGotify] = useState(DEFAULT_GOTIFY); const [ntfy, setNtfy] = useState(DEFAULT_NTFY); const [smtp, setSmtp] = useState(DEFAULT_SMTP); const [webhook, setWebhook] = useState(DEFAULT_WEBHOOK); const [notifications, setNotifications] = useState(DEFAULT_NOTIFICATIONS); const [quietHours, setQuietHours] = useState(DEFAULT_QUIET_HOURS); const [healthChecks, setHealthChecks] = useState(DEFAULT_HEALTH_CHECKS); const [digest, setDigest] = useState(DEFAULT_DIGEST); const [digestPreview, setDigestPreview] = useState<{ title: string; message: string } | null>(null); const [digestBusy, setDigestBusy] = useState<"preview" | "send" | null>(null); const [digestResult, setDigestResult] = useState(null); const [queuedCount, setQueuedCount] = useState(null); const [flushing, setFlushing] = useState(false); const [flushResult, setFlushResult] = useState(null); const [testingGotify, setTestingGotify] = useState(false); const [testGotifyResult, setTestGotifyResult] = useState(null); const [testingNtfy, setTestingNtfy] = useState(false); const [testNtfyResult, setTestNtfyResult] = useState(null); const [testingSmtp, setTestingSmtp] = useState(false); const [testSmtpResult, setTestSmtpResult] = useState(null); const [testingWebhook, setTestingWebhook] = useState(false); const [testWebhookResult, setTestWebhookResult] = useState(null); useEffect(() => { api.settings .get() .then((res: { settings: AppSettings }) => { setGotify(res.settings.gotify); setNtfy(res.settings.ntfy); setSmtp(res.settings.smtp); setWebhook(res.settings.webhook); setNotifications(res.settings.notifications); setQuietHours(res.settings.quietHours); setHealthChecks(res.settings.healthChecks); setDigest(res.settings.digest ?? DEFAULT_DIGEST); }) .catch((err) => setLoadError(err instanceof Error ? err.message : String(err))) .finally(() => setLoading(false)); api.settings .quietHoursQueue() .then((res) => setQueuedCount(res.count)) .catch(() => {}); }, []); async function handleSave() { setSaving(true); setSaveError(null); setSaved(false); try { await api.settings.update({ gotify, ntfy, smtp, webhook, notifications, quietHours, healthChecks, digest }); setSaved(true); setTimeout(() => setSaved(false), 3000); } catch (err) { setSaveError(err instanceof Error ? err.message : String(err)); } finally { setSaving(false); } } async function handleDigestPreview() { setDigestBusy("preview"); setDigestResult(null); try { const res = await api.settings.digestPreview(); setDigestPreview({ title: res.title, message: res.message }); } catch (err) { setDigestResult({ ok: false, message: err instanceof Error ? err.message : String(err) }); } finally { setDigestBusy(null); } } async function handleDigestSend() { setDigestBusy("send"); setDigestResult(null); try { const res = await api.settings.digestSend(); setDigestResult({ ok: true, message: `Sent through ${res.channels} channel${res.channels === 1 ? "" : "s"}.` }); } catch (err) { setDigestResult({ ok: false, message: readableError(err) }); } finally { setDigestBusy(null); } } async function handleFlushNow() { setFlushing(true); setFlushResult(null); try { const res = await api.settings.flushQuietHours(); setFlushResult(res.flushed > 0 ? `Sent a digest of ${res.flushed} queued notification${res.flushed !== 1 ? "s" : ""}.` : "Nothing was queued."); setQueuedCount(0); } catch (err) { setFlushResult(err instanceof Error ? err.message : String(err)); } finally { setFlushing(false); } } async function handleTestGotify() { setTestingGotify(true); setTestGotifyResult(null); try { await api.settings.testGotify(gotify); setTestGotifyResult({ ok: true, message: "Notification sent successfully." }); } catch (err) { setTestGotifyResult({ ok: false, message: err instanceof Error ? err.message : String(err) }); } finally { setTestingGotify(false); } } async function handleTestNtfy() { setTestingNtfy(true); setTestNtfyResult(null); try { await api.settings.testNtfy(ntfy); setTestNtfyResult({ ok: true, message: "Notification sent successfully." }); } catch (err) { setTestNtfyResult({ ok: false, message: err instanceof Error ? err.message : String(err) }); } finally { setTestingNtfy(false); } } async function handleTestSmtp() { setTestingSmtp(true); setTestSmtpResult(null); try { await api.settings.testSmtp(smtp); setTestSmtpResult({ ok: true, message: "Test email sent successfully." }); } catch (err) { setTestSmtpResult({ ok: false, message: err instanceof Error ? err.message : String(err) }); } finally { setTestingSmtp(false); } } async function handleTestWebhook() { setTestingWebhook(true); setTestWebhookResult(null); try { await api.settings.testWebhook(webhook); setTestWebhookResult({ ok: true, message: "Webhook delivered successfully." }); } catch (err) { setTestWebhookResult({ ok: false, message: err instanceof Error ? err.message : String(err) }); } finally { setTestingWebhook(false); } } if (loading) return ; return ( <>

Notifications

{saveError && {saveError}} {saved && ✓ Settings saved}

Gotify

Send push notifications to a self-hosted Gotify instance.

setGotify((g) => ({ ...g, url: e.target.value }))} />
setGotify((g) => ({ ...g, token: e.target.value }))} />
setGotify((g) => ({ ...g, priority: Number(e.target.value) }))} />

ntfy

Send notifications via ntfy.sh or a self-hosted instance.

setNtfy((n) => ({ ...n, url: e.target.value }))} />
setNtfy((n) => ({ ...n, priority: Number(e.target.value) }))} />
setNtfy((n) => ({ ...n, topic: e.target.value }))} />
setNtfy((n) => ({ ...n, token: e.target.value }))} />

Email (SMTP)

Send notifications via email using any SMTP server.

setSmtp((s) => ({ ...s, host: e.target.value }))} />
setSmtp((s) => ({ ...s, port: Number(e.target.value) }))} />
setSmtp((s) => ({ ...s, username: e.target.value }))} />
setSmtp((s) => ({ ...s, password: e.target.value }))} />
setSmtp((s) => ({ ...s, from: e.target.value }))} />
setSmtp((s) => ({ ...s, to: e.target.value }))} />

Webhook

POST a JSON payload to any HTTP endpoint. Uses Discord/Slack-compatible {"{ \"content\": \"…\" }"} format.

setWebhook((w) => ({ ...w, url: e.target.value }))} />
setWebhook((w) => ({ ...w, secret: e.target.value }))} />

Notify on

Controls which events trigger a notification on every enabled channel above.

{[ { key: "dnsAdd" as const, label: "DNS record added" }, { key: "dnsUpdate" as const, label: "DNS record updated" }, { key: "dnsDelete" as const, label: "DNS record deleted" }, { key: "secretCheck" as const, label: "Secret expiry reminder" }, { key: "tailscaleKeyCheck" as const, label: "Tailscale key expiry reminder" }, { key: "dockerUpdateCheck" as const, label: "Docker image update available" }, { key: "proxmoxBackupCheck" as const, label: "Proxmox backup failed or a guest has no coverage" }, { key: "pbsVerificationCheck" as const, label: "Proxmox Backup Server snapshot failed verification" }, { key: "healthAlerts" as const, label: "Server offline, disk nearly full, or Synology volume/disk problem" }, { key: "domainExpiryCheck" as const, label: "Domain registration expiring or expired (daily reminder)" }, { key: "automationAlerts" as const, label: "Semaphore template or Gitea workflow run failed" }, { key: "integrationFailureAlerts" as const, label: "Integration/DNS provider failing repeatedly" }, ].map(({ key, label }) => ( ))}
setNotifications((n) => ({ ...n, integrationFailureThreshold: Number(e.target.value) }))} /> consecutive failures
Based on the Diagnostic Log. A recovery notice is sent once it succeeds again.
setHealthChecks((h) => ({ ...h, serverOfflineMinutes: Number(e.target.value) }))} /> min
Agents report every 15 min by default.
setHealthChecks((h) => ({ ...h, diskUsagePercent: Number(e.target.value) }))} /> %
Servers, Proxmox storage, Synology volumes. Checked every 15 min; a recovery notice follows.
setHealthChecks((h) => ({ ...h, diskForecastDays: Number(e.target.value) }))} /> days
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.
setHealthChecks((h) => ({ ...h, domainWarnDays: Number(e.target.value) }))} /> days before
Reminded daily from then until it's renewed.
{(() => { const dailyChecksEnabled = notifications.secretCheck || notifications.tailscaleKeyCheck || notifications.dockerUpdateCheck || notifications.proxmoxBackupCheck || notifications.pbsVerificationCheck || notifications.domainExpiryCheck; return (
setNotifications((n) => ({ ...n, secretCheckTime: e.target.value }))} />
Shared by the secret, Tailscale key, Docker update, Proxmox backup, Proxmox Backup Server, and domain expiry reminders above.
); })()}

Quiet hours

Notifications that fire during this window are held instead of sent immediately, then delivered as one digest at the end time (in the timezone set above). Scheduled daily reminders already only fire once at a time you pick, so this mainly affects instant ones — DNS changes and integration failure/recovery alerts.

setQuietHours((q) => ({ ...q, start: e.target.value }))} />
setQuietHours((q) => ({ ...q, end: e.target.value }))} />
A start time later than the end time (e.g. 22:00 → 07:00) is treated as spanning midnight.
{queuedCount !== null && queuedCount > 0 && (
{queuedCount} notification{queuedCount !== 1 ? "s" : ""} currently queued.
)} {flushResult &&
{flushResult}
}

Weekly digest

One message a week through the channels above, in the time zone set above: what is wrong now, what was down and for how long, what happened, disks heading for full, things about to expire, updates waiting and maintenance coming up. A topic with nothing to say is left out, and a quiet week says so in one line. Quiet hours hold it like any other notification.

setDigest((d) => ({ ...d, time: e.target.value }))} />
Settings above are saved with the Save button; the preview and "send it now" don't depend on them.
{digestPreview && (
{digestPreview.title}
                    {digestPreview.message}
                  
)}
); }