- WIP add memory and disk usage

This commit is contained in:
Shemy Gan committed 2024-11-11 11:16:06 -05:00
1 parent 2aa792d820
commit 7bbd984fcf
3 files changed
+28 -10

No files matched your search

@@ -116,16 +116,18 @@ const CreateInfrastructureMonitor = () => {
}); });
}; };
const handleBlur = (event) => { const handleBlur = (event, appenedID) => {
event.preventDefault();
const { value, id } = event.target; const { value, id } = event.target;
if (id?.startsWith("notify-email-")) return;
const { error } = infrastractureMonitorValidation.validate( const { error } = infrastractureMonitorValidation.validate(
{ [id]: value }, { [id ?? appenedID]: value },
{ {
abortEarly: false, abortEarly: false,
} }
); );
setErrors((prev) => { setErrors((prev) => {
return buildErrors(prev, id, error); return buildErrors(prev, id ?? appenedID, error);
}); });
}; };
@@ -202,7 +204,7 @@ const CreateInfrastructureMonitor = () => {
if (hasValidationErrors(form, infrastractureMonitorValidation, setErrors)) { if (hasValidationErrors(form, infrastractureMonitorValidation, setErrors)) {
return; return;
} else { } else {
const checkEndpointAction = await dispatch( const checkEndpointAction = dispatch(
checkInfrastructureEndpointResolution({ authToken, monitorURL: form.url }) checkInfrastructureEndpointResolution({ authToken, monitorURL: form.url })
); );
if (checkEndpointAction.meta.requestStatus === "rejected") { if (checkEndpointAction.meta.requestStatus === "rejected") {
@@ -212,7 +214,7 @@ const CreateInfrastructureMonitor = () => {
setErrors({ url: "The entered URL is not reachable." }); setErrors({ url: "The entered URL is not reachable." });
return; return;
} }
const action = await dispatch( const action = dispatch(
createInfrastructureMonitor({ authToken, monitor: generatePayload(form) }) createInfrastructureMonitor({ authToken, monitor: generatePayload(form) })
); );
if (action.meta.requestStatus === "fulfilled") { if (action.meta.requestStatus === "fulfilled") {
@@ -372,7 +374,7 @@ const CreateInfrastructureMonitor = () => {
onBlur={handleBlur} onBlur={handleBlur}
alertUnit="%" alertUnit="%"
/> />
{/* <CustomAlertStack <CustomAlertStack
checkboxId="memory" checkboxId="memory"
checkboxLabel="Memory" checkboxLabel="Memory"
checkboxValue={""} checkboxValue={""}
@@ -391,7 +393,7 @@ const CreateInfrastructureMonitor = () => {
onChange={handleChange} onChange={handleChange}
onBlur={handleBlur} onBlur={handleBlur}
alertUnit="%" alertUnit="%"
/> */} />
{/* <CustomAlertStack {/* <CustomAlertStack
checkboxId="customize-temperature" checkboxId="customize-temperature"
checkboxLabel="Temperature" checkboxLabel="Temperature"
@@ -448,7 +450,7 @@ const CreateInfrastructureMonitor = () => {
label="Check frequency" label="Check frequency"
value={infrastructureMonitor.interval || 15} value={infrastructureMonitor.interval || 15}
onChange={(e) => handleChange(e, "interval")} onChange={(e) => handleChange(e, "interval")}
onBlur={handleBlur} onBlur={(e) => handleBlur(e, "interval")}
items={frequencies} items={frequencies}
/> />
{/* <Field {/* <Field
+8
View File
@@ -22,14 +22,22 @@ const hasValidationErrors = (form, validation, setErrors) => {
"dbConnectionString", "dbConnectionString",
"refreshTokenTTL", "refreshTokenTTL",
"jwtTTL", "jwtTTL",
"notify-email-list",
].includes(err.path[0]) ].includes(err.path[0])
) { ) {
newErrors[err.path[0]] = err.message ?? "Validation error"; newErrors[err.path[0]] = err.message ?? "Validation error";
} }
// Handle conditionally usage number required cases // Handle conditionally usage number required cases
if (!form.cpu || (form.cpu && form.usage_cpu)) { if (!form.cpu || (form.cpu && form.usage_cpu)) {
delete newErrors["usage_cpu"]; delete newErrors["usage_cpu"];
} }
if (!form.memory || (form.memory && form.usage_memory)) {
delete newErrors["usage_memory"];
}
if (!form.disk || (form.disk && form.usage_disk)) {
delete newErrors["usage_disk"];
}
}); });
if (Object.keys(newErrors).length > 0) { if (Object.keys(newErrors).length > 0) {
setErrors(newErrors); setErrors(newErrors);
+10 -2
View File
@@ -187,8 +187,16 @@ const infrastractureMonitorValidation = joi.object({
"any.required": "CPU threshold is required.", "any.required": "CPU threshold is required.",
}), }),
cpu:joi.boolean(), cpu:joi.boolean(),
// usage_memory: joi.number(), memory:joi.boolean(),
// usage_disk: joi.number(), disk:joi.boolean(),
usage_memory: joi.number().messages({
"number.base": "Memory threshold must be a number.",
"any.required": "Memory threshold is required.",
}),
usage_disk: joi.number().messages({
"number.base": "Disk threshold must be a number.",
"any.required": "Disk threshold is required.",
}),
// usage_temperature: joi.number().messages({ // usage_temperature: joi.number().messages({
// "number.base": "Temperature must be a number.", // "number.base": "Temperature must be a number.",
// }), // }),