Skip to content
Open
Show file tree
Hide file tree
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
23 changes: 21 additions & 2 deletions client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions client/src/Hooks/useMonitorForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ const getBaseDefaults = (data?: Monitor | null) => ({
description: data?.description || "",
interval: data?.interval || 60000,
notifications: data?.notifications || [],
escalationNotifications: data?.escalationNotifications || [],
statusWindowSize: data?.statusWindowSize || 5,
statusWindowThreshold: data?.statusWindowThreshold || 60,
geoCheckEnabled: data?.geoCheckEnabled ?? false,
geoCheckLocations: data?.geoCheckLocations || [],
geoCheckInterval: data?.geoCheckInterval || 300000,
escalationDelay: data?.escalationDelay ?? 0,
});

export const useMonitorForm = ({
Expand Down
99 changes: 99 additions & 0 deletions client/src/Pages/CreateMonitor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,105 @@ const CreateMonitorPage = () => {
}
/>

<ConfigBox
title={t("pages.createMonitor.form.escalation.title")}
subtitle={t("pages.createMonitor.form.escalation.description")}
rightContent={
<Stack spacing={theme.spacing(LAYOUT.MD)}>
<Controller
name="escalationDelay"
control={control}
render={({ field, fieldState }) => (
<TextField
{...field}
value={field.value ?? 0}
onChange={(e) => {
const raw = e.target.value;
if (raw === "") {
field.onChange(0);
return;
}
const n = Number(raw);
field.onChange(Number.isFinite(n) ? n : 0);
}}
type="number"
inputProps={{ min: 0, step: 1 }}
fieldLabel={t(
"pages.createMonitor.form.escalation.option.delay.label"
)}
fullWidth
error={!!fieldState.error}
helperText={fieldState.error?.message ?? ""}
/>
)}
/>
<Controller
name="escalationNotifications"
control={control}
render={({ field }) => {
const notificationOptions = (notifications ?? []).map((n) => ({
...n,
name: n.notificationName,
}));
const selectedEscalation = notificationOptions.filter((n) =>
(field.value ?? []).includes(n.id)
);
return (
<Stack spacing={theme.spacing(LAYOUT.MD)}>
<Autocomplete
multiple
fieldLabel={t(
"pages.createMonitor.form.escalation.option.escalationNotifications.label"
)}
options={notificationOptions}
value={selectedEscalation}
getOptionLabel={(option) => option.name}
onChange={(_: unknown, newValue: typeof notificationOptions) => {
field.onChange(newValue.map((n) => n.id));
}}
isOptionEqualToValue={(option, value) => option.id === value.id}
/>
{selectedEscalation.length > 0 && (
<Stack
flex={1}
width="100%"
>
{selectedEscalation.map((notification, index) => (
<Stack
direction="row"
alignItems="center"
key={notification.id}
width="100%"
>
<Typography flexGrow={1}>
{notification.notificationName}
</Typography>
<IconButton
size="small"
onClick={() => {
field.onChange(
(field.value ?? []).filter(
(id: string) => id !== notification.id
)
);
}}
aria-label="Remove escalation notification"
>
<Trash2 size={16} />
</IconButton>
{index < selectedEscalation.length - 1 && <Divider />}
</Stack>
))}
</Stack>
)}
</Stack>
);
}}
/>
</Stack>
}
/>

{(watchedType === "http" ||
watchedType === "grpc" ||
watchedType === "websocket") && (
Expand Down
2 changes: 2 additions & 0 deletions client/src/Types/Monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export interface Monitor {
interval: number;
uptimePercentage?: number;
notifications: string[];
escalationNotifications: string[];
secret?: string;
cpuAlertThreshold: number;
cpuAlertCounter: number;
Expand All @@ -76,6 +77,7 @@ export interface Monitor {
geoCheckEnabled?: boolean;
geoCheckLocations?: GeoContinent[];
geoCheckInterval?: number;
escalationDelay?: number;
recentChecks: CheckSnapshot[];
createdAt: string;
updatedAt: string;
Expand Down
5 changes: 5 additions & 0 deletions client/src/Validation/monitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const baseSchema = z.object({
description: z.string().optional(),
interval: z.number().min(15000, "Interval must be at least 15 seconds"),
notifications: z.array(z.string()),
escalationNotifications: z.array(z.string()),
statusWindowSize: z
.number({ message: "Status window size is required" })
.min(1, "Status window size must be at least 1")
Expand All @@ -27,6 +28,10 @@ const baseSchema = z.object({
.number()
.min(300000, "Interval must be at least 5 minutes")
.optional(),
escalationDelay: z
.number({ message: "Escalation delay is required" })
.int("Escalation delay must be a whole number of minutes")
.min(0, "Escalation delay cannot be negative"),
});

// HTTP monitor schema
Expand Down
12 changes: 12 additions & 0 deletions client/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -543,6 +543,18 @@
"description": "Select the notification channels you want to use",
"title": "Notifications"
},
"escalation": {
"description": "If the monitor stays down for the specified time, notify additional channels.",
"title": "Escalation rules",
"option": {
"delay": {
"label": "Escalate After (minutes)"
},
"escalationNotifications": {
"label": "Escalation Notification Channels"
}
}
},
"type": {
"description": "Select the type of check to perform",
"optionDockerDescription": "Use Docker to monitor if a container is running.",
Expand Down
Loading