From e7ffe47cf819e3250742feeb6006c045a03721c1 Mon Sep 17 00:00:00 2001 From: dongfang <1136005348@qq.com> Date: Thu, 13 Feb 2025 00:54:19 +0000 Subject: [PATCH 1/5] add json validation fields --- Client/src/Validation/validation.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Client/src/Validation/validation.js b/Client/src/Validation/validation.js index 0335b520d..04088e44c 100644 --- a/Client/src/Validation/validation.js +++ b/Client/src/Validation/validation.js @@ -161,6 +161,9 @@ const monitorValidation = joi.object({ "number.base": "Frequency must be a number.", "any.required": "Frequency is required.", }), + expectedValue: joi.string().allow(""), + jsonPath: joi.string().allow(""), + matchMethod: joi.string(), }); const imageValidation = joi.object({ From 2330fc8684718bae5ffde4dbc76e91303a54d7e9 Mon Sep 17 00:00:00 2001 From: dongfang <1136005348@qq.com> Date: Thu, 13 Feb 2025 00:54:24 +0000 Subject: [PATCH 2/5] support create uptime with json validation --- Client/src/Pages/Uptime/Create/index.jsx | 69 ++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/Client/src/Pages/Uptime/Create/index.jsx b/Client/src/Pages/Uptime/Create/index.jsx index a0fcce43b..354dfef29 100644 --- a/Client/src/Pages/Uptime/Create/index.jsx +++ b/Client/src/Pages/Uptime/Create/index.jsx @@ -93,6 +93,12 @@ const CreateMonitor = () => { interval: monitor.interval * MS_PER_MINUTE, }; + if (monitor.type === "http") { + form.expectedValue = monitor.expectedValue; + form.jsonPath = monitor.jsonPath; + form.matchMethod = monitor.matchMethod; + } + const { error } = monitorValidation.validate(form, { abortEarly: false, }); @@ -399,6 +405,69 @@ const CreateMonitor = () => { onChange={(event) => handleChange(event, "interval")} items={SELECT_VALUES} /> + { + monitor.type === "http" && <> + handleChange(event, "matchMethod")} + items={[ + { _id: "equal", name: "Equal" }, + { _id: "include", name: "Include" }, + { _id: "regex", name: "Regex" }, + ]} + /> + + handleChange(event, "expectedValue")} + error={errors["expectedValue"] ? true : false} + helperText={errors["expectedValue"]} + /> + + The expected value is used to match the response result, and the result determines the status. + + + + handleChange(event, "jsonPath")} + error={errors["jsonPath"] ? true : false} + helperText={errors["jsonPath"]} + /> + + The expression is evaluated against the reponse JSON data and the result will get used to match with expected value. Check out  + + jmespath.org + +  for the documentation about the query language. + + + + } Date: Thu, 13 Feb 2025 00:56:16 +0000 Subject: [PATCH 4/5] allow empty string for json validation in server side --- Server/validation/joi.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Server/validation/joi.js b/Server/validation/joi.js index b60022fc5..c0ccc1fe9 100644 --- a/Server/validation/joi.js +++ b/Server/validation/joi.js @@ -194,8 +194,8 @@ const createMonitorBodyValidation = joi.object({ }), notifications: joi.array().items(joi.object()), secret: joi.string(), - jsonPath: joi.string(), - expectedValue: joi.string(), + jsonPath: joi.string().allow(""), + expectedValue: joi.string().allow(""), matchMethod: joi.string(), }); @@ -205,8 +205,8 @@ const editMonitorBodyValidation = joi.object({ interval: joi.number(), notifications: joi.array().items(joi.object()), secret: joi.string(), - jsonPath: joi.string(), - expectedValue: joi.string(), + jsonPath: joi.string().allow(""), + expectedValue: joi.string().allow(""), matchMethod: joi.string(), }); From 133468c36e7d202fac41e83fecd315a6cc3abd75 Mon Sep 17 00:00:00 2001 From: dongfang <1136005348@qq.com> Date: Fri, 14 Feb 2025 02:45:24 +0000 Subject: [PATCH 5/5] refactor some constants and change descriptions --- Client/src/Pages/Uptime/Configure/index.jsx | 30 ++++++++++++--------- Client/src/Pages/Uptime/Create/index.jsx | 30 ++++++++++++--------- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/Client/src/Pages/Uptime/Configure/index.jsx b/Client/src/Pages/Uptime/Configure/index.jsx index 85c43902f..b1121cabf 100644 --- a/Client/src/Pages/Uptime/Configure/index.jsx +++ b/Client/src/Pages/Uptime/Configure/index.jsx @@ -62,6 +62,18 @@ const Configure = () => { "notify-email-default": "notification-email", }; + const matchMethodOptions = [ + { _id: "equal", name: "Equal" }, + { _id: "include", name: "Include" }, + { _id: "regex", name: "Regex" }, + ]; + + const expectedValuePlaceholders = { + regex: "^[\w.-]+@gmail.com$", + equal: "janet@gmail.com", + include: "@gmail.com" + }; + useEffect(() => { const fetchMonitor = async () => { try { @@ -443,11 +455,7 @@ const Configure = () => { label="Match Method" value={monitor.matchMethod || "equal"} onChange={(event) => handleChange(event, "matchMethod")} - items={[ - { _id: "equal", name: "Equal" }, - { _id: "include", name: "Include" }, - { _id: "regex", name: "Regex" }, - ]} + items={matchMethodOptions} /> { id="expected-value" label="Expected value" isOptional={true} - placeholder={{ - regex: "^[\w.-]+@gmail.com$", - equal: "janet@gmail.com", - include: "@gmail.com" - }[monitor.matchMethod || "equal"]} + placeholder={expectedValuePlaceholders[monitor.matchMethod || "equal"]} value={monitor.expectedValue} onChange={(event) => handleChange(event, "expectedValue")} error={errors["expectedValue"] ? true : false} @@ -470,7 +474,7 @@ const Configure = () => { color={theme.palette.primary.contrastTextTertiary} opacity={0.8} > - The expected value is used to match the response result, and the result determines the status. + The expected value is used to match against response result, and the match determines the status. @@ -490,11 +494,11 @@ const Configure = () => { color={theme.palette.primary.contrastTextTertiary} opacity={0.8} > - The expression is evaluated against the reponse JSON data and the result will get used to match with expected value. Check out  + This expression will be evaluated against the reponse JSON data and the result will be used to match against the expected value. See  jmespath.org -  for the documentation about the query language. +  for query language documentation. diff --git a/Client/src/Pages/Uptime/Create/index.jsx b/Client/src/Pages/Uptime/Create/index.jsx index 354dfef29..2d2904291 100644 --- a/Client/src/Pages/Uptime/Create/index.jsx +++ b/Client/src/Pages/Uptime/Create/index.jsx @@ -34,6 +34,18 @@ const CreateMonitor = () => { { _id: 5, name: "5 minutes" }, ]; + const matchMethodOptions = [ + { _id: "equal", name: "Equal" }, + { _id: "include", name: "Include" }, + { _id: "regex", name: "Regex" }, + ]; + + const expectedValuePlaceholders = { + regex: "^[\w.-]+@gmail.com$", + equal: "janet@gmail.com", + include: "@gmail.com" + }; + const monitorTypeMaps = { http: { label: "URL to monitor", @@ -412,11 +424,7 @@ const CreateMonitor = () => { label="Match Method" value={monitor.matchMethod || "equal"} onChange={(event) => handleChange(event, "matchMethod")} - items={[ - { _id: "equal", name: "Equal" }, - { _id: "include", name: "Include" }, - { _id: "regex", name: "Regex" }, - ]} + items={matchMethodOptions} /> { id="expected-value" label="Expected value" isOptional={true} - placeholder={{ - regex: "^[\w.-]+@gmail.com$", - equal: "janet@gmail.com", - include: "@gmail.com" - }[monitor.matchMethod || "equal"]} + placeholder={expectedValuePlaceholders[monitor.matchMethod || "equal"]} value={monitor.expectedValue} onChange={(event) => handleChange(event, "expectedValue")} error={errors["expectedValue"] ? true : false} @@ -439,7 +443,7 @@ const CreateMonitor = () => { color={theme.palette.primary.contrastTextTertiary} opacity={0.8} > - The expected value is used to match the response result, and the result determines the status. + The expected value is used to match against response result, and the match determines the status. @@ -459,11 +463,11 @@ const CreateMonitor = () => { color={theme.palette.primary.contrastTextTertiary} opacity={0.8} > - The expression is evaluated against the reponse JSON data and the result will get used to match with expected value. Check out  + This expression will be evaluated against the reponse JSON data and the result will be used to match against the expected value. See  jmespath.org -  for the documentation about the query language. +  for query language documentation.