implement port monitoring

This commit is contained in:
Alex Holliday committed 2025-11-21 20:03:03 +00:00
1 parent caa863afe8
commit 5d825537ae
10 files changed
+195 -47

No files matched your search

@@ -20,6 +20,7 @@ export const useInitForm = ({
const defaults: z.infer<typeof monitorSchema> = {
type: initialData?.type || "https",
url: initialData?.url || "",
port: initialData?.port || 80,
n: initialData?.n || 3,
notificationChannels: initialData?.notificationChannels || [],
name: initialData?.name || "",
+21
View File
@@ -132,6 +132,11 @@ export const UptimeForm = ({
"Use HTTP to monitor your website or API endpoint."
}
/>
<RadioWithDescription
value="port"
label={"Port"}
description={"Check whether your port is open or not."}
/>
<RadioWithDescription
value="ping"
label={t("pingMonitoring")}
@@ -174,6 +179,22 @@ export const UptimeForm = ({
/>
)}
/>
{selectedType === "port" && (
<Controller
name="port"
control={control}
render={({ field }) => (
<TextInput
{...field}
type="number"
fieldLabel={"Port"}
fullWidth
error={!!errors.port}
helperText={errors.port ? errors.port.message : ""}
/>
)}
/>
)}
<Controller
name="name"
control={control}
+2 -1
View File
@@ -4,13 +4,14 @@ import type { IMonitorStats } from "./monitorStats";
export const MonitorTypes = [
"http",
"https",
"port",
"ping",
"infrastructure",
"pagespeed",
] as const;
export type MonitorType = (typeof MonitorTypes)[number];
export const UptimeMonitorTypes = ["http", "https", "ping"] as const;
export const UptimeMonitorTypes = ["http", "https", "port", "ping"] as const;
export type UptimeMonitorType = (typeof UptimeMonitorTypes)[number];
export const MonitorStatuses = [
+59 -41
View File
@@ -88,17 +88,50 @@ const optionalString = <T extends z.ZodTypeAny>(schema: T) =>
schema.optional()
);
export const monitorSchema = z.object({
type: z.string().min(1, "You must select an option"),
url: z.string().min(1, "URL is required").regex(urlRegex, "Invalid URL"),
n: z.coerce
.number({ message: "Number required" })
.min(1, "Minimum value is 1")
.max(25, "Maximum value is 25"),
notificationChannels: z.array(z.string()).optional().default([]),
name: z.string().min(1, "Display name is required"),
interval: durationSchema,
});
export const monitorSchema = z
.object({
type: z.string().min(1, "You must select an option"),
url: z.string().min(1, "URL is required").regex(urlRegex, "Invalid URL"),
n: z.coerce
.number({ message: "Number required" })
.min(1, "Minimum value is 1")
.max(25, "Maximum value is 25"),
port: z.coerce.number().optional(),
notificationChannels: z.array(z.string()).optional().default([]),
name: z.string().min(1, "Display name is required"),
interval: durationSchema,
})
.superRefine((data, ctx) => {
if (data.type === "port") {
if (!data.port) {
ctx.addIssue({
code: "custom",
message: "Port is required for port monitoring",
path: ["port"],
});
}
if (isNaN(Number(data.port))) {
ctx.addIssue({
code: "custom",
message: "Port must be a number",
path: ["port"],
});
}
if (Number(data.port) < 1 || Number(data.port) > 65535) {
ctx.addIssue({
code: "custom",
message: "Port must be between 1 and 65535",
path: ["port"],
});
}
}
})
.transform((data) => {
if (data.type !== "port") {
return { ...data, port: undefined };
}
return data;
});
export const monitorSchemaPageSpeed = z.object({
type: z.string().min(1, "You must select an option"),
@@ -212,13 +245,9 @@ export const maintenanceSchema = z
export const systemSettingsSchema = z.object({
systemEmailHost: optionalString(
z
.string()
.trim()
.min(1, { message: "SMTP host is required" })
.max(255, {
message: "SMTP host must be 255 characters or fewer",
})
z.string().trim().min(1, { message: "SMTP host is required" }).max(255, {
message: "SMTP host must be 255 characters or fewer",
})
),
systemEmailPort: optionalString(
z
@@ -237,35 +266,24 @@ export const systemSettingsSchema = z.object({
z.string().email({ message: "SMTP email must be valid" })
),
systemEmailPassword: optionalString(
z
.string()
.max(255, {
message: "SMTP password must be 255 characters or fewer",
})
z.string().max(255, {
message: "SMTP password must be 255 characters or fewer",
})
),
systemEmailUser: optionalString(
z
.string()
.trim()
.max(255, {
message: "SMTP username must be 255 characters or fewer",
})
z.string().trim().max(255, {
message: "SMTP username must be 255 characters or fewer",
})
),
systemEmailConnectionHost: optionalString(
z
.string()
.trim()
.max(255, {
message: "Connection host must be 255 characters or fewer",
})
z.string().trim().max(255, {
message: "Connection host must be 255 characters or fewer",
})
),
systemEmailTLSServername: optionalString(
z
.string()
.trim()
.max(255, {
message: "TLS server name must be 255 characters or fewer",
})
z.string().trim().max(255, {
message: "TLS server name must be 255 characters or fewer",
})
),
systemEmailSecure: z.boolean().optional(),
systemEmailPool: z.boolean().optional(),