Merge pull request #1151 from bluewave-labs/feat/fe/docker-monitors
Feat/fe/docker monitors, resolves #1139
This commit is contained in:
6 files changed
+70
-40
No files matched your search
@@ -40,7 +40,7 @@ export const checkEndpointResolution = createAsyncThunk(
|
|||||||
const res = await networkService.checkEndpointResolution({
|
const res = await networkService.checkEndpointResolution({
|
||||||
authToken: authToken,
|
authToken: authToken,
|
||||||
monitorURL: monitorURL,
|
monitorURL: monitorURL,
|
||||||
})
|
});
|
||||||
return res.data;
|
return res.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
if (error.response && error.response.data) {
|
if (error.response && error.response.data) {
|
||||||
@@ -53,7 +53,7 @@ export const checkEndpointResolution = createAsyncThunk(
|
|||||||
return thunkApi.rejectWithValue(payload);
|
return thunkApi.rejectWithValue(payload);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
);
|
||||||
|
|
||||||
export const getUptimeMonitorById = createAsyncThunk(
|
export const getUptimeMonitorById = createAsyncThunk(
|
||||||
"monitors/getMonitorById",
|
"monitors/getMonitorById",
|
||||||
@@ -86,7 +86,7 @@ export const getUptimeMonitorsByTeamId = createAsyncThunk(
|
|||||||
const res = await networkService.getMonitorsAndSummaryByTeamId({
|
const res = await networkService.getMonitorsAndSummaryByTeamId({
|
||||||
authToken: token,
|
authToken: token,
|
||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
types: ["http", "ping"],
|
types: ["http", "ping", "docker"],
|
||||||
});
|
});
|
||||||
return res.data;
|
return res.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -1,10 +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 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 { 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";
|
||||||
@@ -19,21 +19,40 @@ 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, isLoading } = 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",
|
||||||
"monitor-name": "name",
|
"monitor-name": "name",
|
||||||
"monitor-checks-http": "type",
|
"monitor-checks-http": "type",
|
||||||
"monitor-checks-ping": "type",
|
"monitor-checks-ping": "type",
|
||||||
|
"monitor-checks-docker": "type",
|
||||||
"notify-email-default": "notification-email",
|
"notify-email-default": "notification-email",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const monitorTypeMaps = {
|
||||||
|
http: {
|
||||||
|
label: "URL to monitor",
|
||||||
|
placeholder: "google.com",
|
||||||
|
namePlaceholder: "Google",
|
||||||
|
},
|
||||||
|
ping: {
|
||||||
|
label: "IP address to monitor",
|
||||||
|
placeholder: "1.1.1.1",
|
||||||
|
namePlaceholder: "Google",
|
||||||
|
},
|
||||||
|
docker: {
|
||||||
|
label: "Container ID",
|
||||||
|
placeholder: "abc123",
|
||||||
|
namePlaceholder: "My Container",
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
const { monitorId } = useParams();
|
const { monitorId } = useParams();
|
||||||
const [monitor, setMonitor] = useState({
|
const [monitor, setMonitor] = useState({
|
||||||
url: "",
|
url: "",
|
||||||
@@ -112,7 +131,6 @@ const CreateMonitor = () => {
|
|||||||
{ [name]: value },
|
{ [name]: value },
|
||||||
{ abortEarly: false }
|
{ abortEarly: false }
|
||||||
);
|
);
|
||||||
console.log(error);
|
|
||||||
setErrors((prev) => {
|
setErrors((prev) => {
|
||||||
const updatedErrors = { ...prev };
|
const updatedErrors = { ...prev };
|
||||||
if (error) updatedErrors[name] = error.details[0].message;
|
if (error) updatedErrors[name] = error.details[0].message;
|
||||||
@@ -148,16 +166,18 @@ const CreateMonitor = () => {
|
|||||||
setErrors(newErrors);
|
setErrors(newErrors);
|
||||||
createToast({ body: "Error validation data." });
|
createToast({ body: "Error validation data." });
|
||||||
} else {
|
} else {
|
||||||
if (monitor.type === "http") {
|
if (monitor.type === "http") {
|
||||||
const checkEndpointAction = await dispatch(
|
const checkEndpointAction = await dispatch(
|
||||||
checkEndpointResolution({ authToken, monitorURL: form.url })
|
checkEndpointResolution({ authToken, monitorURL: form.url })
|
||||||
)
|
);
|
||||||
if (checkEndpointAction.meta.requestStatus === "rejected") {
|
if (checkEndpointAction.meta.requestStatus === "rejected") {
|
||||||
createToast({ body: "The endpoint you entered doesn't resolve. Check the URL again." });
|
createToast({
|
||||||
setErrors({ url: "The entered URL is not reachable." });
|
body: "The endpoint you entered doesn't resolve. Check the URL again.",
|
||||||
return;
|
});
|
||||||
}
|
setErrors({ url: "The entered URL is not reachable." });
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
form = {
|
form = {
|
||||||
...form,
|
...form,
|
||||||
@@ -232,9 +252,9 @@ const CreateMonitor = () => {
|
|||||||
<Field
|
<Field
|
||||||
type={monitor.type === "http" ? "url" : "text"}
|
type={monitor.type === "http" ? "url" : "text"}
|
||||||
id="monitor-url"
|
id="monitor-url"
|
||||||
label="URL to monitor"
|
label={monitorTypeMaps[monitor.type].label || "URL to monitor"}
|
||||||
https={https}
|
https={https}
|
||||||
placeholder="google.com"
|
placeholder={monitorTypeMaps[monitor.type].placeholder || ""}
|
||||||
value={monitor.url}
|
value={monitor.url}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
error={errors["url"]}
|
error={errors["url"]}
|
||||||
@@ -244,7 +264,7 @@ const CreateMonitor = () => {
|
|||||||
id="monitor-name"
|
id="monitor-name"
|
||||||
label="Display name"
|
label="Display name"
|
||||||
isOptional={true}
|
isOptional={true}
|
||||||
placeholder="Google"
|
placeholder={monitorTypeMaps[monitor.type].namePlaceholder || ""}
|
||||||
value={monitor.name}
|
value={monitor.name}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
error={errors["name"]}
|
error={errors["name"]}
|
||||||
@@ -299,6 +319,15 @@ const CreateMonitor = () => {
|
|||||||
checked={monitor.type === "ping"}
|
checked={monitor.type === "ping"}
|
||||||
onChange={(event) => handleChange(event)}
|
onChange={(event) => handleChange(event)}
|
||||||
/>
|
/>
|
||||||
|
<Radio
|
||||||
|
id="monitor-checks-docker"
|
||||||
|
title="Docker container monitoring"
|
||||||
|
desc="Check whether your container is running or not."
|
||||||
|
size="small"
|
||||||
|
value="docker"
|
||||||
|
checked={monitor.type === "docker"}
|
||||||
|
onChange={(event) => handleChange(event)}
|
||||||
|
/>
|
||||||
{errors["type"] ? (
|
{errors["type"] ? (
|
||||||
<Box className="error-container">
|
<Box className="error-container">
|
||||||
<Typography
|
<Typography
|
||||||
@@ -387,14 +416,14 @@ const CreateMonitor = () => {
|
|||||||
justifyContent="flex-end"
|
justifyContent="flex-end"
|
||||||
>
|
>
|
||||||
<LoadingButton
|
<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}
|
loading={isLoading}
|
||||||
>
|
>
|
||||||
Create monitor
|
Create monitor
|
||||||
</LoadingButton>
|
</LoadingButton>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Stack>
|
</Stack>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -150,7 +150,7 @@ const MonitorTable = ({ isAdmin, filter, setIsSearching, isSearching }) => {
|
|||||||
authToken,
|
authToken,
|
||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
limit: 25,
|
limit: 25,
|
||||||
types: ["http", "ping"],
|
types: ["http", "ping", "docker"],
|
||||||
status: null,
|
status: null,
|
||||||
checkOrder: "desc",
|
checkOrder: "desc",
|
||||||
normalize: true,
|
normalize: true,
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ const SERVICE_NAME = "monitorModule";
|
|||||||
const CHECK_MODEL_LOOKUP = {
|
const CHECK_MODEL_LOOKUP = {
|
||||||
http: Check,
|
http: Check,
|
||||||
ping: Check,
|
ping: Check,
|
||||||
|
docker: Check,
|
||||||
pagespeed: PageSpeedCheck,
|
pagespeed: PageSpeedCheck,
|
||||||
hardware: HardwareCheck,
|
hardware: HardwareCheck,
|
||||||
};
|
};
|
||||||
@@ -349,7 +350,7 @@ const getMonitorStatsById = async (req) => {
|
|||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (monitor.type === "http" || monitor.type === "ping") {
|
if (monitor.type === "http" || monitor.type === "ping" || monitor.type === "docker") {
|
||||||
// HTTP/PING Specific stats
|
// HTTP/PING Specific stats
|
||||||
monitorStats.periodAvgResponseTime = getAverageResponseTime(checksForDateRange);
|
monitorStats.periodAvgResponseTime = getAverageResponseTime(checksForDateRange);
|
||||||
monitorStats.periodUptime = getUptimePercentage(checksForDateRange);
|
monitorStats.periodUptime = getUptimePercentage(checksForDateRange);
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ class NetworkService {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const containers = await docker.listContainers({ all: true });
|
const containers = await docker.listContainers({ all: true });
|
||||||
const containerExists = containers.some((c) => c.Id === job.data.url);
|
const containerExists = containers.some((c) => c.Id.startsWith(job.data.url));
|
||||||
if (!containerExists) {
|
if (!containerExists) {
|
||||||
throw new Error(errorMessages.DOCKER_NOT_FOUND);
|
throw new Error(errorMessages.DOCKER_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -144,8 +144,8 @@ const getMonitorsAndSummaryByTeamIdQueryValidation = joi.object({
|
|||||||
type: joi
|
type: joi
|
||||||
.alternatives()
|
.alternatives()
|
||||||
.try(
|
.try(
|
||||||
joi.string().valid("http", "ping", "pagespeed"),
|
joi.string().valid("http", "ping", "pagespeed", "docker"),
|
||||||
joi.array().items(joi.string().valid("http", "ping", "pagespeed"))
|
joi.array().items(joi.string().valid("http", "ping", "pagespeed", "docker"))
|
||||||
),
|
),
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -161,8 +161,8 @@ const getMonitorsByTeamIdQueryValidation = joi.object({
|
|||||||
type: joi
|
type: joi
|
||||||
.alternatives()
|
.alternatives()
|
||||||
.try(
|
.try(
|
||||||
joi.string().valid("http", "ping", "pagespeed"),
|
joi.string().valid("http", "ping", "pagespeed", "docker"),
|
||||||
joi.array().items(joi.string().valid("http", "ping", "pagespeed"))
|
joi.array().items(joi.string().valid("http", "ping", "pagespeed", "docker"))
|
||||||
),
|
),
|
||||||
page: joi.number(),
|
page: joi.number(),
|
||||||
rowsPerPage: joi.number(),
|
rowsPerPage: joi.number(),
|
||||||
|
|||||||
Reference in new issue
Block a user