Add new intervals and tcp mode to health checks

This commit is contained in:
Owen
2026-04-15 16:31:15 -07:00
parent b070570cb6
commit ad15b7c3c6
11 changed files with 614 additions and 322 deletions

View File

@@ -1844,6 +1844,14 @@
"healthCheckIntervalMin": "Check interval must be at least 5 seconds", "healthCheckIntervalMin": "Check interval must be at least 5 seconds",
"healthCheckTimeoutMin": "Timeout must be at least 1 second", "healthCheckTimeoutMin": "Timeout must be at least 1 second",
"healthCheckRetryMin": "Retry attempts must be at least 1", "healthCheckRetryMin": "Retry attempts must be at least 1",
"healthCheckMode": "Check Mode",
"healthCheckModeDescription": "TCP mode verifies connectivity only. HTTP mode validates the HTTP response.",
"healthyThreshold": "Healthy Threshold",
"healthyThresholdDescription": "Consecutive successes required before marking as healthy.",
"unhealthyThreshold": "Unhealthy Threshold",
"unhealthyThresholdDescription": "Consecutive failures required before marking as unhealthy.",
"healthCheckHealthyThresholdMin": "Healthy threshold must be at least 1",
"healthCheckUnhealthyThresholdMin": "Unhealthy threshold must be at least 1",
"httpMethod": "HTTP Method", "httpMethod": "HTTP Method",
"selectHttpMethod": "Select HTTP method", "selectHttpMethod": "Select HTTP method",
"domainPickerSubdomainLabel": "Subdomain", "domainPickerSubdomainLabel": "Subdomain",

View File

@@ -205,7 +205,9 @@ export const targetHealthCheck = pgTable("targetHealthCheck", {
hcHealth: text("hcHealth") hcHealth: text("hcHealth")
.$type<"unknown" | "healthy" | "unhealthy">() .$type<"unknown" | "healthy" | "unhealthy">()
.default("unknown"), // "unknown", "healthy", "unhealthy" .default("unknown"), // "unknown", "healthy", "unhealthy"
hcTlsServerName: text("hcTlsServerName") hcTlsServerName: text("hcTlsServerName"),
hcHealthyThreshold: integer("hcHealthyThreshold").default(1),
hcUnhealthyThreshold: integer("hcUnhealthyThreshold").default(1)
}); });
export const exitNodes = pgTable("exitNodes", { export const exitNodes = pgTable("exitNodes", {

View File

@@ -232,7 +232,9 @@ export const targetHealthCheck = sqliteTable("targetHealthCheck", {
hcHealth: text("hcHealth") hcHealth: text("hcHealth")
.$type<"unknown" | "healthy" | "unhealthy">() .$type<"unknown" | "healthy" | "unhealthy">()
.default("unknown"), // "unknown", "healthy", "unhealthy" .default("unknown"), // "unknown", "healthy", "unhealthy"
hcTlsServerName: text("hcTlsServerName") hcTlsServerName: text("hcTlsServerName"),
hcHealthyThreshold: integer("hcHealthyThreshold").default(1),
hcUnhealthyThreshold: integer("hcUnhealthyThreshold").default(1)
}); });
export const exitNodes = sqliteTable("exitNodes", { export const exitNodes = sqliteTable("exitNodes", {

View File

@@ -158,7 +158,9 @@ export async function updateProxyResources(
healthcheckData?.["follow-redirects"], healthcheckData?.["follow-redirects"],
hcMethod: healthcheckData?.method, hcMethod: healthcheckData?.method,
hcStatus: healthcheckData?.status, hcStatus: healthcheckData?.status,
hcHealth: "unknown" hcHealth: "unknown",
hcHealthyThreshold: healthcheckData?.["healthy-threshold"],
hcUnhealthyThreshold: healthcheckData?.["unhealthy-threshold"]
}) })
.returning(); .returning();
@@ -522,7 +524,9 @@ export async function updateProxyResources(
healthcheckData?.followRedirects || healthcheckData?.followRedirects ||
healthcheckData?.["follow-redirects"], healthcheckData?.["follow-redirects"],
hcMethod: healthcheckData?.method, hcMethod: healthcheckData?.method,
hcStatus: healthcheckData?.status hcStatus: healthcheckData?.status,
hcHealthyThreshold: healthcheckData?.["healthy-threshold"],
hcUnhealthyThreshold: healthcheckData?.["unhealthy-threshold"]
}) })
.where( .where(
eq( eq(
@@ -1081,6 +1085,8 @@ function checkIfHealthcheckChanged(
JSON.stringify(incoming.hcHeaders) JSON.stringify(incoming.hcHeaders)
) )
return true; return true;
if (existing.hcHealthyThreshold !== incoming.hcHealthyThreshold) return true;
if (existing.hcUnhealthyThreshold !== incoming.hcUnhealthyThreshold) return true;
return false; return false;
} }

View File

@@ -12,7 +12,7 @@ export const TargetHealthCheckSchema = z.object({
hostname: z.string(), hostname: z.string(),
port: z.int().min(1).max(65535), port: z.int().min(1).max(65535),
enabled: z.boolean().optional().default(true), enabled: z.boolean().optional().default(true),
path: z.string().optional().default("/"), path: z.string().optional(),
scheme: z.string().optional(), scheme: z.string().optional(),
mode: z.string().default("http"), mode: z.string().default("http"),
interval: z.int().default(30), interval: z.int().default(30),
@@ -26,8 +26,10 @@ export const TargetHealthCheckSchema = z.object({
.default(null), .default(null),
"follow-redirects": z.boolean().default(true), "follow-redirects": z.boolean().default(true),
followRedirects: z.boolean().optional(), // deprecated alias followRedirects: z.boolean().optional(), // deprecated alias
method: z.string().default("GET"), method: z.string().optional(),
status: z.int().optional() status: z.int().optional(),
"healthy-threshold": z.int().min(1).optional().default(1),
"unhealthy-threshold": z.int().min(1).optional().default(1)
}); });
// Schema for individual target within a resource // Schema for individual target within a resource

View File

@@ -213,7 +213,9 @@ export async function buildTargetConfigurationForNewtClient(siteId: number) {
hcHeaders: targetHealthCheck.hcHeaders, hcHeaders: targetHealthCheck.hcHeaders,
hcMethod: targetHealthCheck.hcMethod, hcMethod: targetHealthCheck.hcMethod,
hcTlsServerName: targetHealthCheck.hcTlsServerName, hcTlsServerName: targetHealthCheck.hcTlsServerName,
hcStatus: targetHealthCheck.hcStatus hcStatus: targetHealthCheck.hcStatus,
hcHealthyThreshold: targetHealthCheck.hcHealthyThreshold,
hcUnhealthyThreshold: targetHealthCheck.hcUnhealthyThreshold
}) })
.from(targets) .from(targets)
.innerJoin(resources, eq(targets.resourceId, resources.resourceId)) .innerJoin(resources, eq(targets.resourceId, resources.resourceId))
@@ -247,17 +249,12 @@ export async function buildTargetConfigurationForNewtClient(siteId: number) {
const healthCheckTargets = allTargets.map((target) => { const healthCheckTargets = allTargets.map((target) => {
// make sure the stuff is defined // make sure the stuff is defined
if ( const isTCP = target.hcMode?.toLowerCase() === "tcp";
!target.hcPath || if (!target.hcHostname || !target.hcPort || !target.hcInterval) {
!target.hcHostname || return null;
!target.hcPort || }
!target.hcInterval || if (!isTCP && (!target.hcPath || !target.hcMethod)) {
!target.hcMethod return null;
) {
// logger.debug(
// `Skipping adding target health check ${target.targetId} due to missing health check fields`
// );
return null; // Skip targets with missing health check fields
} }
// parse headers // parse headers
@@ -287,7 +284,9 @@ export async function buildTargetConfigurationForNewtClient(siteId: number) {
hcHeaders: hcHeadersSend, hcHeaders: hcHeadersSend,
hcMethod: target.hcMethod, hcMethod: target.hcMethod,
hcTlsServerName: target.hcTlsServerName, hcTlsServerName: target.hcTlsServerName,
hcStatus: target.hcStatus hcStatus: target.hcStatus,
hcHealthyThreshold: target.hcHealthyThreshold,
hcUnhealthyThreshold: target.hcUnhealthyThreshold
}; };
}); });

View File

@@ -9,6 +9,7 @@ import { eq, lt, isNull, and, or, ne, not } from "drizzle-orm";
import logger from "@server/logger"; import logger from "@server/logger";
import { sendNewtSyncMessage } from "./sync"; import { sendNewtSyncMessage } from "./sync";
import { recordPing } from "./pingAccumulator"; import { recordPing } from "./pingAccumulator";
import { fireSiteOfflineAlert } from "#dynamic/lib/alerts";
// Track if the offline checker interval is running // Track if the offline checker interval is running
let offlineCheckerInterval: NodeJS.Timeout | null = null; let offlineCheckerInterval: NodeJS.Timeout | null = null;
@@ -40,6 +41,8 @@ export const startNewtOfflineChecker = (): void => {
const staleSites = await db const staleSites = await db
.select({ .select({
siteId: sites.siteId, siteId: sites.siteId,
orgId: sites.orgId,
name: sites.name,
newtId: newts.newtId, newtId: newts.newtId,
lastPing: sites.lastPing lastPing: sites.lastPing
}) })
@@ -104,6 +107,8 @@ export const startNewtOfflineChecker = (): void => {
) )
); );
} }
await fireSiteOfflineAlert(staleSite.orgId, staleSite.siteId, staleSite.name);
} }
// this part only effects self hosted. Its not efficient but we dont expect people to have very many wireguard sites // this part only effects self hosted. Its not efficient but we dont expect people to have very many wireguard sites

View File

@@ -43,17 +43,18 @@ export async function addTargets(
} }
// Ensure all necessary fields are present // Ensure all necessary fields are present
if ( const isTCP = hc.hcMode?.toLowerCase() === "tcp";
!hc.hcPath || if (!hc.hcHostname || !hc.hcPort || !hc.hcInterval) {
!hc.hcHostname ||
!hc.hcPort ||
!hc.hcInterval ||
!hc.hcMethod
) {
logger.debug( logger.debug(
`Skipping target ${target.targetId} due to missing health check fields` `Skipping target ${target.targetId} due to missing health check fields`
); );
return null; // Skip targets with missing health check fields return null;
}
if (!isTCP && (!hc.hcPath || !hc.hcMethod)) {
logger.debug(
`Skipping target ${target.targetId} due to missing HTTP health check fields`
);
return null;
} }
const hcHeadersParse = hc.hcHeaders ? JSON.parse(hc.hcHeaders) : null; const hcHeadersParse = hc.hcHeaders ? JSON.parse(hc.hcHeaders) : null;
@@ -90,7 +91,9 @@ export async function addTargets(
hcHeaders: hcHeadersSend, hcHeaders: hcHeadersSend,
hcMethod: hc.hcMethod, hcMethod: hc.hcMethod,
hcStatus: hcStatus, hcStatus: hcStatus,
hcTlsServerName: hc.hcTlsServerName hcTlsServerName: hc.hcTlsServerName,
hcHealthyThreshold: hc.hcHealthyThreshold,
hcUnhealthyThreshold: hc.hcUnhealthyThreshold
}; };
}); });

View File

@@ -42,6 +42,8 @@ const createTargetSchema = z.strictObject({
hcMethod: z.string().min(1).optional().nullable(), hcMethod: z.string().min(1).optional().nullable(),
hcStatus: z.int().optional().nullable(), hcStatus: z.int().optional().nullable(),
hcTlsServerName: z.string().optional().nullable(), hcTlsServerName: z.string().optional().nullable(),
hcHealthyThreshold: z.int().positive().min(1).optional().nullable(),
hcUnhealthyThreshold: z.int().positive().min(1).optional().nullable(),
path: z.string().optional().nullable(), path: z.string().optional().nullable(),
pathMatchType: z.enum(["exact", "prefix", "regex"]).optional().nullable(), pathMatchType: z.enum(["exact", "prefix", "regex"]).optional().nullable(),
rewritePath: z.string().optional().nullable(), rewritePath: z.string().optional().nullable(),
@@ -241,7 +243,9 @@ export async function createTarget(
hcMethod: targetData.hcMethod ?? null, hcMethod: targetData.hcMethod ?? null,
hcStatus: targetData.hcStatus ?? null, hcStatus: targetData.hcStatus ?? null,
hcHealth: "unknown", hcHealth: "unknown",
hcTlsServerName: targetData.hcTlsServerName ?? null hcTlsServerName: targetData.hcTlsServerName ?? null,
hcHealthyThreshold: targetData.hcHealthyThreshold ?? null,
hcUnhealthyThreshold: targetData.hcUnhealthyThreshold ?? null
}) })
.returning(); .returning();

View File

@@ -43,6 +43,8 @@ const updateTargetBodySchema = z
hcMethod: z.string().min(1).optional().nullable(), hcMethod: z.string().min(1).optional().nullable(),
hcStatus: z.int().optional().nullable(), hcStatus: z.int().optional().nullable(),
hcTlsServerName: z.string().optional().nullable(), hcTlsServerName: z.string().optional().nullable(),
hcHealthyThreshold: z.int().positive().min(1).optional().nullable(),
hcUnhealthyThreshold: z.int().positive().min(1).optional().nullable(),
path: z.string().optional().nullable(), path: z.string().optional().nullable(),
pathMatchType: z pathMatchType: z
.enum(["exact", "prefix", "regex"]) .enum(["exact", "prefix", "regex"])
@@ -240,6 +242,8 @@ export async function updateTarget(
hcMethod: parsedBody.data.hcMethod, hcMethod: parsedBody.data.hcMethod,
hcStatus: parsedBody.data.hcStatus, hcStatus: parsedBody.data.hcStatus,
hcTlsServerName: parsedBody.data.hcTlsServerName, hcTlsServerName: parsedBody.data.hcTlsServerName,
hcHealthyThreshold: parsedBody.data.hcHealthyThreshold,
hcUnhealthyThreshold: parsedBody.data.hcUnhealthyThreshold,
...(hcHealthValue !== undefined && { hcHealth: hcHealthValue }) ...(hcHealthValue !== undefined && { hcHealth: hcHealthValue })
}) })
.where(eq(targetHealthCheck.targetId, targetId)) .where(eq(targetHealthCheck.targetId, targetId))

View File

@@ -52,6 +52,8 @@ type HealthCheckConfig = {
hcMode: string; hcMode: string;
hcUnhealthyInterval: number; hcUnhealthyInterval: number;
hcTlsServerName: string; hcTlsServerName: string;
hcHealthyThreshold: number;
hcUnhealthyThreshold: number;
}; };
type HealthCheckDialogProps = { type HealthCheckDialogProps = {
@@ -75,44 +77,73 @@ export default function HealthCheckDialog({
}: HealthCheckDialogProps) { }: HealthCheckDialogProps) {
const t = useTranslations(); const t = useTranslations();
const healthCheckSchema = z.object({ const healthCheckSchema = z
hcEnabled: z.boolean(), .object({
hcPath: z.string().min(1, { message: t("healthCheckPathRequired") }), hcEnabled: z.boolean(),
hcMethod: z hcPath: z.string().optional(),
.string() hcMethod: z.string().optional(),
.min(1, { message: t("healthCheckMethodRequired") }), hcInterval: z
hcInterval: z .int()
.int() .positive()
.positive() .min(5, { message: t("healthCheckIntervalMin") }),
.min(5, { message: t("healthCheckIntervalMin") }), hcTimeout: z
hcTimeout: z .int()
.int() .positive()
.positive() .min(1, { message: t("healthCheckTimeoutMin") }),
.min(1, { message: t("healthCheckTimeoutMin") }), hcStatus: z.int().positive().min(100).optional().nullable(),
hcStatus: z.int().positive().min(100).optional().nullable(), hcHeaders: z
hcHeaders: z .array(z.object({ name: z.string(), value: z.string() }))
.array(z.object({ name: z.string(), value: z.string() })) .nullable()
.nullable() .optional(),
.optional(), hcScheme: z.string().optional(),
hcScheme: z.string().optional(), hcHostname: z.string(),
hcHostname: z.string(), hcPort: z
hcPort: z .string()
.string() .min(1, { message: t("healthCheckPortInvalid") })
.min(1, { message: t("healthCheckPortInvalid") }) .refine(
.refine( (val) => {
(val) => { const port = parseInt(val);
const port = parseInt(val); return port > 0 && port <= 65535;
return port > 0 && port <= 65535; },
}, {
{ message: t("healthCheckPortInvalid")
message: t("healthCheckPortInvalid") }
),
hcFollowRedirects: z.boolean(),
hcMode: z.string(),
hcUnhealthyInterval: z.int().positive().min(5),
hcTlsServerName: z.string(),
hcHealthyThreshold: z
.int()
.positive()
.min(1, {
message: t("healthCheckHealthyThresholdMin")
}),
hcUnhealthyThreshold: z
.int()
.positive()
.min(1, {
message: t("healthCheckUnhealthyThresholdMin")
})
})
.superRefine((data, ctx) => {
if (data.hcMode !== "tcp") {
if (!data.hcPath || data.hcPath.length < 1) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: t("healthCheckPathRequired"),
path: ["hcPath"]
});
} }
), if (!data.hcMethod || data.hcMethod.length < 1) {
hcFollowRedirects: z.boolean(), ctx.addIssue({
hcMode: z.string(), code: z.ZodIssueCode.custom,
hcUnhealthyInterval: z.int().positive().min(5), message: t("healthCheckMethodRequired"),
hcTlsServerName: z.string() path: ["hcMethod"]
}); });
}
}
});
const form = useForm<z.infer<typeof healthCheckSchema>>({ const form = useForm<z.infer<typeof healthCheckSchema>>({
resolver: zodResolver(healthCheckSchema), resolver: zodResolver(healthCheckSchema),
@@ -122,12 +153,10 @@ export default function HealthCheckDialog({
useEffect(() => { useEffect(() => {
if (!open) return; if (!open) return;
// Determine default scheme from target method
const getDefaultScheme = () => { const getDefaultScheme = () => {
if (initialConfig?.hcScheme) { if (initialConfig?.hcScheme) {
return initialConfig.hcScheme; return initialConfig.hcScheme;
} }
// Default to target method if it's http or https, otherwise default to http
if (targetMethod === "https") { if (targetMethod === "https") {
return "https"; return "https";
} }
@@ -148,24 +177,30 @@ export default function HealthCheckDialog({
? initialConfig.hcPort.toString() ? initialConfig.hcPort.toString()
: "", : "",
hcFollowRedirects: initialConfig?.hcFollowRedirects, hcFollowRedirects: initialConfig?.hcFollowRedirects,
hcMode: initialConfig?.hcMode, hcMode: initialConfig?.hcMode ?? "http",
hcUnhealthyInterval: initialConfig?.hcUnhealthyInterval, hcUnhealthyInterval: initialConfig?.hcUnhealthyInterval,
hcTlsServerName: initialConfig?.hcTlsServerName ?? "" hcTlsServerName: initialConfig?.hcTlsServerName ?? "",
hcHealthyThreshold: initialConfig?.hcHealthyThreshold ?? 1,
hcUnhealthyThreshold: initialConfig?.hcUnhealthyThreshold ?? 1
}); });
}, [open]); }, [open]);
const watchedEnabled = form.watch("hcEnabled"); const watchedEnabled = form.watch("hcEnabled");
const watchedMode = form.watch("hcMode");
const handleFieldChange = async (fieldName: string, value: any) => { const handleFieldChange = async (fieldName: string, value: any) => {
try { try {
const currentValues = form.getValues(); const currentValues = form.getValues();
const updatedValues = { ...currentValues, [fieldName]: value }; const updatedValues = { ...currentValues, [fieldName]: value };
// Convert hcPort from string to number before passing to parent
const configToSend: HealthCheckConfig = { const configToSend: HealthCheckConfig = {
...updatedValues, ...updatedValues,
hcPath: updatedValues.hcPath ?? "",
hcMethod: updatedValues.hcMethod ?? "",
hcPort: parseInt(updatedValues.hcPort), hcPort: parseInt(updatedValues.hcPort),
hcStatus: updatedValues.hcStatus || null hcStatus: updatedValues.hcStatus || null,
hcHealthyThreshold: updatedValues.hcHealthyThreshold,
hcUnhealthyThreshold: updatedValues.hcUnhealthyThreshold
}; };
await onChanges(configToSend); await onChanges(configToSend);
@@ -226,14 +261,262 @@ export default function HealthCheckDialog({
{watchedEnabled && ( {watchedEnabled && (
<div className="space-y-4"> <div className="space-y-4">
<div className="grid grid-cols-1 md:grid-cols-4 gap-4"> {/* Mode */}
<FormField
control={form.control}
name="hcMode"
render={({ field }) => (
<FormItem>
<FormLabel>
{t("healthCheckMode")}
</FormLabel>
<Select
onValueChange={(value) => {
field.onChange(value);
handleFieldChange(
"hcMode",
value
);
}}
value={field.value}
>
<FormControl>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
</FormControl>
<SelectContent>
<SelectItem value="http">
HTTP
</SelectItem>
<SelectItem value="tcp">
TCP
</SelectItem>
</SelectContent>
</Select>
<FormDescription>
{t(
"healthCheckModeDescription"
)}
</FormDescription>
<FormMessage />
</FormItem>
)}
/>
{/* Connection fields */}
{watchedMode === "tcp" ? (
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<FormField
control={form.control}
name="hcHostname"
render={({ field }) => (
<FormItem>
<FormLabel>
{t("healthHostname")}
</FormLabel>
<FormControl>
<Input
{...field}
onChange={(
e
) => {
field.onChange(
e
);
handleFieldChange(
"hcHostname",
e.target
.value
);
}}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="hcPort"
render={({ field }) => (
<FormItem>
<FormLabel>
{t("healthPort")}
</FormLabel>
<FormControl>
<Input
{...field}
onChange={(
e
) => {
const value =
e.target
.value;
field.onChange(
value
);
handleFieldChange(
"hcPort",
value
);
}}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
) : (
<div className="grid grid-cols-1 md:grid-cols-4 gap-4">
<FormField
control={form.control}
name="hcScheme"
render={({ field }) => (
<FormItem>
<FormLabel>
{t("healthScheme")}
</FormLabel>
<Select
onValueChange={(
value
) => {
field.onChange(
value
);
handleFieldChange(
"hcScheme",
value
);
}}
defaultValue={
field.value
}
>
<FormControl>
<SelectTrigger>
<SelectValue
placeholder={t(
"healthSelectScheme"
)}
/>
</SelectTrigger>
</FormControl>
<SelectContent>
<SelectItem value="http">
HTTP
</SelectItem>
<SelectItem value="https">
HTTPS
</SelectItem>
</SelectContent>
</Select>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="hcHostname"
render={({ field }) => (
<FormItem>
<FormLabel>
{t("healthHostname")}
</FormLabel>
<FormControl>
<Input
{...field}
onChange={(
e
) => {
field.onChange(
e
);
handleFieldChange(
"hcHostname",
e.target
.value
);
}}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="hcPort"
render={({ field }) => (
<FormItem>
<FormLabel>
{t("healthPort")}
</FormLabel>
<FormControl>
<Input
{...field}
onChange={(
e
) => {
const value =
e.target
.value;
field.onChange(
value
);
handleFieldChange(
"hcPort",
value
);
}}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="hcPath"
render={({ field }) => (
<FormItem>
<FormLabel>
{t("healthCheckPath")}
</FormLabel>
<FormControl>
<Input
{...field}
onChange={(
e
) => {
field.onChange(
e
);
handleFieldChange(
"hcPath",
e.target
.value
);
}}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
)}
{/* HTTP Method */}
{watchedMode !== "tcp" && (
<FormField <FormField
control={form.control} control={form.control}
name="hcScheme" name="hcMethod"
render={({ field }) => ( render={({ field }) => (
<FormItem> <FormItem>
<FormLabel> <FormLabel>
{t("healthScheme")} {t("httpMethod")}
</FormLabel> </FormLabel>
<Select <Select
onValueChange={( onValueChange={(
@@ -243,7 +526,7 @@ export default function HealthCheckDialog({
value value
); );
handleFieldChange( handleFieldChange(
"hcScheme", "hcMethod",
value value
); );
}} }}
@@ -255,17 +538,26 @@ export default function HealthCheckDialog({
<SelectTrigger> <SelectTrigger>
<SelectValue <SelectValue
placeholder={t( placeholder={t(
"healthSelectScheme" "selectHttpMethod"
)} )}
/> />
</SelectTrigger> </SelectTrigger>
</FormControl> </FormControl>
<SelectContent> <SelectContent>
<SelectItem value="http"> <SelectItem value="GET">
HTTP GET
</SelectItem> </SelectItem>
<SelectItem value="https"> <SelectItem value="POST">
HTTPS POST
</SelectItem>
<SelectItem value="HEAD">
HEAD
</SelectItem>
<SelectItem value="PUT">
PUT
</SelectItem>
<SelectItem value="DELETE">
DELETE
</SelectItem> </SelectItem>
</SelectContent> </SelectContent>
</Select> </Select>
@@ -273,143 +565,9 @@ export default function HealthCheckDialog({
</FormItem> </FormItem>
)} )}
/> />
<FormField )}
control={form.control}
name="hcHostname"
render={({ field }) => (
<FormItem>
<FormLabel>
{t("healthHostname")}
</FormLabel>
<FormControl>
<Input
{...field}
onChange={(e) => {
field.onChange(
e
);
handleFieldChange(
"hcHostname",
e.target
.value
);
}}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="hcPort"
render={({ field }) => (
<FormItem>
<FormLabel>
{t("healthPort")}
</FormLabel>
<FormControl>
<Input
{...field}
onChange={(e) => {
const value =
e.target
.value;
field.onChange(
value
);
handleFieldChange(
"hcPort",
value
);
}}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="hcPath"
render={({ field }) => (
<FormItem>
<FormLabel>
{t("healthCheckPath")}
</FormLabel>
<FormControl>
<Input
{...field}
onChange={(e) => {
field.onChange(
e
);
handleFieldChange(
"hcPath",
e.target
.value
);
}}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
</div>
{/* HTTP Method */} {/* Check Interval, Unhealthy Interval, and Timeout */}
<FormField
control={form.control}
name="hcMethod"
render={({ field }) => (
<FormItem>
<FormLabel>
{t("httpMethod")}
</FormLabel>
<Select
onValueChange={(value) => {
field.onChange(value);
handleFieldChange(
"hcMethod",
value
);
}}
defaultValue={field.value}
>
<FormControl>
<SelectTrigger>
<SelectValue
placeholder={t(
"selectHttpMethod"
)}
/>
</SelectTrigger>
</FormControl>
<SelectContent>
<SelectItem value="GET">
GET
</SelectItem>
<SelectItem value="POST">
POST
</SelectItem>
<SelectItem value="HEAD">
HEAD
</SelectItem>
<SelectItem value="PUT">
PUT
</SelectItem>
<SelectItem value="DELETE">
DELETE
</SelectItem>
</SelectContent>
</Select>
<FormMessage />
</FormItem>
)}
/>
{/* Check Interval, Timeout, and Retry Attempts */}
<div className="grid grid-cols-1 md:grid-cols-3 gap-4"> <div className="grid grid-cols-1 md:grid-cols-3 gap-4">
<FormField <FormField
control={form.control} control={form.control}
@@ -515,112 +673,211 @@ export default function HealthCheckDialog({
/> />
</div> </div>
{/* Expected Response Codes */} {/* Healthy and Unhealthy Thresholds */}
<FormField <div className="grid grid-cols-1 md:grid-cols-2 gap-4">
control={form.control} <FormField
name="hcStatus" control={form.control}
render={({ field }) => ( name="hcHealthyThreshold"
<FormItem> render={({ field }) => (
<FormLabel> <FormItem>
{t("expectedResponseCodes")} <FormLabel>
</FormLabel> {t("healthyThreshold")}
<FormControl> </FormLabel>
<Input <FormControl>
type="number" <Input
{...field} type="number"
value={ {...field}
field.value || "" onChange={(e) => {
} const value =
onChange={(e) => { parseInt(
const value = e.target
parseInt( .value
e.target );
.value field.onChange(
value
); );
field.onChange( handleFieldChange(
value "hcHealthyThreshold",
); value
handleFieldChange( );
"hcStatus", }}
value />
); </FormControl>
}} <FormDescription>
/> {t(
</FormControl> "healthyThresholdDescription"
<FormDescription> )}
{t( </FormDescription>
"expectedResponseCodesDescription" <FormMessage />
)} </FormItem>
</FormDescription> )}
<FormMessage /> />
</FormItem>
)}
/>
{/*TLS Server Name (SNI)*/} <FormField
<FormField control={form.control}
control={form.control} name="hcUnhealthyThreshold"
name="hcTlsServerName" render={({ field }) => (
render={({ field }) => ( <FormItem>
<FormItem> <FormLabel>
<FormLabel> {t("unhealthyThreshold")}
{t("tlsServerName")} </FormLabel>
</FormLabel> <FormControl>
<FormControl> <Input
<Input type="number"
{...field} {...field}
onChange={(e) => { onChange={(e) => {
field.onChange(e); const value =
handleFieldChange( parseInt(
"hcTlsServerName", e.target
e.target.value .value
); );
}} field.onChange(
/> value
</FormControl> );
<FormDescription> handleFieldChange(
{t( "hcUnhealthyThreshold",
"tlsServerNameDescription" value
)} );
</FormDescription> }}
<FormMessage /> />
</FormItem> </FormControl>
)} <FormDescription>
/> {t(
"unhealthyThresholdDescription"
)}
</FormDescription>
<FormMessage />
</FormItem>
)}
/>
</div>
{/* Custom Headers */} {/* HTTP-only fields */}
<FormField {watchedMode !== "tcp" && (
control={form.control} <>
name="hcHeaders" {/* Expected Response Codes */}
render={({ field }) => ( <FormField
<FormItem> control={form.control}
<FormLabel> name="hcStatus"
{t("customHeaders")} render={({ field }) => (
</FormLabel> <FormItem>
<FormControl> <FormLabel>
<HeadersInput {t(
value={field.value} "expectedResponseCodes"
onChange={(value) => { )}
field.onChange( </FormLabel>
value <FormControl>
); <Input
handleFieldChange( type="number"
"hcHeaders", {...field}
value value={
); field.value ||
}} ""
rows={4} }
/> onChange={(
</FormControl> e
<FormDescription> ) => {
{t( const value =
"customHeadersDescription" parseInt(
)} e
</FormDescription> .target
<FormMessage /> .value
</FormItem> );
)} field.onChange(
/> value
);
handleFieldChange(
"hcStatus",
value
);
}}
/>
</FormControl>
<FormDescription>
{t(
"expectedResponseCodesDescription"
)}
</FormDescription>
<FormMessage />
</FormItem>
)}
/>
{/* TLS Server Name (SNI) */}
<FormField
control={form.control}
name="hcTlsServerName"
render={({ field }) => (
<FormItem>
<FormLabel>
{t("tlsServerName")}
</FormLabel>
<FormControl>
<Input
{...field}
onChange={(
e
) => {
field.onChange(
e
);
handleFieldChange(
"hcTlsServerName",
e.target
.value
);
}}
/>
</FormControl>
<FormDescription>
{t(
"tlsServerNameDescription"
)}
</FormDescription>
<FormMessage />
</FormItem>
)}
/>
{/* Custom Headers */}
<FormField
control={form.control}
name="hcHeaders"
render={({ field }) => (
<FormItem>
<FormLabel>
{t("customHeaders")}
</FormLabel>
<FormControl>
<HeadersInput
value={
field.value
}
onChange={(
value
) => {
field.onChange(
value
);
handleFieldChange(
"hcHeaders",
value
);
}}
rows={4}
/>
</FormControl>
<FormDescription>
{t(
"customHeadersDescription"
)}
</FormDescription>
<FormMessage />
</FormItem>
)}
/>
</>
)}
</div> </div>
)} )}
</form> </form>
@@ -632,4 +889,4 @@ export default function HealthCheckDialog({
</CredenzaContent> </CredenzaContent>
</Credenza> </Credenza>
); );
} }