Merge pull request #946 from om-3004/enhancement/check-if-url-resolves
check if the url resolves before adding the monitor
This commit is contained in:
10 files changed
+828
-360
No files matched your search
@@ -31,6 +31,30 @@ export const createPageSpeed = createAsyncThunk(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const checkEndpointResolution = createAsyncThunk(
|
||||||
|
"monitors/checkEndpoint",
|
||||||
|
async (data, thunkApi) => {
|
||||||
|
try {
|
||||||
|
const { authToken, monitorURL } = data;
|
||||||
|
|
||||||
|
const res = await networkService.checkEndpointResolution({
|
||||||
|
authToken: authToken,
|
||||||
|
monitorURL: monitorURL,
|
||||||
|
})
|
||||||
|
return res.data;
|
||||||
|
} catch (error) {
|
||||||
|
if (error.response && error.response.data) {
|
||||||
|
return thunkApi.rejectWithValue(error.response.data);
|
||||||
|
}
|
||||||
|
const payload = {
|
||||||
|
status: false,
|
||||||
|
msg: error.message ? error.message : "Unknown error",
|
||||||
|
};
|
||||||
|
return thunkApi.rejectWithValue(payload);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
export const getPagespeedMonitorById = createAsyncThunk(
|
export const getPagespeedMonitorById = createAsyncThunk(
|
||||||
"monitors/getMonitorById",
|
"monitors/getMonitorById",
|
||||||
async (data, thunkApi) => {
|
async (data, thunkApi) => {
|
||||||
@@ -222,7 +246,24 @@ const pageSpeedMonitorSlice = createSlice({
|
|||||||
? action.payload.msg
|
? action.payload.msg
|
||||||
: "Failed to create page speed monitor";
|
: "Failed to create page speed monitor";
|
||||||
})
|
})
|
||||||
|
// *****************************************************
|
||||||
|
// Resolve Endpoint
|
||||||
|
// *****************************************************
|
||||||
|
.addCase(checkEndpointResolution.pending, (state) => {
|
||||||
|
state.isLoading = true;
|
||||||
|
})
|
||||||
|
.addCase(checkEndpointResolution.fulfilled, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.success = action.payload.success;
|
||||||
|
state.msg = action.payload.msg;
|
||||||
|
})
|
||||||
|
.addCase(checkEndpointResolution.rejected, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.success = false;
|
||||||
|
state.msg = action.payload
|
||||||
|
? action.payload.msg
|
||||||
|
: "Failed to check endpoint resolution";
|
||||||
|
})
|
||||||
// *****************************************************
|
// *****************************************************
|
||||||
// Update Monitor
|
// Update Monitor
|
||||||
// *****************************************************
|
// *****************************************************
|
||||||
|
|||||||
@@ -31,6 +31,30 @@ export const createUptimeMonitor = createAsyncThunk(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
export const checkEndpointResolution = createAsyncThunk(
|
||||||
|
"monitors/checkEndpoint",
|
||||||
|
async (data, thunkApi) => {
|
||||||
|
try {
|
||||||
|
const { authToken, monitorURL } = data;
|
||||||
|
|
||||||
|
const res = await networkService.checkEndpointResolution({
|
||||||
|
authToken: authToken,
|
||||||
|
monitorURL: monitorURL,
|
||||||
|
})
|
||||||
|
return res.data;
|
||||||
|
} catch (error) {
|
||||||
|
if (error.response && error.response.data) {
|
||||||
|
return thunkApi.rejectWithValue(error.response.data);
|
||||||
|
}
|
||||||
|
const payload = {
|
||||||
|
status: false,
|
||||||
|
msg: error.message ? error.message : "Unknown error",
|
||||||
|
};
|
||||||
|
return thunkApi.rejectWithValue(payload);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
export const getUptimeMonitorById = createAsyncThunk(
|
export const getUptimeMonitorById = createAsyncThunk(
|
||||||
"monitors/getMonitorById",
|
"monitors/getMonitorById",
|
||||||
async (data, thunkApi) => {
|
async (data, thunkApi) => {
|
||||||
@@ -271,6 +295,24 @@ const uptimeMonitorsSlice = createSlice({
|
|||||||
: "Failed to create uptime monitor";
|
: "Failed to create uptime monitor";
|
||||||
})
|
})
|
||||||
// *****************************************************
|
// *****************************************************
|
||||||
|
// Resolve Endpoint
|
||||||
|
// *****************************************************
|
||||||
|
.addCase(checkEndpointResolution.pending, (state) => {
|
||||||
|
state.isLoading = true;
|
||||||
|
})
|
||||||
|
.addCase(checkEndpointResolution.fulfilled, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.success = action.payload.success;
|
||||||
|
state.msg = action.payload.msg;
|
||||||
|
})
|
||||||
|
.addCase(checkEndpointResolution.rejected, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.success = false;
|
||||||
|
state.msg = action.payload
|
||||||
|
? action.payload.msg
|
||||||
|
: "Failed to check endpoint resolution";
|
||||||
|
})
|
||||||
|
// *****************************************************
|
||||||
// Get Monitor By Id
|
// Get Monitor By Id
|
||||||
// *****************************************************
|
// *****************************************************
|
||||||
.addCase(getUptimeMonitorById.pending, (state) => {
|
.addCase(getUptimeMonitorById.pending, (state) => {
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { Box, Button, ButtonGroup, Stack, Typography } from "@mui/material";
|
import { Box, Button, ButtonGroup, Stack, Typography } from "@mui/material";
|
||||||
|
import LoadingButton from '@mui/lab/LoadingButton';
|
||||||
import { useSelector, useDispatch } from "react-redux";
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
import { monitorValidation } from "../../../Validation/validation";
|
import { monitorValidation } from "../../../Validation/validation";
|
||||||
import { createUptimeMonitor } from "../../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
import { createUptimeMonitor } from "../../../Features/UptimeMonitors/uptimeMonitorsSlice";
|
||||||
|
import { checkEndpointResolution } from "../../../Features/UptimeMonitors/uptimeMonitorsSlice"
|
||||||
import { useNavigate, useParams } from "react-router-dom";
|
import { useNavigate, useParams } from "react-router-dom";
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { createToast } from "../../../Utils/toastUtils";
|
import { createToast } from "../../../Utils/toastUtils";
|
||||||
@@ -17,12 +19,12 @@ import { getUptimeMonitorById } from "../../../Features/UptimeMonitors/uptimeMon
|
|||||||
import "./index.css";
|
import "./index.css";
|
||||||
|
|
||||||
const CreateMonitor = () => {
|
const CreateMonitor = () => {
|
||||||
const MS_PER_MINUTE = 60000;
|
const MS_PER_MINUTE = 60000;
|
||||||
const { user, authToken } = useSelector((state) => state.auth);
|
const { user, authToken } = useSelector((state) => state.auth);
|
||||||
const { monitors } = useSelector((state) => state.uptimeMonitors);
|
const { monitors, isLoading } = useSelector((state) => state.uptimeMonitors);
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
const idMap = {
|
const idMap = {
|
||||||
"monitor-url": "url",
|
"monitor-url": "url",
|
||||||
@@ -146,6 +148,17 @@ const CreateMonitor = () => {
|
|||||||
setErrors(newErrors);
|
setErrors(newErrors);
|
||||||
createToast({ body: "Error validation data." });
|
createToast({ body: "Error validation data." });
|
||||||
} else {
|
} else {
|
||||||
|
if (monitor.type === "http") {
|
||||||
|
const checkEndpointAction = await dispatch(
|
||||||
|
checkEndpointResolution({ authToken, monitorURL: form.url })
|
||||||
|
)
|
||||||
|
if (checkEndpointAction.meta.requestStatus === "rejected") {
|
||||||
|
createToast({ body: "The endpoint you entered doesn't resolve. Check the URL again." });
|
||||||
|
setErrors({ url: "The entered URL is not reachable." });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
form = {
|
form = {
|
||||||
...form,
|
...form,
|
||||||
description: form.name,
|
description: form.name,
|
||||||
@@ -373,14 +386,15 @@ const CreateMonitor = () => {
|
|||||||
direction="row"
|
direction="row"
|
||||||
justifyContent="flex-end"
|
justifyContent="flex-end"
|
||||||
>
|
>
|
||||||
<Button
|
<LoadingButton
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={handleCreateMonitor}
|
onClick={handleCreateMonitor}
|
||||||
disabled={Object.keys(errors).length !== 0 && true}
|
disabled={Object.keys(errors).length !== 0 && true}
|
||||||
>
|
loading={isLoading}
|
||||||
Create monitor
|
>
|
||||||
</Button>
|
Create monitor
|
||||||
|
</LoadingButton>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
import { Box, Button, ButtonGroup, Stack, Typography } from "@mui/material";
|
import { Box, Button, ButtonGroup, Stack, Typography } from "@mui/material";
|
||||||
|
import LoadingButton from '@mui/lab/LoadingButton';
|
||||||
import { useSelector, useDispatch } from "react-redux";
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
import { monitorValidation } from "../../../Validation/validation";
|
import { monitorValidation } from "../../../Validation/validation";
|
||||||
import { useNavigate } from "react-router-dom";
|
import { useNavigate } from "react-router-dom";
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
import { createPageSpeed } from "../../../Features/PageSpeedMonitor/pageSpeedMonitorSlice";
|
import { createPageSpeed, checkEndpointResolution } from "../../../Features/PageSpeedMonitor/pageSpeedMonitorSlice";
|
||||||
import { createToast } from "../../../Utils/toastUtils";
|
import { createToast } from "../../../Utils/toastUtils";
|
||||||
import { logger } from "../../../Utils/Logger";
|
import { logger } from "../../../Utils/Logger";
|
||||||
import { ConfigBox } from "../../Monitors/styled";
|
import { ConfigBox } from "../../Monitors/styled";
|
||||||
@@ -16,11 +17,12 @@ import Breadcrumbs from "../../../Components/Breadcrumbs";
|
|||||||
import "./index.css";
|
import "./index.css";
|
||||||
|
|
||||||
const CreatePageSpeed = () => {
|
const CreatePageSpeed = () => {
|
||||||
const MS_PER_MINUTE = 60000;
|
const MS_PER_MINUTE = 60000;
|
||||||
const { user, authToken } = useSelector((state) => state.auth);
|
const { user, authToken } = useSelector((state) => state.auth);
|
||||||
const dispatch = useDispatch();
|
const { isLoading } = useSelector((state) => state.pageSpeedMonitors);
|
||||||
const navigate = useNavigate();
|
const dispatch = useDispatch();
|
||||||
const theme = useTheme();
|
const navigate = useNavigate();
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
const idMap = {
|
const idMap = {
|
||||||
"monitor-url": "url",
|
"monitor-url": "url",
|
||||||
@@ -103,248 +105,252 @@ const CreatePageSpeed = () => {
|
|||||||
abortEarly: false,
|
abortEarly: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
const newErrors = {};
|
const newErrors = {};
|
||||||
error.details.forEach((err) => {
|
error.details.forEach((err) => {
|
||||||
newErrors[err.path[0]] = err.message;
|
newErrors[err.path[0]] = err.message;
|
||||||
});
|
});
|
||||||
setErrors(newErrors);
|
setErrors(newErrors);
|
||||||
createToast({ body: "Error validation data." });
|
createToast({ body: "Error validation data." });
|
||||||
} else {
|
} else {
|
||||||
form = {
|
const checkEndpointAction = await dispatch(
|
||||||
...form,
|
checkEndpointResolution({ authToken, monitorURL: form.url })
|
||||||
description: form.name,
|
)
|
||||||
teamId: user.teamId,
|
if (checkEndpointAction.meta.requestStatus === "rejected") {
|
||||||
userId: user._id,
|
createToast({ body: "The endpoint you entered doesn't resolve. Check the URL again." });
|
||||||
notifications: monitor.notifications,
|
setErrors({ url: "The entered URL is not reachable." });
|
||||||
};
|
return;
|
||||||
const action = await dispatch(createPageSpeed({ authToken, monitor: form }));
|
}
|
||||||
if (action.meta.requestStatus === "fulfilled") {
|
|
||||||
createToast({ body: "Monitor created successfully!" });
|
|
||||||
navigate("/pagespeed");
|
|
||||||
} else {
|
|
||||||
createToast({ body: "Failed to create monitor." });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
//select values
|
form = {
|
||||||
const frequencies = [
|
...form,
|
||||||
{ _id: 3, name: "3 minutes" },
|
description: form.name,
|
||||||
{ _id: 5, name: "5 minutes" },
|
teamId: user.teamId,
|
||||||
{ _id: 10, name: "10 minutes" },
|
userId: user._id,
|
||||||
{ _id: 20, name: "20 minutes" },
|
notifications: monitor.notifications,
|
||||||
{ _id: 60, name: "1 hour" },
|
};
|
||||||
{ _id: 1440, name: "1 day" },
|
const action = await dispatch(
|
||||||
{ _id: 10080, name: "1 week" },
|
createPageSpeed({ authToken, monitor: form })
|
||||||
];
|
);
|
||||||
return (
|
if (action.meta.requestStatus === "fulfilled") {
|
||||||
<Box
|
createToast({ body: "Monitor created successfully!" });
|
||||||
className="create-monitor"
|
navigate("/pagespeed");
|
||||||
sx={{
|
} else {
|
||||||
"& h1": {
|
createToast({ body: "Failed to create monitor." });
|
||||||
color: theme.palette.text.primary,
|
}
|
||||||
},
|
}
|
||||||
}}
|
};
|
||||||
>
|
|
||||||
<Breadcrumbs
|
//select values
|
||||||
list={[
|
const frequencies = [
|
||||||
{ name: "pagespeed", path: "/pagespeed" },
|
{ _id: 3, name: "3 minutes" },
|
||||||
{ name: "create", path: `/pagespeed/create` },
|
{ _id: 5, name: "5 minutes" },
|
||||||
]}
|
{ _id: 10, name: "10 minutes" },
|
||||||
/>
|
{ _id: 20, name: "20 minutes" },
|
||||||
<Stack
|
{ _id: 60, name: "1 hour" },
|
||||||
component="form"
|
{ _id: 1440, name: "1 day" },
|
||||||
className="create-monitor-form"
|
{ _id: 10080, name: "1 week" },
|
||||||
onSubmit={handleCreateMonitor}
|
];
|
||||||
noValidate
|
return (
|
||||||
spellCheck="false"
|
<Box
|
||||||
gap={theme.spacing(12)}
|
className="create-monitor"
|
||||||
mt={theme.spacing(6)}
|
sx={{
|
||||||
>
|
"& h1": {
|
||||||
<Typography
|
color: theme.palette.text.primary,
|
||||||
component="h1"
|
},
|
||||||
variant="h1"
|
}}
|
||||||
>
|
>
|
||||||
<Typography
|
<Breadcrumbs
|
||||||
component="span"
|
list={[
|
||||||
fontSize="inherit"
|
{ name: "pagespeed", path: "/pagespeed" },
|
||||||
>
|
{ name: "create", path: `/pagespeed/create` },
|
||||||
Create your{" "}
|
]}
|
||||||
</Typography>
|
/>
|
||||||
<Typography
|
<Stack
|
||||||
component="span"
|
component="form"
|
||||||
fontSize="inherit"
|
className="create-monitor-form"
|
||||||
fontWeight="inherit"
|
onSubmit={handleCreateMonitor}
|
||||||
color={theme.palette.text.secondary}
|
noValidate
|
||||||
>
|
spellCheck="false"
|
||||||
pagespeed monitor
|
gap={theme.spacing(12)}
|
||||||
</Typography>
|
mt={theme.spacing(6)}
|
||||||
</Typography>
|
>
|
||||||
<ConfigBox>
|
<Typography component="h1" variant="h1">
|
||||||
<Box>
|
<Typography component="span" fontSize="inherit">
|
||||||
<Typography component="h2">General settings</Typography>
|
Create your{" "}
|
||||||
<Typography component="p">
|
</Typography>
|
||||||
Here you can select the URL of the host, together with the type of monitor.
|
<Typography
|
||||||
</Typography>
|
component="span"
|
||||||
</Box>
|
fontSize="inherit"
|
||||||
<Stack gap={theme.spacing(15)}>
|
fontWeight="inherit"
|
||||||
<Field
|
color={theme.palette.text.secondary}
|
||||||
type={"url"}
|
>
|
||||||
id="monitor-url"
|
pagespeed monitor
|
||||||
label="URL to monitor"
|
</Typography>
|
||||||
https={https}
|
</Typography>
|
||||||
placeholder="google.com"
|
<ConfigBox>
|
||||||
value={monitor.url}
|
<Box>
|
||||||
onChange={handleChange}
|
<Typography component="h2">General settings</Typography>
|
||||||
error={errors["url"]}
|
<Typography component="p">
|
||||||
/>
|
Here you can select the URL of the host, together with the type of
|
||||||
<Field
|
monitor.
|
||||||
type="text"
|
</Typography>
|
||||||
id="monitor-name"
|
</Box>
|
||||||
label="Display name"
|
<Stack gap={theme.spacing(15)}>
|
||||||
isOptional={true}
|
<Field
|
||||||
placeholder="Google"
|
type={"url"}
|
||||||
value={monitor.name}
|
id="monitor-url"
|
||||||
onChange={handleChange}
|
label="URL to monitor"
|
||||||
error={errors["name"]}
|
https={https}
|
||||||
/>
|
placeholder="google.com"
|
||||||
</Stack>
|
value={monitor.url}
|
||||||
</ConfigBox>
|
onChange={handleChange}
|
||||||
<ConfigBox>
|
error={errors["url"]}
|
||||||
<Box>
|
/>
|
||||||
<Typography component="h2">Checks to perform</Typography>
|
<Field
|
||||||
<Typography component="p">
|
type="text"
|
||||||
You can always add or remove checks after adding your site.
|
id="monitor-name"
|
||||||
</Typography>
|
label="Display name"
|
||||||
</Box>
|
isOptional={true}
|
||||||
<Stack gap={theme.spacing(12)}>
|
placeholder="Google"
|
||||||
<Stack gap={theme.spacing(6)}>
|
value={monitor.name}
|
||||||
<Radio
|
onChange={handleChange}
|
||||||
id="monitor-checks-http"
|
error={errors["name"]}
|
||||||
title="Website monitoring"
|
/>
|
||||||
desc="Use HTTP(s) to monitor your website or API endpoint."
|
</Stack>
|
||||||
size="small"
|
</ConfigBox>
|
||||||
value="http"
|
<ConfigBox>
|
||||||
checked={monitor.type === "pagespeed"}
|
<Box>
|
||||||
onChange={(event) => handleChange(event)}
|
<Typography component="h2">Checks to perform</Typography>
|
||||||
/>
|
<Typography component="p">
|
||||||
<ButtonGroup sx={{ ml: "32px" }}>
|
You can always add or remove checks after adding your site.
|
||||||
<Button
|
</Typography>
|
||||||
variant="group"
|
</Box>
|
||||||
filled={https.toString()}
|
<Stack gap={theme.spacing(12)}>
|
||||||
onClick={() => setHttps(true)}
|
<Stack gap={theme.spacing(6)}>
|
||||||
>
|
<Radio
|
||||||
HTTPS
|
id="monitor-checks-http"
|
||||||
</Button>
|
title="Website monitoring"
|
||||||
<Button
|
desc="Use HTTP(s) to monitor your website or API endpoint."
|
||||||
variant="group"
|
size="small"
|
||||||
filled={(!https).toString()}
|
value="http"
|
||||||
onClick={() => setHttps(false)}
|
checked={monitor.type === "pagespeed"}
|
||||||
>
|
onChange={(event) => handleChange(event)}
|
||||||
HTTP
|
/>
|
||||||
</Button>
|
<ButtonGroup sx={{ ml: "32px" }}>
|
||||||
</ButtonGroup>
|
<Button
|
||||||
</Stack>
|
variant="group"
|
||||||
{errors["type"] ? (
|
filled={https.toString()}
|
||||||
<Box className="error-container">
|
onClick={() => setHttps(true)}
|
||||||
<Typography
|
>
|
||||||
component="p"
|
HTTPS
|
||||||
className="input-error"
|
</Button>
|
||||||
color={theme.palette.error.text}
|
<Button
|
||||||
>
|
variant="group"
|
||||||
{errors["type"]}
|
filled={(!https).toString()}
|
||||||
</Typography>
|
onClick={() => setHttps(false)}
|
||||||
</Box>
|
>
|
||||||
) : (
|
HTTP
|
||||||
""
|
</Button>
|
||||||
)}
|
</ButtonGroup>
|
||||||
</Stack>
|
</Stack>
|
||||||
</ConfigBox>
|
{errors["type"] ? (
|
||||||
<ConfigBox>
|
<Box className="error-container">
|
||||||
<Box>
|
<Typography
|
||||||
<Typography component="h2">Incident notifications</Typography>
|
component="p"
|
||||||
<Typography component="p">
|
className="input-error"
|
||||||
When there is an incident, notify users.
|
color={theme.palette.error.text}
|
||||||
</Typography>
|
>
|
||||||
</Box>
|
{errors["type"]}
|
||||||
<Stack gap={theme.spacing(6)}>
|
</Typography>
|
||||||
<Typography component="p">When there is a new incident,</Typography>
|
</Box>
|
||||||
<Checkbox
|
) : (
|
||||||
id="notify-sms"
|
""
|
||||||
label="Notify via SMS (coming soon)"
|
)}
|
||||||
isChecked={false}
|
</Stack>
|
||||||
value=""
|
</ConfigBox>
|
||||||
onChange={() => logger.warn("disabled")}
|
<ConfigBox>
|
||||||
isDisabled={true}
|
<Box>
|
||||||
/>
|
<Typography component="h2">Incident notifications</Typography>
|
||||||
<Checkbox
|
<Typography component="p">
|
||||||
id="notify-email-default"
|
When there is an incident, notify users.
|
||||||
label={`Notify via email (to ${user.email})`}
|
</Typography>
|
||||||
isChecked={monitor.notifications.some(
|
</Box>
|
||||||
(notification) => notification.type === "email"
|
<Stack gap={theme.spacing(6)}>
|
||||||
)}
|
<Typography component="p">When there is a new incident,</Typography>
|
||||||
value={user?.email}
|
<Checkbox
|
||||||
onChange={(event) => handleChange(event)}
|
id="notify-sms"
|
||||||
/>
|
label="Notify via SMS (coming soon)"
|
||||||
<Checkbox
|
isChecked={false}
|
||||||
id="notify-email"
|
value=""
|
||||||
label="Also notify via email to multiple addresses (coming soon)"
|
onChange={() => logger.warn("disabled")}
|
||||||
isChecked={false}
|
isDisabled={true}
|
||||||
value=""
|
/>
|
||||||
onChange={() => logger.warn("disabled")}
|
<Checkbox
|
||||||
isDisabled={true}
|
id="notify-email-default"
|
||||||
/>
|
label={`Notify via email (to ${user.email})`}
|
||||||
{monitor.notifications.some(
|
isChecked={monitor.notifications.some(
|
||||||
(notification) => notification.type === "emails"
|
(notification) => notification.type === "email"
|
||||||
) ? (
|
)}
|
||||||
<Box mx={theme.spacing(16)}>
|
value={user?.email}
|
||||||
<Field
|
onChange={(event) => handleChange(event)}
|
||||||
id="notify-email-list"
|
/>
|
||||||
type="text"
|
<Checkbox
|
||||||
placeholder="name@gmail.com"
|
id="notify-email"
|
||||||
value=""
|
label="Also notify via email to multiple addresses (coming soon)"
|
||||||
onChange={() => logger.warn("disabled")}
|
isChecked={false}
|
||||||
/>
|
value=""
|
||||||
<Typography mt={theme.spacing(4)}>
|
onChange={() => logger.warn("disabled")}
|
||||||
You can separate multiple emails with a comma
|
isDisabled={true}
|
||||||
</Typography>
|
/>
|
||||||
</Box>
|
{monitor.notifications.some(
|
||||||
) : (
|
(notification) => notification.type === "emails"
|
||||||
""
|
) ? (
|
||||||
)}
|
<Box mx={theme.spacing(16)}>
|
||||||
</Stack>
|
<Field
|
||||||
</ConfigBox>
|
id="notify-email-list"
|
||||||
<ConfigBox>
|
type="text"
|
||||||
<Box>
|
placeholder="name@gmail.com"
|
||||||
<Typography component="h2">Advanced settings</Typography>
|
value=""
|
||||||
</Box>
|
onChange={() => logger.warn("disabled")}
|
||||||
<Stack gap={theme.spacing(12)}>
|
/>
|
||||||
<Select
|
<Typography mt={theme.spacing(4)}>
|
||||||
id="monitor-interval"
|
You can separate multiple emails with a comma
|
||||||
label="Check frequency"
|
</Typography>
|
||||||
value={monitor.interval || 3}
|
</Box>
|
||||||
onChange={(event) => handleChange(event, "interval")}
|
) : (
|
||||||
items={frequencies}
|
""
|
||||||
/>
|
)}
|
||||||
</Stack>
|
</Stack>
|
||||||
</ConfigBox>
|
</ConfigBox>
|
||||||
<Stack
|
<ConfigBox>
|
||||||
direction="row"
|
<Box>
|
||||||
justifyContent="flex-end"
|
<Typography component="h2">Advanced settings</Typography>
|
||||||
>
|
</Box>
|
||||||
<Button
|
<Stack gap={theme.spacing(12)}>
|
||||||
variant="contained"
|
<Select
|
||||||
color="primary"
|
id="monitor-interval"
|
||||||
onClick={handleCreateMonitor}
|
label="Check frequency"
|
||||||
disabled={Object.keys(errors).length !== 0 && true}
|
value={monitor.interval || 3}
|
||||||
>
|
onChange={(event) => handleChange(event, "interval")}
|
||||||
Create monitor
|
items={frequencies}
|
||||||
</Button>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Stack>
|
</ConfigBox>
|
||||||
</Box>
|
<Stack direction="row" justifyContent="flex-end">
|
||||||
);
|
<LoadingButton
|
||||||
|
variant="contained"
|
||||||
|
color="primary"
|
||||||
|
onClick={handleCreateMonitor}
|
||||||
|
disabled={Object.keys(errors).length !== 0 && true}
|
||||||
|
loading={isLoading}
|
||||||
|
>
|
||||||
|
Create monitor
|
||||||
|
</LoadingButton>
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default CreatePageSpeed;
|
export default CreatePageSpeed;
|
||||||
@@ -3,7 +3,6 @@ const BASE_URL = import.meta.env.VITE_APP_API_BASE_URL;
|
|||||||
const FALLBACK_BASE_URL = "http://localhost:5000/api/v1";
|
const FALLBACK_BASE_URL = "http://localhost:5000/api/v1";
|
||||||
import { clearAuthState } from "../Features/Auth/authSlice";
|
import { clearAuthState } from "../Features/Auth/authSlice";
|
||||||
import { clearUptimeMonitorState } from "../Features/UptimeMonitors/uptimeMonitorsSlice";
|
import { clearUptimeMonitorState } from "../Features/UptimeMonitors/uptimeMonitorsSlice";
|
||||||
import { logger } from "./Logger";
|
|
||||||
class NetworkService {
|
class NetworkService {
|
||||||
constructor(store, dispatch, navigate) {
|
constructor(store, dispatch, navigate) {
|
||||||
this.store = store;
|
this.store = store;
|
||||||
@@ -89,21 +88,47 @@ class NetworkService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* ************************************
|
* ************************************
|
||||||
* Gets monitors and summary of stats by TeamID
|
* Check the endpoint resolution
|
||||||
* ************************************
|
* ************************************
|
||||||
*
|
*
|
||||||
* @async
|
* @async
|
||||||
* @param {Object} config - The configuration object.
|
* @param {Object} config - The configuration object.
|
||||||
* @param {string} config.authToken - The authorization token to be used in the request header.
|
* @param {string} config.authToken - The authorization token to be used in the request header.
|
||||||
* @param {string} config.teamId - Team ID
|
* @param {Object} config.monitorURL - The monitor url to be sent in the request body.
|
||||||
* @param {Array<string>} config.types - Array of monitor types
|
* @returns {Promise<AxiosResponse>} The response from the axios POST request.
|
||||||
* @returns {Promise<AxiosResponse>} The response from the axios POST request.
|
*/
|
||||||
*/
|
async checkEndpointResolution(config) {
|
||||||
async getMonitorsAndSummaryByTeamId(config) {
|
const { authToken, monitorURL } = config;
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
|
|
||||||
|
if (monitorURL) params.append("monitorURL", monitorURL);
|
||||||
|
|
||||||
|
return this.axiosInstance.get(`/monitors/resolution/url?${params.toString()}`, {
|
||||||
|
headers: {
|
||||||
|
Authorization: `Bearer ${authToken}`,
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* ************************************
|
||||||
|
* Gets monitors and summary of stats by TeamID
|
||||||
|
* ************************************
|
||||||
|
*
|
||||||
|
* @async
|
||||||
|
* @param {Object} config - The configuration object.
|
||||||
|
* @param {string} config.authToken - The authorization token to be used in the request header.
|
||||||
|
* @param {string} config.teamId - Team ID
|
||||||
|
* @param {Array<string>} config.types - Array of monitor types
|
||||||
|
* @returns {Promise<AxiosResponse>} The response from the axios POST request.
|
||||||
|
*/
|
||||||
|
async getMonitorsAndSummaryByTeamId(config) {
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
|
||||||
if (config.types) {
|
if (config.types) {
|
||||||
config.types.forEach((type) => {
|
config.types.forEach((type) => {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
getMonitorByIdQueryValidation,
|
getMonitorByIdQueryValidation,
|
||||||
getMonitorsByTeamIdValidation,
|
getMonitorsByTeamIdValidation,
|
||||||
createMonitorBodyValidation,
|
createMonitorBodyValidation,
|
||||||
|
getMonitorURLByQueryValidation,
|
||||||
editMonitorBodyValidation,
|
editMonitorBodyValidation,
|
||||||
getMonitorsAndSummaryByTeamIdParamValidation,
|
getMonitorsAndSummaryByTeamIdParamValidation,
|
||||||
getMonitorsAndSummaryByTeamIdQueryValidation,
|
getMonitorsAndSummaryByTeamIdQueryValidation,
|
||||||
@@ -13,13 +14,14 @@ import {
|
|||||||
getCertificateParamValidation,
|
getCertificateParamValidation,
|
||||||
} from "../validation/joi.js";
|
} from "../validation/joi.js";
|
||||||
import sslChecker from "ssl-checker";
|
import sslChecker from "ssl-checker";
|
||||||
|
|
||||||
const SERVICE_NAME = "monitorController";
|
|
||||||
import { errorMessages, successMessages } from "../utils/messages.js";
|
import { errorMessages, successMessages } from "../utils/messages.js";
|
||||||
import jwt from "jsonwebtoken";
|
import jwt from "jsonwebtoken";
|
||||||
import { getTokenFromHeaders } from "../utils/utils.js";
|
import { getTokenFromHeaders } from "../utils/utils.js";
|
||||||
import logger from "../utils/logger.js";
|
import logger from "../utils/logger.js";
|
||||||
import { handleError, handleValidationError } from "./controllerUtils.js";
|
import { handleError, handleValidationError } from "./controllerUtils.js";
|
||||||
|
import dns from "dns";
|
||||||
|
|
||||||
|
const SERVICE_NAME = "monitorController";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns all monitors
|
* Returns all monitors
|
||||||
@@ -257,6 +259,44 @@ const createMonitor = async (req, res, next) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if the endpoint can be resolved
|
||||||
|
* @async
|
||||||
|
* @param {Object} req - The Express request object.
|
||||||
|
* @property {Object} req.query - The query parameters of the request.
|
||||||
|
* @param {Object} res - The Express response object.
|
||||||
|
* @param {function} next - The next middleware function.
|
||||||
|
* @returns {Object} The response object with a success status, a message, and the resolution result.
|
||||||
|
* @throws {Error} If there is an error during the process, especially if there is a validation error (422).
|
||||||
|
*/
|
||||||
|
const checkEndpointResolution = async (req, res, next) => {
|
||||||
|
try {
|
||||||
|
await getMonitorURLByQueryValidation.validateAsync(req.query);
|
||||||
|
} catch (error) {
|
||||||
|
next(handleValidationError(error, SERVICE_NAME));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
let { monitorURL } = req.query;
|
||||||
|
monitorURL = new URL(monitorURL);
|
||||||
|
await new Promise((resolve, reject) => {
|
||||||
|
dns.resolve(monitorURL.hostname, (error) => {
|
||||||
|
if (error) {
|
||||||
|
reject(error);
|
||||||
|
}
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
return res.status(200).json({
|
||||||
|
success: true,
|
||||||
|
msg: `URL resolved successfully`,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
next(handleError(error, SERVICE_NAME, "checkEndpointResolution"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a monitor by its ID and also deletes associated checks, alerts, and notifications.
|
* Deletes a monitor by its ID and also deletes associated checks, alerts, and notifications.
|
||||||
* @async
|
* @async
|
||||||
@@ -477,6 +517,7 @@ export {
|
|||||||
getMonitorsAndSummaryByTeamId,
|
getMonitorsAndSummaryByTeamId,
|
||||||
getMonitorsByTeamId,
|
getMonitorsByTeamId,
|
||||||
createMonitor,
|
createMonitor,
|
||||||
|
checkEndpointResolution,
|
||||||
deleteMonitor,
|
deleteMonitor,
|
||||||
deleteAllMonitors,
|
deleteAllMonitors,
|
||||||
editMonitor,
|
editMonitor,
|
||||||
|
|||||||
+302
-62
@@ -22,12 +22,16 @@
|
|||||||
"variables": {
|
"variables": {
|
||||||
"PORT": {
|
"PORT": {
|
||||||
"description": "API Port",
|
"description": "API Port",
|
||||||
"enum": ["5000"],
|
"enum": [
|
||||||
|
"5000"
|
||||||
|
],
|
||||||
"default": "5000"
|
"default": "5000"
|
||||||
},
|
},
|
||||||
"API_PATH": {
|
"API_PATH": {
|
||||||
"description": "API Base Path",
|
"description": "API Base Path",
|
||||||
"enum": ["api/v1"],
|
"enum": [
|
||||||
|
"api/v1"
|
||||||
|
],
|
||||||
"default": "api/v1"
|
"default": "api/v1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -38,7 +42,9 @@
|
|||||||
"variables": {
|
"variables": {
|
||||||
"API_PATH": {
|
"API_PATH": {
|
||||||
"description": "API Base Path",
|
"description": "API Base Path",
|
||||||
"enum": ["api/v1"],
|
"enum": [
|
||||||
|
"api/v1"
|
||||||
|
],
|
||||||
"default": "api/v1"
|
"default": "api/v1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,12 +55,16 @@
|
|||||||
"variables": {
|
"variables": {
|
||||||
"PORT": {
|
"PORT": {
|
||||||
"description": "API Port",
|
"description": "API Port",
|
||||||
"enum": ["5000"],
|
"enum": [
|
||||||
|
"5000"
|
||||||
|
],
|
||||||
"default": "5000"
|
"default": "5000"
|
||||||
},
|
},
|
||||||
"API_PATH": {
|
"API_PATH": {
|
||||||
"description": "API Base Path",
|
"description": "API Base Path",
|
||||||
"enum": ["api/v1"],
|
"enum": [
|
||||||
|
"api/v1"
|
||||||
|
],
|
||||||
"default": "api/v1"
|
"default": "api/v1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,7 +99,9 @@
|
|||||||
"paths": {
|
"paths": {
|
||||||
"/auth/register": {
|
"/auth/register": {
|
||||||
"post": {
|
"post": {
|
||||||
"tags": ["auth"],
|
"tags": [
|
||||||
|
"auth"
|
||||||
|
],
|
||||||
"description": "Register a new user",
|
"description": "Register a new user",
|
||||||
"requestBody": {
|
"requestBody": {
|
||||||
"content": {
|
"content": {
|
||||||
@@ -125,8 +137,23 @@
|
|||||||
},
|
},
|
||||||
"role": {
|
"role": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"enum": [["user"], ["admin"], ["superadmin"], ["Demo"]],
|
"enum": [
|
||||||
"default": ["superadmin"]
|
[
|
||||||
|
"user"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"admin"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"superadmin"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"Demo"
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"default": [
|
||||||
|
"superadmin"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"teamId": {
|
"teamId": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
@@ -173,14 +200,19 @@
|
|||||||
},
|
},
|
||||||
"/auth/login": {
|
"/auth/login": {
|
||||||
"post": {
|
"post": {
|
||||||
"tags": ["auth"],
|
"tags": [
|
||||||
|
"auth"
|
||||||
|
],
|
||||||
"description": "Login with credentials",
|
"description": "Login with credentials",
|
||||||
"requestBody": {
|
"requestBody": {
|
||||||
"content": {
|
"content": {
|
||||||
"application/json": {
|
"application/json": {
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": ["email", "password"],
|
"required": [
|
||||||
|
"email",
|
||||||
|
"password"
|
||||||
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"email": {
|
"email": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
@@ -231,7 +263,9 @@
|
|||||||
},
|
},
|
||||||
"/auth/user/{userId}": {
|
"/auth/user/{userId}": {
|
||||||
"put": {
|
"put": {
|
||||||
"tags": ["auth"],
|
"tags": [
|
||||||
|
"auth"
|
||||||
|
],
|
||||||
"description": "Change user information",
|
"description": "Change user information",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
@@ -292,7 +326,9 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"delete": {
|
"delete": {
|
||||||
"tags": ["auth"],
|
"tags": [
|
||||||
|
"auth"
|
||||||
|
],
|
||||||
"description": "Delete user",
|
"description": "Delete user",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
@@ -345,7 +381,9 @@
|
|||||||
},
|
},
|
||||||
"/auth/users/superadmin": {
|
"/auth/users/superadmin": {
|
||||||
"get": {
|
"get": {
|
||||||
"tags": ["auth"],
|
"tags": [
|
||||||
|
"auth"
|
||||||
|
],
|
||||||
"description": "Checks to see if an admin account exists",
|
"description": "Checks to see if an admin account exists",
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
@@ -388,7 +426,9 @@
|
|||||||
},
|
},
|
||||||
"/auth/users": {
|
"/auth/users": {
|
||||||
"get": {
|
"get": {
|
||||||
"tags": ["auth"],
|
"tags": [
|
||||||
|
"auth"
|
||||||
|
],
|
||||||
"description": "Get all users",
|
"description": "Get all users",
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
@@ -431,14 +471,18 @@
|
|||||||
},
|
},
|
||||||
"/auth/recovery/request": {
|
"/auth/recovery/request": {
|
||||||
"post": {
|
"post": {
|
||||||
"tags": ["auth"],
|
"tags": [
|
||||||
|
"auth"
|
||||||
|
],
|
||||||
"description": "Request a recovery token",
|
"description": "Request a recovery token",
|
||||||
"requestBody": {
|
"requestBody": {
|
||||||
"content": {
|
"content": {
|
||||||
"application/json": {
|
"application/json": {
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": ["email"],
|
"required": [
|
||||||
|
"email"
|
||||||
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"email": {
|
"email": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
@@ -485,14 +529,18 @@
|
|||||||
},
|
},
|
||||||
"/auth/recovery/validate": {
|
"/auth/recovery/validate": {
|
||||||
"post": {
|
"post": {
|
||||||
"tags": ["auth"],
|
"tags": [
|
||||||
|
"auth"
|
||||||
|
],
|
||||||
"description": "Validate recovery token",
|
"description": "Validate recovery token",
|
||||||
"requestBody": {
|
"requestBody": {
|
||||||
"content": {
|
"content": {
|
||||||
"application/json": {
|
"application/json": {
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": ["recoveryToken"],
|
"required": [
|
||||||
|
"recoveryToken"
|
||||||
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"recoveryToken": {
|
"recoveryToken": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
@@ -538,14 +586,19 @@
|
|||||||
},
|
},
|
||||||
"/auth/recovery/reset": {
|
"/auth/recovery/reset": {
|
||||||
"post": {
|
"post": {
|
||||||
"tags": ["auth"],
|
"tags": [
|
||||||
|
"auth"
|
||||||
|
],
|
||||||
"description": "Password reset",
|
"description": "Password reset",
|
||||||
"requestBody": {
|
"requestBody": {
|
||||||
"content": {
|
"content": {
|
||||||
"application/json": {
|
"application/json": {
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": ["recoveryToken", "password"],
|
"required": [
|
||||||
|
"recoveryToken",
|
||||||
|
"password"
|
||||||
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"recoveryToken": {
|
"recoveryToken": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
@@ -594,14 +647,19 @@
|
|||||||
},
|
},
|
||||||
"/invite": {
|
"/invite": {
|
||||||
"post": {
|
"post": {
|
||||||
"tags": ["invite"],
|
"tags": [
|
||||||
|
"invite"
|
||||||
|
],
|
||||||
"description": "Request an invitation",
|
"description": "Request an invitation",
|
||||||
"requestBody": {
|
"requestBody": {
|
||||||
"content": {
|
"content": {
|
||||||
"application/json": {
|
"application/json": {
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": ["email", "role"],
|
"required": [
|
||||||
|
"email",
|
||||||
|
"role"
|
||||||
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"email": {
|
"email": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
@@ -655,14 +713,18 @@
|
|||||||
},
|
},
|
||||||
"/invite/verify": {
|
"/invite/verify": {
|
||||||
"post": {
|
"post": {
|
||||||
"tags": ["invite"],
|
"tags": [
|
||||||
|
"invite"
|
||||||
|
],
|
||||||
"description": "Request an invitation",
|
"description": "Request an invitation",
|
||||||
"requestBody": {
|
"requestBody": {
|
||||||
"content": {
|
"content": {
|
||||||
"application/json": {
|
"application/json": {
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": ["token"],
|
"required": [
|
||||||
|
"token"
|
||||||
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"token": {
|
"token": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
@@ -713,7 +775,9 @@
|
|||||||
},
|
},
|
||||||
"/monitors": {
|
"/monitors": {
|
||||||
"get": {
|
"get": {
|
||||||
"tags": ["monitors"],
|
"tags": [
|
||||||
|
"monitors"
|
||||||
|
],
|
||||||
"description": "Get all monitors",
|
"description": "Get all monitors",
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
@@ -754,7 +818,9 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"post": {
|
"post": {
|
||||||
"tags": ["monitors"],
|
"tags": [
|
||||||
|
"monitors"
|
||||||
|
],
|
||||||
"description": "Create a new monitor",
|
"description": "Create a new monitor",
|
||||||
"requestBody": {
|
"requestBody": {
|
||||||
"content": {
|
"content": {
|
||||||
@@ -804,7 +870,9 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"delete": {
|
"delete": {
|
||||||
"tags": ["monitors"],
|
"tags": [
|
||||||
|
"monitors"
|
||||||
|
],
|
||||||
"description": "Delete all monitors",
|
"description": "Delete all monitors",
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
@@ -845,9 +913,78 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/monitors/resolution/url": {
|
||||||
|
"get": {
|
||||||
|
"tags": [
|
||||||
|
"monitors"
|
||||||
|
],
|
||||||
|
"description": "Check DNS resolution for a given URL",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"name": "monitorURL",
|
||||||
|
"in": "query",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"type": "string",
|
||||||
|
"example": "https://example.com"
|
||||||
|
},
|
||||||
|
"description": "The URL to check DNS resolution for"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "URL resolved successfully",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/SuccessResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "DNS resolution failed",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/ErrorResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"422": {
|
||||||
|
"description": "Unprocessable Content",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/ErrorResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Internal Server Error",
|
||||||
|
"content": {
|
||||||
|
"application/json": {
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/components/schemas/ErrorResponse"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"bearerAuth": []
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
"/monitors/{monitorId}": {
|
"/monitors/{monitorId}": {
|
||||||
"get": {
|
"get": {
|
||||||
"tags": ["monitors"],
|
"tags": [
|
||||||
|
"monitors"
|
||||||
|
],
|
||||||
"description": "Get monitor by id",
|
"description": "Get monitor by id",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
@@ -898,7 +1035,9 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"put": {
|
"put": {
|
||||||
"tags": ["monitors"],
|
"tags": [
|
||||||
|
"monitors"
|
||||||
|
],
|
||||||
"description": "Update monitor by id",
|
"description": "Update monitor by id",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
@@ -958,7 +1097,9 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"delete": {
|
"delete": {
|
||||||
"tags": ["monitors"],
|
"tags": [
|
||||||
|
"monitors"
|
||||||
|
],
|
||||||
"description": "Delete monitor by id",
|
"description": "Delete monitor by id",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
@@ -1011,7 +1152,9 @@
|
|||||||
},
|
},
|
||||||
"/monitors/stats/{monitorId}": {
|
"/monitors/stats/{monitorId}": {
|
||||||
"get": {
|
"get": {
|
||||||
"tags": ["monitors"],
|
"tags": [
|
||||||
|
"monitors"
|
||||||
|
],
|
||||||
"description": "Get monitor stats",
|
"description": "Get monitor stats",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
@@ -1064,7 +1207,9 @@
|
|||||||
},
|
},
|
||||||
"/monitors/certificate/{monitorId}": {
|
"/monitors/certificate/{monitorId}": {
|
||||||
"get": {
|
"get": {
|
||||||
"tags": ["monitors"],
|
"tags": [
|
||||||
|
"monitors"
|
||||||
|
],
|
||||||
"description": "Get monitor certificate",
|
"description": "Get monitor certificate",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
@@ -1117,7 +1262,9 @@
|
|||||||
},
|
},
|
||||||
"/monitors/team/summary/{teamId}": {
|
"/monitors/team/summary/{teamId}": {
|
||||||
"get": {
|
"get": {
|
||||||
"tags": ["monitors"],
|
"tags": [
|
||||||
|
"monitors"
|
||||||
|
],
|
||||||
"description": "Get monitors and summary by teamId",
|
"description": "Get monitors and summary by teamId",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
@@ -1134,7 +1281,11 @@
|
|||||||
"required": false,
|
"required": false,
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"enum": ["http", "ping", "pagespeed"]
|
"enum": [
|
||||||
|
"http",
|
||||||
|
"ping",
|
||||||
|
"pagespeed"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@@ -1179,7 +1330,9 @@
|
|||||||
},
|
},
|
||||||
"/monitors/team/{teamId}": {
|
"/monitors/team/{teamId}": {
|
||||||
"get": {
|
"get": {
|
||||||
"tags": ["monitors"],
|
"tags": [
|
||||||
|
"monitors"
|
||||||
|
],
|
||||||
"description": "Get monitors by teamId",
|
"description": "Get monitors by teamId",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
@@ -1206,7 +1359,10 @@
|
|||||||
"required": false,
|
"required": false,
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": ["asc", "desc"]
|
"enum": [
|
||||||
|
"asc",
|
||||||
|
"desc"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -1225,7 +1381,11 @@
|
|||||||
"required": false,
|
"required": false,
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": ["http", "ping", "pagespeed"]
|
"enum": [
|
||||||
|
"http",
|
||||||
|
"ping",
|
||||||
|
"pagespeed"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -1269,7 +1429,11 @@
|
|||||||
"required": false,
|
"required": false,
|
||||||
"schema": {
|
"schema": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": ["http", "ping", "pagespeed"]
|
"enum": [
|
||||||
|
"http",
|
||||||
|
"ping",
|
||||||
|
"pagespeed"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
@@ -1314,7 +1478,9 @@
|
|||||||
},
|
},
|
||||||
"/monitors/pause/{monitorId}": {
|
"/monitors/pause/{monitorId}": {
|
||||||
"post": {
|
"post": {
|
||||||
"tags": ["monitors"],
|
"tags": [
|
||||||
|
"monitors"
|
||||||
|
],
|
||||||
"description": "Pause monitor",
|
"description": "Pause monitor",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
@@ -1367,7 +1533,9 @@
|
|||||||
},
|
},
|
||||||
"/monitors/demo": {
|
"/monitors/demo": {
|
||||||
"post": {
|
"post": {
|
||||||
"tags": ["monitors"],
|
"tags": [
|
||||||
|
"monitors"
|
||||||
|
],
|
||||||
"description": "Create a demo monitor",
|
"description": "Create a demo monitor",
|
||||||
"requestBody": {
|
"requestBody": {
|
||||||
"content": {
|
"content": {
|
||||||
@@ -1419,7 +1587,9 @@
|
|||||||
},
|
},
|
||||||
"/checks/{monitorId}": {
|
"/checks/{monitorId}": {
|
||||||
"get": {
|
"get": {
|
||||||
"tags": ["checks"],
|
"tags": [
|
||||||
|
"checks"
|
||||||
|
],
|
||||||
"description": "Get all checks for a monitor",
|
"description": "Get all checks for a monitor",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
@@ -1470,7 +1640,9 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"post": {
|
"post": {
|
||||||
"tags": ["checks"],
|
"tags": [
|
||||||
|
"checks"
|
||||||
|
],
|
||||||
"description": "Create a new check",
|
"description": "Create a new check",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
@@ -1530,7 +1702,9 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"delete": {
|
"delete": {
|
||||||
"tags": ["checks"],
|
"tags": [
|
||||||
|
"checks"
|
||||||
|
],
|
||||||
"description": "Delete all checks for a monitor",
|
"description": "Delete all checks for a monitor",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
@@ -1583,7 +1757,9 @@
|
|||||||
},
|
},
|
||||||
"/checks/team/{teamId}": {
|
"/checks/team/{teamId}": {
|
||||||
"get": {
|
"get": {
|
||||||
"tags": ["checks"],
|
"tags": [
|
||||||
|
"checks"
|
||||||
|
],
|
||||||
"description": "Get all checks for a team",
|
"description": "Get all checks for a team",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
@@ -1634,7 +1810,9 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"delete": {
|
"delete": {
|
||||||
"tags": ["checks"],
|
"tags": [
|
||||||
|
"checks"
|
||||||
|
],
|
||||||
"description": "Delete all checks for a team",
|
"description": "Delete all checks for a team",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
@@ -1687,7 +1865,9 @@
|
|||||||
},
|
},
|
||||||
"/checks/team/ttl": {
|
"/checks/team/ttl": {
|
||||||
"put": {
|
"put": {
|
||||||
"tags": ["checks"],
|
"tags": [
|
||||||
|
"checks"
|
||||||
|
],
|
||||||
"description": "Update check TTL",
|
"description": "Update check TTL",
|
||||||
"requestBody": {
|
"requestBody": {
|
||||||
"content": {
|
"content": {
|
||||||
@@ -1739,7 +1919,9 @@
|
|||||||
},
|
},
|
||||||
"/maintenance-window/monitor/{monitorId}": {
|
"/maintenance-window/monitor/{monitorId}": {
|
||||||
"get": {
|
"get": {
|
||||||
"tags": ["maintenance-window"],
|
"tags": [
|
||||||
|
"maintenance-window"
|
||||||
|
],
|
||||||
"description": "Get maintenance window for monitor",
|
"description": "Get maintenance window for monitor",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
@@ -1790,7 +1972,9 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"post": {
|
"post": {
|
||||||
"tags": ["maintenance-window"],
|
"tags": [
|
||||||
|
"maintenance-window"
|
||||||
|
],
|
||||||
"description": "Create maintenance window for monitor",
|
"description": "Create maintenance window for monitor",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
@@ -1852,7 +2036,9 @@
|
|||||||
},
|
},
|
||||||
"/maintenance-window/user/{userId}": {
|
"/maintenance-window/user/{userId}": {
|
||||||
"get": {
|
"get": {
|
||||||
"tags": ["maintenance-window"],
|
"tags": [
|
||||||
|
"maintenance-window"
|
||||||
|
],
|
||||||
"description": "Get maintenance window for user",
|
"description": "Get maintenance window for user",
|
||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
@@ -1905,7 +2091,9 @@
|
|||||||
},
|
},
|
||||||
"/queue/jobs": {
|
"/queue/jobs": {
|
||||||
"get": {
|
"get": {
|
||||||
"tags": ["queue"],
|
"tags": [
|
||||||
|
"queue"
|
||||||
|
],
|
||||||
"description": "Get all jobs in queue",
|
"description": "Get all jobs in queue",
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
@@ -1946,7 +2134,9 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"post": {
|
"post": {
|
||||||
"tags": ["queue"],
|
"tags": [
|
||||||
|
"queue"
|
||||||
|
],
|
||||||
"description": "Create a new job. Useful for testing scaling workers",
|
"description": "Create a new job. Useful for testing scaling workers",
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
@@ -1989,7 +2179,9 @@
|
|||||||
},
|
},
|
||||||
"/queue/metrics": {
|
"/queue/metrics": {
|
||||||
"get": {
|
"get": {
|
||||||
"tags": ["queue"],
|
"tags": [
|
||||||
|
"queue"
|
||||||
|
],
|
||||||
"description": "Get queue metrics",
|
"description": "Get queue metrics",
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
@@ -2032,7 +2224,9 @@
|
|||||||
},
|
},
|
||||||
"/queue/obliterate": {
|
"/queue/obliterate": {
|
||||||
"post": {
|
"post": {
|
||||||
"tags": ["queue"],
|
"tags": [
|
||||||
|
"queue"
|
||||||
|
],
|
||||||
"description": "Obliterate job queue",
|
"description": "Obliterate job queue",
|
||||||
"responses": {
|
"responses": {
|
||||||
"200": {
|
"200": {
|
||||||
@@ -2074,7 +2268,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
"components": {
|
"components": {
|
||||||
"securitySchemes": {
|
"securitySchemes": {
|
||||||
"bearerAuth": {
|
"bearerAuth": {
|
||||||
@@ -2113,7 +2306,14 @@
|
|||||||
},
|
},
|
||||||
"UserUpdateRequest": {
|
"UserUpdateRequest": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": ["firstName", "lastName", "email", "password", "role", "teamId"],
|
"required": [
|
||||||
|
"firstName",
|
||||||
|
"lastName",
|
||||||
|
"email",
|
||||||
|
"password",
|
||||||
|
"role",
|
||||||
|
"teamId"
|
||||||
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"firstName": {
|
"firstName": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
@@ -2135,8 +2335,23 @@
|
|||||||
},
|
},
|
||||||
"role": {
|
"role": {
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"enum": [["user"], ["admin"], ["superadmin"], ["Demo"]],
|
"enum": [
|
||||||
"default": ["superadmin"]
|
[
|
||||||
|
"user"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"admin"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"superadmin"
|
||||||
|
],
|
||||||
|
[
|
||||||
|
"Demo"
|
||||||
|
]
|
||||||
|
],
|
||||||
|
"default": [
|
||||||
|
"superadmin"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"deleteProfileImage": {
|
"deleteProfileImage": {
|
||||||
"type": "boolean"
|
"type": "boolean"
|
||||||
@@ -2145,7 +2360,14 @@
|
|||||||
},
|
},
|
||||||
"CreateMonitorBody": {
|
"CreateMonitorBody": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": ["userId", "teamId", "name", "description", "type", "url"],
|
"required": [
|
||||||
|
"userId",
|
||||||
|
"teamId",
|
||||||
|
"name",
|
||||||
|
"description",
|
||||||
|
"type",
|
||||||
|
"url"
|
||||||
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"_id": {
|
"_id": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
@@ -2164,7 +2386,11 @@
|
|||||||
},
|
},
|
||||||
"type": {
|
"type": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"enum": ["http", "ping", "pagespeed"]
|
"enum": [
|
||||||
|
"http",
|
||||||
|
"ping",
|
||||||
|
"pagespeed"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"url": {
|
"url": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
@@ -2205,7 +2431,13 @@
|
|||||||
},
|
},
|
||||||
"CreateCheckBody": {
|
"CreateCheckBody": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": ["monitorId", "status", "responseTime", "statusCode", "message"],
|
"required": [
|
||||||
|
"monitorId",
|
||||||
|
"status",
|
||||||
|
"responseTime",
|
||||||
|
"statusCode",
|
||||||
|
"message"
|
||||||
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"monitorId": {
|
"monitorId": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
@@ -2226,7 +2458,9 @@
|
|||||||
},
|
},
|
||||||
"UpdateCheckTTLBody": {
|
"UpdateCheckTTLBody": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": ["ttl"],
|
"required": [
|
||||||
|
"ttl"
|
||||||
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"ttl": {
|
"ttl": {
|
||||||
"type": "integer"
|
"type": "integer"
|
||||||
@@ -2235,7 +2469,13 @@
|
|||||||
},
|
},
|
||||||
"CreateMaintenanceWindowBody": {
|
"CreateMaintenanceWindowBody": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"required": ["userId", "active", "oneTime", "start", "end"],
|
"required": [
|
||||||
|
"userId",
|
||||||
|
"active",
|
||||||
|
"oneTime",
|
||||||
|
"start",
|
||||||
|
"end"
|
||||||
|
],
|
||||||
"properties": {
|
"properties": {
|
||||||
"userId": {
|
"userId": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
import { Router } from "express";
|
import { Router } from "express";
|
||||||
import {
|
import {
|
||||||
getAllMonitors,
|
getAllMonitors,
|
||||||
getMonitorStatsById,
|
getMonitorStatsById,
|
||||||
getMonitorCertificate,
|
getMonitorCertificate,
|
||||||
getMonitorById,
|
getMonitorById,
|
||||||
getMonitorsAndSummaryByTeamId,
|
getMonitorsAndSummaryByTeamId,
|
||||||
getMonitorsByTeamId,
|
getMonitorsByTeamId,
|
||||||
createMonitor,
|
createMonitor,
|
||||||
deleteMonitor,
|
checkEndpointResolution,
|
||||||
deleteAllMonitors,
|
deleteMonitor,
|
||||||
editMonitor,
|
deleteAllMonitors,
|
||||||
pauseMonitor,
|
editMonitor,
|
||||||
addDemoMonitors,
|
pauseMonitor,
|
||||||
|
addDemoMonitors,
|
||||||
} from "../controllers/monitorController.js";
|
} from "../controllers/monitorController.js";
|
||||||
import { isAllowed } from "../middleware/isAllowed.js";
|
import { isAllowed } from "../middleware/isAllowed.js";
|
||||||
import { fetchMonitorCertificate } from "../controllers/controllerUtils.js";
|
import { fetchMonitorCertificate } from "../controllers/controllerUtils.js";
|
||||||
@@ -21,15 +22,25 @@ const router = Router();
|
|||||||
router.get("/", getAllMonitors);
|
router.get("/", getAllMonitors);
|
||||||
router.get("/stats/:monitorId", getMonitorStatsById);
|
router.get("/stats/:monitorId", getMonitorStatsById);
|
||||||
router.get("/certificate/:monitorId", (req, res, next) => {
|
router.get("/certificate/:monitorId", (req, res, next) => {
|
||||||
getMonitorCertificate(req, res, next, fetchMonitorCertificate);
|
getMonitorCertificate(req, res, next, fetchMonitorCertificate);
|
||||||
});
|
});
|
||||||
router.get("/:monitorId", getMonitorById);
|
router.get("/:monitorId", getMonitorById);
|
||||||
router.get("/team/summary/:teamId", getMonitorsAndSummaryByTeamId);
|
router.get("/team/summary/:teamId", getMonitorsAndSummaryByTeamId);
|
||||||
router.get("/team/:teamId", getMonitorsByTeamId);
|
router.get("/team/:teamId", getMonitorsByTeamId);
|
||||||
|
|
||||||
router.post("/", isAllowed(["admin", "superadmin"]), createMonitor);
|
router.get(
|
||||||
|
"/resolution/url",
|
||||||
|
isAllowed(["admin", "superadmin"]),
|
||||||
|
checkEndpointResolution
|
||||||
|
)
|
||||||
|
|
||||||
router.delete("/:monitorId", isAllowed(["admin", "superadmin"]), deleteMonitor);
|
router.delete(
|
||||||
|
"/:monitorId",
|
||||||
|
isAllowed(["admin", "superadmin"]),
|
||||||
|
deleteMonitor
|
||||||
|
);
|
||||||
|
|
||||||
|
router.post("/", isAllowed(["admin", "superadmin"]), createMonitor);
|
||||||
|
|
||||||
router.put("/:monitorId", isAllowed(["admin", "superadmin"]), editMonitor);
|
router.put("/:monitorId", isAllowed(["admin", "superadmin"]), editMonitor);
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import {
|
|||||||
getMonitorsAndSummaryByTeamId,
|
getMonitorsAndSummaryByTeamId,
|
||||||
getMonitorsByTeamId,
|
getMonitorsByTeamId,
|
||||||
createMonitor,
|
createMonitor,
|
||||||
|
checkEndpointResolution,
|
||||||
deleteMonitor,
|
deleteMonitor,
|
||||||
deleteAllMonitors,
|
deleteAllMonitors,
|
||||||
editMonitor,
|
editMonitor,
|
||||||
@@ -16,9 +17,7 @@ import jwt from "jsonwebtoken";
|
|||||||
import sinon from "sinon";
|
import sinon from "sinon";
|
||||||
import { successMessages } from "../../utils/messages.js";
|
import { successMessages } from "../../utils/messages.js";
|
||||||
import logger from "../../utils/logger.js";
|
import logger from "../../utils/logger.js";
|
||||||
import * as monitorController from "../../controllers/monitorController.js";
|
import dns from "dns";
|
||||||
import { fetchMonitorCertificate } from "../../controllers/controllerUtils.js";
|
|
||||||
|
|
||||||
const SERVICE_NAME = "monitorController";
|
const SERVICE_NAME = "monitorController";
|
||||||
|
|
||||||
describe("Monitor Controller - getAllMonitors", () => {
|
describe("Monitor Controller - getAllMonitors", () => {
|
||||||
@@ -460,6 +459,50 @@ describe("Monitor Controller - createMonitor", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("Monitor Controllor - checkEndpointResolution", () => {
|
||||||
|
let req, res, next, dnsResolveStub;
|
||||||
|
beforeEach(() => {
|
||||||
|
req = { query: { monitorURL: 'https://example.com' } };
|
||||||
|
res = { status: sinon.stub().returnsThis(), json: sinon.stub() };
|
||||||
|
next = sinon.stub();
|
||||||
|
dnsResolveStub = sinon.stub(dns, 'resolve');
|
||||||
|
});
|
||||||
|
afterEach(() => {
|
||||||
|
dnsResolveStub.restore();
|
||||||
|
});
|
||||||
|
it('should resolve the URL successfully', async () => {
|
||||||
|
dnsResolveStub.callsFake((hostname, callback) => callback(null));
|
||||||
|
await checkEndpointResolution(req, res, next);
|
||||||
|
expect(res.status.calledWith(200)).to.be.true;
|
||||||
|
expect(res.json.calledWith({
|
||||||
|
success: true,
|
||||||
|
msg: 'URL resolved successfully',
|
||||||
|
})).to.be.true;
|
||||||
|
expect(next.called).to.be.false;
|
||||||
|
});
|
||||||
|
it("should return an error if DNS resolution fails", async () => {
|
||||||
|
const dnsError = new Error("DNS resolution failed");
|
||||||
|
dnsError.code = 'ENOTFOUND';
|
||||||
|
dnsResolveStub.callsFake((hostname, callback) => callback(dnsError));
|
||||||
|
await checkEndpointResolution(req, res, next);
|
||||||
|
expect(next.calledOnce).to.be.true;
|
||||||
|
const errorPassedToNext = next.getCall(0).args[0];
|
||||||
|
expect(errorPassedToNext).to.be.an.instanceOf(Error);
|
||||||
|
expect(errorPassedToNext.message).to.include('DNS resolution failed');
|
||||||
|
expect(errorPassedToNext.code).to.equal('ENOTFOUND');
|
||||||
|
expect(errorPassedToNext.status).to.equal(500);
|
||||||
|
});
|
||||||
|
it('should reject with an error if query validation fails', async () => {
|
||||||
|
req.query.monitorURL = 'invalid-url';
|
||||||
|
await checkEndpointResolution(req, res, next);
|
||||||
|
expect(next.calledOnce).to.be.true;
|
||||||
|
const error = next.getCall(0).args[0];
|
||||||
|
expect(next.firstCall.args[0]).to.be.an("error");
|
||||||
|
expect(next.firstCall.args[0].status).to.equal(422);
|
||||||
|
expect(error.message).to.equal('"monitorURL" must be a valid uri');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("Monitor Controller - deleteMonitor", () => {
|
describe("Monitor Controller - deleteMonitor", () => {
|
||||||
let req, res, next;
|
let req, res, next;
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
|||||||
@@ -236,6 +236,10 @@ const pauseMonitorParamValidation = joi.object({
|
|||||||
monitorId: joi.string().required(),
|
monitorId: joi.string().required(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const getMonitorURLByQueryValidation = joi.object({
|
||||||
|
monitorURL: joi.string().uri().required(),
|
||||||
|
});
|
||||||
|
|
||||||
//****************************************
|
//****************************************
|
||||||
// Alerts
|
// Alerts
|
||||||
//****************************************
|
//****************************************
|
||||||
@@ -446,6 +450,7 @@ export {
|
|||||||
getCertificateParamValidation,
|
getCertificateParamValidation,
|
||||||
editMonitorBodyValidation,
|
editMonitorBodyValidation,
|
||||||
pauseMonitorParamValidation,
|
pauseMonitorParamValidation,
|
||||||
|
getMonitorURLByQueryValidation,
|
||||||
editUserParamValidation,
|
editUserParamValidation,
|
||||||
editUserBodyValidation,
|
editUserBodyValidation,
|
||||||
createAlertParamValidation,
|
createAlertParamValidation,
|
||||||
|
|||||||
Reference in new issue
Block a user