Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions apps/web/src/pages/Alerts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -36,7 +54,7 @@ const Alerts = () => {
const [ruleForm, setRuleForm] = useState({
name: "",
alertType: "cpu" as "cpu" | "memory" | "disk" | "upstream" | "ssl",
condition: "",
condition: getConditionForAlertType("cpu"),
threshold: 80,
severity: "warning" as "critical" | "warning" | "info",
channels: [] as string[],
Expand Down Expand Up @@ -145,7 +163,7 @@ const Alerts = () => {
setRuleForm({
name: "",
alertType: "cpu",
condition: "",
condition: getConditionForAlertType("cpu"),
threshold: 80,
severity: "warning",
channels: [],
Expand All @@ -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";
Expand All @@ -197,7 +209,7 @@ const Alerts = () => {
setRuleForm({
...ruleForm,
alertType: type,
condition,
condition: getConditionForAlertType(type),
threshold,
checkInterval,
name: ruleForm.name || name
Expand Down