From 756ce76eb8a8abd0cdfd6c5c7039884eefd0c5e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=E1=BA=A1nh=20T=C6=B0=E1=BB=9Dng=20Solo?= Date: Fri, 3 Oct 2025 13:47:13 +0700 Subject: [PATCH 1/2] fix: set default condition for alert rules to "cpu > threshold" --- apps/web/src/pages/Alerts.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/web/src/pages/Alerts.tsx b/apps/web/src/pages/Alerts.tsx index 9bb7270..096f571 100644 --- a/apps/web/src/pages/Alerts.tsx +++ b/apps/web/src/pages/Alerts.tsx @@ -36,7 +36,7 @@ const Alerts = () => { const [ruleForm, setRuleForm] = useState({ name: "", alertType: "cpu" as "cpu" | "memory" | "disk" | "upstream" | "ssl", - condition: "", + condition: "cpu > threshold", threshold: 80, severity: "warning" as "critical" | "warning" | "info", channels: [] as string[], @@ -145,7 +145,7 @@ const Alerts = () => { setRuleForm({ name: "", alertType: "cpu", - condition: "", + condition: "cpu > threshold", threshold: 80, severity: "warning", channels: [], From d0ce50be2ebab4f8ccc7c12f56ed202d765172c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=E1=BA=A1nh=20T=C6=B0=E1=BB=9Dng=20Solo?= Date: Fri, 3 Oct 2025 14:01:10 +0700 Subject: [PATCH 2/2] feat: enhance alert condition generation for various alert types --- apps/web/src/pages/Alerts.tsx | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/apps/web/src/pages/Alerts.tsx b/apps/web/src/pages/Alerts.tsx index 096f571..12e7c48 100644 --- a/apps/web/src/pages/Alerts.tsx +++ b/apps/web/src/pages/Alerts.tsx @@ -24,6 +24,24 @@ const Alerts = () => { const [isRuleDialogOpen, setIsRuleDialogOpen] = useState(false); const [loading, setLoading] = useState(false); + // Helper function to generate condition based on alert type + const getConditionForAlertType = (alertType: "cpu" | "memory" | "disk" | "upstream" | "ssl"): string => { + switch (alertType) { + case "cpu": + return "cpu > threshold"; + case "memory": + return "memory > threshold"; + case "disk": + return "disk > threshold"; + case "upstream": + return "upstream_status == down"; + case "ssl": + return "ssl_days_remaining < threshold"; + default: + return "cpu > threshold"; + } + }; + const [channelForm, setChannelForm] = useState({ name: "", type: "email" as "email" | "telegram", @@ -36,7 +54,7 @@ const Alerts = () => { const [ruleForm, setRuleForm] = useState({ name: "", alertType: "cpu" as "cpu" | "memory" | "disk" | "upstream" | "ssl", - condition: "cpu > threshold", + condition: getConditionForAlertType("cpu"), threshold: 80, severity: "warning" as "critical" | "warning" | "info", channels: [] as string[], @@ -145,7 +163,7 @@ const Alerts = () => { setRuleForm({ name: "", alertType: "cpu", - condition: "cpu > threshold", + condition: getConditionForAlertType("cpu"), threshold: 80, severity: "warning", channels: [], @@ -156,38 +174,32 @@ const Alerts = () => { // Update condition and defaults based on alert type const handleAlertTypeChange = (type: "cpu" | "memory" | "disk" | "upstream" | "ssl") => { - let condition = ""; let threshold = 80; let checkInterval = 60; let name = ""; switch (type) { case "cpu": - condition = "cpu > threshold"; threshold = 80; checkInterval = 30; name = "High CPU Usage"; break; case "memory": - condition = "memory > threshold"; threshold = 85; checkInterval = 30; name = "High Memory Usage"; break; case "disk": - condition = "disk > threshold"; threshold = 90; checkInterval = 300; // 5 minutes name = "High Disk Usage"; break; case "upstream": - condition = "upstream_status == down"; threshold = 1; checkInterval = 60; name = "Upstream Down"; break; case "ssl": - condition = "ssl_days_remaining < threshold"; threshold = 30; checkInterval = 86400; // 1 day name = "SSL Certificate Expiring"; @@ -197,7 +209,7 @@ const Alerts = () => { setRuleForm({ ...ruleForm, alertType: type, - condition, + condition: getConditionForAlertType(type), threshold, checkInterval, name: ruleForm.name || name