mirror of
https://github.com/bluewave-labs/Checkmate.git
synced 2026-05-08 01:30:01 -05:00
Add pause routes and controller, implement functionality
This commit is contained in:
@@ -264,7 +264,7 @@ const Configure = () => {
|
|||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
level="tertiary"
|
level="tertiary"
|
||||||
label="Pause"
|
label={monitor?.isActive ? "Pause" : "Resume"}
|
||||||
animate="rotate180"
|
animate="rotate180"
|
||||||
img={<PauseCircleOutlineIcon />}
|
img={<PauseCircleOutlineIcon />}
|
||||||
sx={{
|
sx={{
|
||||||
|
|||||||
@@ -24,11 +24,20 @@ const Monitors = ({ isAdmin }) => {
|
|||||||
dispatch(getUptimeMonitorsByTeamId(authState.authToken));
|
dispatch(getUptimeMonitorsByTeamId(authState.authToken));
|
||||||
}, [authState.authToken, dispatch]);
|
}, [authState.authToken, dispatch]);
|
||||||
|
|
||||||
const up = monitorState.monitors.reduce((acc, cur) => {
|
const monitorStats = monitorState.monitors.reduce(
|
||||||
return cur.status === true ? acc + 1 : acc;
|
(acc, monitor) => {
|
||||||
}, 0);
|
if (monitor.isActive === false) {
|
||||||
|
acc["paused"] += 1;
|
||||||
|
} else if (monitor.status === true) {
|
||||||
|
acc["up"] += 1;
|
||||||
|
} else {
|
||||||
|
acc["down"] += 1;
|
||||||
|
}
|
||||||
|
return acc;
|
||||||
|
},
|
||||||
|
{ paused: 0, up: 0, down: 0 }
|
||||||
|
);
|
||||||
|
|
||||||
const down = monitorState.monitors.length - up;
|
|
||||||
const data = buildData(monitorState.monitors, isAdmin, navigate);
|
const data = buildData(monitorState.monitors, isAdmin, navigate);
|
||||||
|
|
||||||
let loading = monitorState.isLoading && monitorState.monitors.length === 0;
|
let loading = monitorState.isLoading && monitorState.monitors.length === 0;
|
||||||
@@ -73,9 +82,9 @@ const Monitors = ({ isAdmin }) => {
|
|||||||
direction="row"
|
direction="row"
|
||||||
justifyContent="space-between"
|
justifyContent="space-between"
|
||||||
>
|
>
|
||||||
<StatusBox title="up" value={up} />
|
<StatusBox title="up" value={monitorStats.up} />
|
||||||
<StatusBox title="down" value={down} />
|
<StatusBox title="down" value={monitorStats.down} />
|
||||||
<StatusBox title="paused" value={0} />
|
<StatusBox title="paused" value={monitorStats.paused} />
|
||||||
</Stack>
|
</Stack>
|
||||||
<Box
|
<Box
|
||||||
flex={1}
|
flex={1}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ const {
|
|||||||
createMonitorBodyValidation,
|
createMonitorBodyValidation,
|
||||||
editMonitorBodyValidation,
|
editMonitorBodyValidation,
|
||||||
getMonitorsByTeamIdQueryValidation,
|
getMonitorsByTeamIdQueryValidation,
|
||||||
|
pauseMonitorParamValidation,
|
||||||
} = require("../validation/joi");
|
} = require("../validation/joi");
|
||||||
|
|
||||||
const sslChecker = require("ssl-checker");
|
const sslChecker = require("ssl-checker");
|
||||||
@@ -309,7 +310,7 @@ const editMonitor = async (req, res, next) => {
|
|||||||
// Get notifications from the request body
|
// Get notifications from the request body
|
||||||
const notifications = req.body.notifications;
|
const notifications = req.body.notifications;
|
||||||
|
|
||||||
const editedMonitor = await req.db.editMonitor(req, res);
|
const editedMonitor = await req.db.editMonitor(monitorId, req.body);
|
||||||
|
|
||||||
await req.db.deleteNotificationsByMonitorId(editedMonitor._id);
|
await req.db.deleteNotificationsByMonitorId(editedMonitor._id);
|
||||||
|
|
||||||
@@ -337,6 +338,43 @@ const editMonitor = async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const pauseMonitor = async (req, res, next) => {
|
||||||
|
try {
|
||||||
|
await pauseMonitorParamValidation.validateAsync(req.params);
|
||||||
|
} catch (error) {
|
||||||
|
error.status = 422;
|
||||||
|
error.service = SERVICE_NAME;
|
||||||
|
error.message =
|
||||||
|
error.details?.[0]?.message || error.message || "Validation Error";
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const monitor = await req.db.getMonitorById(req.params.monitorId);
|
||||||
|
if (monitor.isActive) {
|
||||||
|
await req.jobQueue.deleteJob(monitor);
|
||||||
|
} else {
|
||||||
|
await req.jobQueue.addJob(monitor._id, monitor);
|
||||||
|
}
|
||||||
|
monitor.isActive = !monitor.isActive;
|
||||||
|
const updatedMonitor = await req.db.editMonitor(
|
||||||
|
req.params.monitorId,
|
||||||
|
monitor
|
||||||
|
);
|
||||||
|
return res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
msg: updatedMonitor.isActive
|
||||||
|
? successMessages.MONITOR_RESUME
|
||||||
|
: successMessages.MONITOR_PAUSE,
|
||||||
|
data: updatedMonitor,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
error.service = SERVICE_NAME;
|
||||||
|
error.method = "pauseMonitor";
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getAllMonitors,
|
getAllMonitors,
|
||||||
getMonitorStatsById,
|
getMonitorStatsById,
|
||||||
@@ -347,4 +385,5 @@ module.exports = {
|
|||||||
deleteMonitor,
|
deleteMonitor,
|
||||||
deleteAllMonitors,
|
deleteAllMonitors,
|
||||||
editMonitor,
|
editMonitor,
|
||||||
|
pauseMonitor,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ const { NormalizeData } = require("../../../utils/dataUtils");
|
|||||||
*/
|
*/
|
||||||
const getAllMonitors = async (req, res) => {
|
const getAllMonitors = async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const monitors = await Monitor.find({ isActive: true });
|
const monitors = await Monitor.find();
|
||||||
return monitors;
|
return monitors;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
@@ -431,9 +431,7 @@ const deleteMonitorsByUserId = async (userId) => {
|
|||||||
* @returns {Promise<Monitor>}
|
* @returns {Promise<Monitor>}
|
||||||
* @throws {Error}
|
* @throws {Error}
|
||||||
*/
|
*/
|
||||||
const editMonitor = async (req, res) => {
|
const editMonitor = async (candidateId, candidateMonitor) => {
|
||||||
const candidateId = req.params.monitorId;
|
|
||||||
const candidateMonitor = req.body;
|
|
||||||
candidateMonitor.notifications = undefined;
|
candidateMonitor.notifications = undefined;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -31,4 +31,11 @@ router.delete(
|
|||||||
isAllowed(["superadmin"]),
|
isAllowed(["superadmin"]),
|
||||||
monitorController.deleteAllMonitors
|
monitorController.deleteAllMonitors
|
||||||
);
|
);
|
||||||
|
|
||||||
|
router.post(
|
||||||
|
"/pause/:monitorId",
|
||||||
|
isAllowed(["admin", "superadmin"]),
|
||||||
|
monitorController.pauseMonitor
|
||||||
|
);
|
||||||
|
|
||||||
module.exports = router;
|
module.exports = router;
|
||||||
|
|||||||
@@ -87,6 +87,8 @@ const successMessages = {
|
|||||||
//Job Queue
|
//Job Queue
|
||||||
JOB_QUEUE_DELETE_JOB: "Job removed successfully",
|
JOB_QUEUE_DELETE_JOB: "Job removed successfully",
|
||||||
JOB_QUEUE_OBLITERATE: "Queue OBLITERATED!!!",
|
JOB_QUEUE_OBLITERATE: "Queue OBLITERATED!!!",
|
||||||
|
JOB_QUEUE_PAUSE_JOB: "Job paused successfully",
|
||||||
|
JOB_QUEUE_RESUME_JOB: "Job resumed successfully",
|
||||||
|
|
||||||
//Maintenance Window Controller
|
//Maintenance Window Controller
|
||||||
MAINTENANCE_WINDOW_CREATE: "Maintenance Window created successfully",
|
MAINTENANCE_WINDOW_CREATE: "Maintenance Window created successfully",
|
||||||
|
|||||||
@@ -197,6 +197,10 @@ const editMonitorBodyValidation = joi.object({
|
|||||||
notifications: joi.array().items(joi.object()),
|
notifications: joi.array().items(joi.object()),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const pauseMonitorParamValidation = joi.object({
|
||||||
|
monitorId: joi.string().required(),
|
||||||
|
});
|
||||||
|
|
||||||
//****************************************
|
//****************************************
|
||||||
// Alerts
|
// Alerts
|
||||||
//****************************************
|
//****************************************
|
||||||
@@ -350,6 +354,7 @@ module.exports = {
|
|||||||
getMonitorsByTeamIdValidation,
|
getMonitorsByTeamIdValidation,
|
||||||
getMonitorsByTeamIdQueryValidation,
|
getMonitorsByTeamIdQueryValidation,
|
||||||
editMonitorBodyValidation,
|
editMonitorBodyValidation,
|
||||||
|
pauseMonitorParamValidation,
|
||||||
editUserParamValidation,
|
editUserParamValidation,
|
||||||
editUserBodyValidation,
|
editUserBodyValidation,
|
||||||
createAlertParamValidation,
|
createAlertParamValidation,
|
||||||
|
|||||||
Reference in New Issue
Block a user