mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-05-21 00:48:45 -05:00
123 lines
3.1 KiB
TypeScript
123 lines
3.1 KiB
TypeScript
import { z } from "zod";
|
|
|
|
// Common base schema for all monitor types
|
|
const baseSchema = z.object({
|
|
name: z
|
|
.string()
|
|
.min(1, "Monitor name is required")
|
|
.max(50, "Monitor name must be at most 50 characters"),
|
|
interval: z.number().min(15000, "Interval must be at least 15 seconds"),
|
|
notifications: z.array(z.string()),
|
|
statusWindowSize: z
|
|
.number()
|
|
.min(1, "Status window size must be at least 1")
|
|
.max(20, "Status window size must be at most 20"),
|
|
statusWindowThreshold: z
|
|
.number()
|
|
.min(1, "Incident percentage must be at least 1")
|
|
.max(100, "Incident percentage must be at most 100"),
|
|
});
|
|
|
|
// HTTP monitor schema
|
|
const httpSchema = baseSchema.extend({
|
|
type: z.literal("http"),
|
|
url: z
|
|
.string()
|
|
.min(1, "URL is required")
|
|
.url("Please enter a valid URL"),
|
|
ignoreTlsErrors: z.boolean(),
|
|
matchMethod: z.enum(["equal", "include", "regex", ""]).optional(),
|
|
expectedValue: z.string().optional(),
|
|
jsonPath: z.string().optional(),
|
|
});
|
|
|
|
// Ping monitor schema
|
|
const pingSchema = baseSchema.extend({
|
|
type: z.literal("ping"),
|
|
url: z.string().min(1, "Host is required"),
|
|
});
|
|
|
|
// Port monitor schema
|
|
const portSchema = baseSchema.extend({
|
|
type: z.literal("port"),
|
|
url: z.string().min(1, "Host is required"),
|
|
port: z
|
|
.number()
|
|
.min(1, "Port must be at least 1")
|
|
.max(65535, "Port must be at most 65535"),
|
|
});
|
|
|
|
// Docker monitor schema
|
|
const dockerSchema = baseSchema.extend({
|
|
type: z.literal("docker"),
|
|
url: z.string().min(1, "Container ID is required"),
|
|
});
|
|
|
|
// Game server monitor schema
|
|
const gameSchema = baseSchema.extend({
|
|
type: z.literal("game"),
|
|
url: z.string().min(1, "Host is required"),
|
|
port: z
|
|
.number()
|
|
.min(1, "Port must be at least 1")
|
|
.max(65535, "Port must be at most 65535"),
|
|
gameId: z.string().min(1, "Game type is required"),
|
|
});
|
|
|
|
// PageSpeed monitor schema
|
|
const pagespeedSchema = baseSchema.extend({
|
|
type: z.literal("pagespeed"),
|
|
url: z
|
|
.string()
|
|
.min(1, "URL is required")
|
|
.url("Please enter a valid URL"),
|
|
});
|
|
|
|
// Hardware/Infrastructure monitor schema
|
|
const hardwareSchema = baseSchema.extend({
|
|
type: z.literal("hardware"),
|
|
url: z.string().optional(),
|
|
secret: z.string().optional(),
|
|
cpuAlertThreshold: z
|
|
.number()
|
|
.min(0, "CPU threshold must be at least 0")
|
|
.max(100, "CPU threshold must be at most 100"),
|
|
memoryAlertThreshold: z
|
|
.number()
|
|
.min(0, "Memory threshold must be at least 0")
|
|
.max(100, "Memory threshold must be at most 100"),
|
|
diskAlertThreshold: z
|
|
.number()
|
|
.min(0, "Disk threshold must be at least 0")
|
|
.max(100, "Disk threshold must be at most 100"),
|
|
tempAlertThreshold: z
|
|
.number()
|
|
.min(0, "Temperature threshold must be at least 0")
|
|
.max(150, "Temperature threshold must be at most 150"),
|
|
selectedDisks: z.array(z.string()),
|
|
});
|
|
|
|
// Discriminated union of all monitor types
|
|
export const monitorSchema = z.discriminatedUnion("type", [
|
|
httpSchema,
|
|
pingSchema,
|
|
portSchema,
|
|
dockerSchema,
|
|
gameSchema,
|
|
pagespeedSchema,
|
|
hardwareSchema,
|
|
]);
|
|
|
|
export type MonitorFormData = z.infer<typeof monitorSchema>;
|
|
|
|
// Type-specific schemas exported for individual use
|
|
export {
|
|
httpSchema,
|
|
pingSchema,
|
|
portSchema,
|
|
dockerSchema,
|
|
gameSchema,
|
|
pagespeedSchema,
|
|
hardwareSchema,
|
|
};
|