Add temperature threshold to create infrastructure monitor page

This commit is contained in:
Alex Holliday committed 2024-11-25 11:20:52 +08:00
1 parent 24d5a38527
commit 71cde317a7
4 files changed
+20 -10

No files matched your search

@@ -32,12 +32,14 @@ const CreateInfrastructureMonitor = () => {
usage_memory: "", usage_memory: "",
disk: false, disk: false,
usage_disk: "", usage_disk: "",
temperature: false,
usage_temperature: "",
secret: "", secret: "",
}); });
const MS_PER_MINUTE = 60000; const MS_PER_MINUTE = 60000;
const THRESHOLD_FIELD_PREFIX = "usage_"; const THRESHOLD_FIELD_PREFIX = "usage_";
const HARDWARE_MONITOR_TYPES = ["cpu", "memory", "disk"]; const HARDWARE_MONITOR_TYPES = ["cpu", "memory", "disk", "temperature"];
const { user, authToken } = useSelector((state) => state.auth); const { user, authToken } = useSelector((state) => state.auth);
const monitorState = useSelector((state) => state.infrastructureMonitor); const monitorState = useSelector((state) => state.infrastructureMonitor);
const dispatch = useDispatch(); const dispatch = useDispatch();
@@ -74,18 +76,18 @@ const CreateInfrastructureMonitor = () => {
}); });
}; };
const handleBlur = (event, appenedID) => { const handleBlur = (event, appendID) => {
event.preventDefault(); event.preventDefault();
const { value, id } = event.target; const { value, id } = event.target;
if (id?.startsWith("notify-email-")) return; if (id?.startsWith("notify-email-")) return;
const { error } = infrastructureMonitorValidation.validate( const { error } = infrastructureMonitorValidation.validate(
{ [id ?? appenedID]: value }, { [id ?? appendID]: value },
{ {
abortEarly: false, abortEarly: false,
} }
); );
setErrors((prev) => { setErrors((prev) => {
return buildErrors(prev, id ?? appenedID, error); return buildErrors(prev, id ?? appendID, error);
}); });
}; };
@@ -297,7 +299,8 @@ const CreateInfrastructureMonitor = () => {
<Box> <Box>
<Typography component="h2">Customize alerts</Typography> <Typography component="h2">Customize alerts</Typography>
<Typography component="p"> <Typography component="p">
Send a notification to user(s) when thresholds exceed a specified percentage. Send a notification to user(s) when thresholds exceed a specified
percentage.
</Typography> </Typography>
</Box> </Box>
<Stack gap={theme.spacing(6)}> <Stack gap={theme.spacing(6)}>
+7 -2
View File
@@ -37,8 +37,13 @@ const hasValidationErrors = (form, validation, setErrors) => {
if (!form.disk || form.usage_disk) { if (!form.disk || form.usage_disk) {
newErrors["usage_disk"] = null; newErrors["usage_disk"] = null;
} }
if (!form.temperature || form.usage_temperature) {
newErrors["usage_temperature"] = null;
}
}); });
if (Object.values(newErrors).some(v=> v)) {
console.log("newErrors", newErrors);
if (Object.values(newErrors).some((v) => v)) {
setErrors(newErrors); setErrors(newErrors);
return true; return true;
} else { } else {
@@ -48,4 +53,4 @@ const hasValidationErrors = (form, validation, setErrors) => {
} }
return false; return false;
}; };
export { buildErrors, hasValidationErrors }; export { buildErrors, hasValidationErrors };
+4 -3
View File
@@ -190,15 +190,16 @@ const infrastructureMonitorValidation = joi.object({
cpu: joi.boolean(), cpu: joi.boolean(),
memory: joi.boolean(), memory: joi.boolean(),
disk: joi.boolean(), disk: joi.boolean(),
temperature: joi.boolean(),
usage_memory: joi.number().messages({ usage_memory: joi.number().messages({
"number.base": THRESHOLD_COMMON_BASE_MSG, "number.base": THRESHOLD_COMMON_BASE_MSG,
}), }),
usage_disk: joi.number().messages({ usage_disk: joi.number().messages({
"number.base": THRESHOLD_COMMON_BASE_MSG, "number.base": THRESHOLD_COMMON_BASE_MSG,
}), }),
// usage_temperature: joi.number().messages({ usage_temperature: joi.number().messages({
// "number.base": "Temperature must be a number.", "number.base": "Temperature must be a number.",
// }), }),
// usage_system: joi.number().messages({ // usage_system: joi.number().messages({
// "number.base": "System load must be a number.", // "number.base": "System load must be a number.",
// }), // }),
+1
View File
@@ -201,6 +201,7 @@ const createMonitorBodyValidation = joi.object({
usage_cpu: joi.number(), usage_cpu: joi.number(),
usage_memory: joi.number(), usage_memory: joi.number(),
usage_disk: joi.number(), usage_disk: joi.number(),
usage_temperature: joi.number(),
}), }),
notifications: joi.array().items(joi.object()), notifications: joi.array().items(joi.object()),
secret: joi.string(), secret: joi.string(),