Skip to content

Commit c055c3d

Browse files
author
mannilakash
committed
feat: adding custom/default user agent support for http monitors
1 parent c24b41e commit c055c3d

19 files changed

Lines changed: 104 additions & 4 deletions

File tree

client/src/Hooks/useMonitorForm.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export const useMonitorForm = ({
4040
matchMethod: data?.matchMethod || "",
4141
expectedValue: data?.expectedValue || "",
4242
jsonPath: data?.jsonPath || "",
43+
customUserAgent: data?.customUserAgent || "",
4344
};
4445
break;
4546
case "ping":

client/src/Hooks/useSettingsForm.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export const useSettingsForm = ({ data = null }: UseSettingsFormOptions = {}) =>
4040
: 80,
4141
},
4242
checkTTL: data?.checkTTL ?? 30,
43+
defaultUserAgent: data?.defaultUserAgent || "",
4344
pagespeedApiKey: "",
4445
systemEmailPassword: "",
4546
};

client/src/Pages/CreateMonitor/index.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -795,6 +795,31 @@ const CreateMonitorPage = () => {
795795
/>
796796
)}
797797

798+
{watchedType === "http" && (
799+
<ConfigBox
800+
title={t("pages.createMonitor.form.userAgent.title")}
801+
subtitle={t("pages.createMonitor.form.userAgent.description")}
802+
rightContent={
803+
<Controller
804+
name="customUserAgent"
805+
control={control}
806+
render={({ field, fieldState }) => (
807+
<TextField
808+
{...field}
809+
value={field.value ?? ""}
810+
type="text"
811+
fieldLabel={t("pages.createMonitor.form.userAgent.option.label")}
812+
placeholder={t("pages.createMonitor.form.userAgent.option.placeholder")}
813+
fullWidth
814+
error={!!fieldState.error}
815+
helperText={fieldState.error?.message ?? ""}
816+
/>
817+
)}
818+
/>
819+
}
820+
/>
821+
)}
822+
798823
{watchedType === "http" && (
799824
<ConfigBox
800825
title={t("pages.createMonitor.form.advanced.title")}

client/src/Pages/Settings/index.tsx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,30 @@ export const SettingsPage = () => {
425425
}
426426
/>
427427

428+
{/* Default User-Agent - Admin Only */}
429+
{isAdmin && (
430+
<ConfigBox
431+
title={t("pages.settings.form.userAgent.title")}
432+
subtitle={t("pages.settings.form.userAgent.description")}
433+
rightContent={
434+
<Controller
435+
name="defaultUserAgent"
436+
control={form.control}
437+
render={({ field, fieldState }) => (
438+
<TextField
439+
{...field}
440+
value={field.value ?? ""}
441+
fieldLabel={t("pages.settings.form.userAgent.option.label")}
442+
placeholder={t("pages.settings.form.userAgent.option.placeholder")}
443+
error={!!fieldState.error}
444+
helperText={fieldState.error?.message}
445+
/>
446+
)}
447+
/>
448+
}
449+
/>
450+
)}
451+
428452
{/* Clear All Stats */}
429453
{isAdmin && (
430454
<ConfigBox

client/src/Types/Monitor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ export interface Monitor {
7373
gameId?: string;
7474
grpcServiceName?: string;
7575
group: string | null;
76+
customUserAgent?: string;
7677
geoCheckEnabled?: boolean;
7778
geoCheckLocations?: GeoContinent[];
7879
geoCheckInterval?: number;

client/src/Types/Settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface Settings {
2121
systemEmailRequireTLS: boolean;
2222
systemEmailRejectUnauthorized: boolean;
2323
showURL: boolean;
24+
defaultUserAgent?: string;
2425
singleton: boolean;
2526
globalThresholds?: SettingsThresholds;
2627
createdAt: string;

client/src/Validation/monitor.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const httpSchema = baseSchema.extend({
3838
matchMethod: z.enum(["equal", "include", "regex", ""]).optional(),
3939
expectedValue: z.string().optional(),
4040
jsonPath: z.string().optional(),
41+
customUserAgent: z.string().max(500).optional(),
4142
});
4243

4344
// Ping monitor schema

client/src/Validation/settings.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ export const settingsSchema = z.object({
1212
systemEmailSecure: z.boolean().optional(),
1313
systemEmailPool: z.boolean().optional(),
1414
showURL: z.boolean().optional(),
15+
defaultUserAgent: z
16+
.string()
17+
.max(500)
18+
.transform((val) => (val.trim() === "" ? null : val.trim()))
19+
.optional(),
1520
checkTTL: z
1621
.number()
1722
.int()

client/src/locales/en.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,14 @@
527527
},
528528
"title": "TLS/SSL settings"
529529
},
530+
"userAgent": {
531+
"title": "Custom User-Agent",
532+
"description": "Override the User-Agent header sent with HTTP requests for this monitor. Useful for identifying Checkmate in WAF logs. Leave blank to use the global default.",
533+
"option": {
534+
"label": "User-Agent",
535+
"placeholder": "Checkmate/X.X (uptime monitor)"
536+
}
537+
},
530538
"incidents": {
531539
"description": "A sliding window is used to determine when a monitor goes down. The status of a monitor will only change when the percentage of checks in the sliding window meet the specified value.",
532540
"option": {
@@ -1043,6 +1051,14 @@
10431051
}
10441052
}
10451053
},
1054+
"userAgent": {
1055+
"title": "Default User-Agent",
1056+
"description": "Set a default User-Agent header sent with all HTTP uptime monitor requests. Individual monitors can override this. Useful for identifying Checkmate in WAF logs and whitelists.",
1057+
"option": {
1058+
"label": "Default User-Agent",
1059+
"placeholder": "Checkmate/X.X (uptime monitor; your-instance)"
1060+
}
1061+
},
10461062
"stats": {
10471063
"title": "Monitor history",
10481064
"description": "Clear all monitoring history and statistics for your team. This action is irreversible.",

server/src/config/services.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export const initializeServices = async ({
181181

182182
// Network providers
183183
const pingProvider = new PingProvider(ping);
184-
const httpProvider = new HttpProvider(got, new AdvancedMatcher(jmespath));
184+
const httpProvider = new HttpProvider(got, new AdvancedMatcher(jmespath), settingsService);
185185
const pageSpeedProvider = new PageSpeedProvider(httpProvider, settingsService, logger);
186186
const hardwareProvider = new HardwareProvider(httpProvider);
187187
const dockerProvider = new DockerProvider(logger, Docker);

0 commit comments

Comments
 (0)