diff --git a/app/alerts/page.tsx b/app/alerts/page.tsx index 0dca775..78ccaaf 100644 --- a/app/alerts/page.tsx +++ b/app/alerts/page.tsx @@ -49,7 +49,14 @@ export default function AlertsPage() { const [checking, setChecking] = useState(false); const [checkResults, setCheckResults] = useState([]); const [lastCheckTime, setLastCheckTime] = useState(""); - const [checkInterval, setCheckInterval] = useState(10); // 默认 10 分钟检查一次 + const [checkInterval, setCheckInterval] = useState(10); + + // 从配置加载 checkInterval + useEffect(() => { + if (config?.checkInterval) { + setCheckInterval(config.checkInterval); + } + }, [config?.checkInterval]); const ruleDescriptions = RULE_DESCRIPTIONS[locale as keyof typeof RULE_DESCRIPTIONS] || RULE_DESCRIPTIONS.zh; @@ -138,6 +145,24 @@ export default function AlertsPage() { .finally(() => setSaving(false)); }; + const handleIntervalChange = (value: number) => { + if (!config) return; + setCheckInterval(value); + setSaving(true); + fetch("/api/alerts", { + method: "PUT", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ checkInterval: value }), + }) + .then((r) => r.json()) + .then((newConfig) => { + setConfig(newConfig); + setSaved(true); + setTimeout(() => setSaved(false), 2000); + }) + .finally(() => setSaving(false)); + }; + const handleRuleToggle = (ruleId: string) => { if (!config) return; const rules = config.rules.map((r) => @@ -212,13 +237,16 @@ export default function AlertsPage() { {t("alerts.checkInterval") || "Check Interval"}: )} diff --git a/app/api/alerts/route.ts b/app/api/alerts/route.ts index ae25055..16222cf 100644 --- a/app/api/alerts/route.ts +++ b/app/api/alerts/route.ts @@ -16,6 +16,7 @@ interface AlertRule { interface AlertConfig { enabled: boolean; receiveAgent: string; // 接收告警的 agent ID + checkInterval: number; // 检查间隔(分钟) rules: AlertRule[]; lastAlerts?: Record; // 上次告警时间戳 } @@ -37,6 +38,7 @@ function getAlertConfig(): AlertConfig { return { enabled: false, receiveAgent: "main", + checkInterval: 10, rules: DEFAULT_RULES, lastAlerts: {}, }; @@ -76,6 +78,7 @@ export async function PUT(request: Request) { if (body.enabled !== undefined) config.enabled = body.enabled; if (body.receiveAgent) config.receiveAgent = body.receiveAgent; + if (body.checkInterval !== undefined) config.checkInterval = body.checkInterval; if (body.rules) { // 合并规则配置 for (const newRule of body.rules) {