Merge pull request #1607 from bluewave-labs/fix/be/incidents
fix: be/incidents, resolves #1567
This commit is contained in:
19 files changed
+347
-243
No files matched your search
@@ -16,7 +16,7 @@ import { BaseLabel } from "../Label";
|
|||||||
const DEFAULT_CODE = 9999; // Default code for unknown status
|
const DEFAULT_CODE = 9999; // Default code for unknown status
|
||||||
|
|
||||||
const handleStatusCode = (status) => {
|
const handleStatusCode = (status) => {
|
||||||
if (status >= 100 && status < 600) {
|
if (status) {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
return DEFAULT_CODE;
|
return DEFAULT_CODE;
|
||||||
|
|||||||
@@ -5,11 +5,11 @@ import { TablePaginationActions } from "./Actions";
|
|||||||
import SelectorVertical from "../../../assets/icons/selector-vertical.svg?react";
|
import SelectorVertical from "../../../assets/icons/selector-vertical.svg?react";
|
||||||
|
|
||||||
Pagination.propTypes = {
|
Pagination.propTypes = {
|
||||||
monitorCount: PropTypes.number.isRequired, // Total number of items for pagination.
|
itemCount: PropTypes.number.isRequired, // Total number of items for pagination.
|
||||||
page: PropTypes.number.isRequired, // Current page index.
|
page: PropTypes.number.isRequired, // Current page index.
|
||||||
rowsPerPage: PropTypes.number.isRequired, // Number of rows displayed per page.
|
rowsPerPage: PropTypes.number.isRequired, // Number of rows displayed per page.
|
||||||
handleChangePage: PropTypes.func.isRequired, // Function to handle page changes.
|
handleChangePage: PropTypes.func.isRequired, // Function to handle page changes.
|
||||||
handleChangeRowsPerPage: PropTypes.func.isRequired, // Function to handle changes in rows per page.
|
handleChangeRowsPerPage: PropTypes.func, // Function to handle changes in rows per page.
|
||||||
};
|
};
|
||||||
|
|
||||||
const ROWS_PER_PAGE_OPTIONS = [5, 10, 15, 25];
|
const ROWS_PER_PAGE_OPTIONS = [5, 10, 15, 25];
|
||||||
@@ -18,6 +18,7 @@ const ROWS_PER_PAGE_OPTIONS = [5, 10, 15, 25];
|
|||||||
* Pagination component for table navigation with customized styling and behavior.
|
* Pagination component for table navigation with customized styling and behavior.
|
||||||
*
|
*
|
||||||
* @param {object} props - Component properties.
|
* @param {object} props - Component properties.
|
||||||
|
* @param {string} props.paginationLabel - Label for the pagination.
|
||||||
* @param {number} props.monitorCount - Total number of monitors to paginate.
|
* @param {number} props.monitorCount - Total number of monitors to paginate.
|
||||||
* @param {number} props.page - Current page index (0-based).
|
* @param {number} props.page - Current page index (0-based).
|
||||||
* @param {number} props.rowsPerPage - Number of rows to display per page.
|
* @param {number} props.rowsPerPage - Number of rows to display per page.
|
||||||
@@ -26,7 +27,8 @@ const ROWS_PER_PAGE_OPTIONS = [5, 10, 15, 25];
|
|||||||
* @returns {JSX.Element} The Pagination component.
|
* @returns {JSX.Element} The Pagination component.
|
||||||
*/
|
*/
|
||||||
function Pagination({
|
function Pagination({
|
||||||
monitorCount,
|
paginationLabel,
|
||||||
|
itemCount,
|
||||||
page,
|
page,
|
||||||
rowsPerPage,
|
rowsPerPage,
|
||||||
handleChangePage,
|
handleChangePage,
|
||||||
@@ -35,7 +37,7 @@ function Pagination({
|
|||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
const start = page * rowsPerPage + 1;
|
const start = page * rowsPerPage + 1;
|
||||||
const end = Math.min(page * rowsPerPage + rowsPerPage, monitorCount);
|
const end = Math.min(page * rowsPerPage + rowsPerPage, itemCount);
|
||||||
const range = `${start} - ${end}`;
|
const range = `${start} - ${end}`;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -51,11 +53,11 @@ function Pagination({
|
|||||||
variant="body2"
|
variant="body2"
|
||||||
sx={{ opacity: 0.7 }}
|
sx={{ opacity: 0.7 }}
|
||||||
>
|
>
|
||||||
Showing {range} of {monitorCount} monitor(s)
|
Showing {range} of {itemCount} {paginationLabel}
|
||||||
</Typography>
|
</Typography>
|
||||||
<TablePagination
|
<TablePagination
|
||||||
component="div"
|
component="div"
|
||||||
count={monitorCount}
|
count={itemCount}
|
||||||
page={page}
|
page={page}
|
||||||
onPageChange={handleChangePage}
|
onPageChange={handleChangePage}
|
||||||
rowsPerPage={rowsPerPage}
|
rowsPerPage={rowsPerPage}
|
||||||
@@ -121,4 +123,4 @@ function Pagination({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export { Pagination };
|
export default Pagination;
|
||||||
@@ -82,9 +82,10 @@ const DataTable = ({ headers, data, config = { emptyView: "No data" } }) => {
|
|||||||
</TableRow>
|
</TableRow>
|
||||||
) : (
|
) : (
|
||||||
data.map((row) => {
|
data.map((row) => {
|
||||||
|
const key = row.id || row._id || Math.random();
|
||||||
return (
|
return (
|
||||||
<TableRow
|
<TableRow
|
||||||
key={row.id}
|
key={key}
|
||||||
sx={config?.rowSX ?? {}}
|
sx={config?.rowSX ?? {}}
|
||||||
onClick={() => config?.onRowClick(row)}
|
onClick={() => config?.onRowClick(row)}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import PropTypes from "prop-types";
|
import PropTypes from "prop-types";
|
||||||
import { Pagination, PaginationItem, Typography, Box } from "@mui/material";
|
import { Typography, Box } from "@mui/material";
|
||||||
|
|
||||||
import ArrowBackRoundedIcon from "@mui/icons-material/ArrowBackRounded";
|
|
||||||
import ArrowForwardRoundedIcon from "@mui/icons-material/ArrowForwardRounded";
|
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { useSelector } from "react-redux";
|
import { useSelector } from "react-redux";
|
||||||
import { networkService } from "../../../main";
|
import { networkService } from "../../../main";
|
||||||
@@ -16,7 +14,9 @@ import { HttpStatusLabel } from "../../../Components/HttpStatusLabel";
|
|||||||
import { Empty } from "./Empty/Empty";
|
import { Empty } from "./Empty/Empty";
|
||||||
import { IncidentSkeleton } from "./Skeleton/Skeleton";
|
import { IncidentSkeleton } from "./Skeleton/Skeleton";
|
||||||
import DataTable from "../../../Components/Table";
|
import DataTable from "../../../Components/Table";
|
||||||
const IncidentTable = ({ monitors, selectedMonitor, filter }) => {
|
import Pagination from "../../../Components/Table/TablePagination";
|
||||||
|
|
||||||
|
const IncidentTable = ({ monitors, selectedMonitor, filter, dateRange }) => {
|
||||||
const uiTimezone = useSelector((state) => state.ui.timezone);
|
const uiTimezone = useSelector((state) => state.ui.timezone);
|
||||||
|
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
@@ -24,19 +24,10 @@ const IncidentTable = ({ monitors, selectedMonitor, filter }) => {
|
|||||||
const mode = useSelector((state) => state.ui.mode);
|
const mode = useSelector((state) => state.ui.mode);
|
||||||
const [checks, setChecks] = useState([]);
|
const [checks, setChecks] = useState([]);
|
||||||
const [checksCount, setChecksCount] = useState(0);
|
const [checksCount, setChecksCount] = useState(0);
|
||||||
const [paginationController, setPaginationController] = useState({
|
const [page, setPage] = useState(0);
|
||||||
page: 0,
|
const [rowsPerPage, setRowsPerPage] = useState(10);
|
||||||
rowsPerPage: 14,
|
|
||||||
});
|
|
||||||
const [isLoading, setIsLoading] = useState(false);
|
const [isLoading, setIsLoading] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setPaginationController((prevPaginationController) => ({
|
|
||||||
...prevPaginationController,
|
|
||||||
page: 0,
|
|
||||||
}));
|
|
||||||
}, [filter, selectedMonitor]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchPage = async () => {
|
const fetchPage = async () => {
|
||||||
if (!monitors || Object.keys(monitors).length === 0) {
|
if (!monitors || Object.keys(monitors).length === 0) {
|
||||||
@@ -51,10 +42,10 @@ const IncidentTable = ({ monitors, selectedMonitor, filter }) => {
|
|||||||
teamId: user.teamId,
|
teamId: user.teamId,
|
||||||
sortOrder: "desc",
|
sortOrder: "desc",
|
||||||
limit: null,
|
limit: null,
|
||||||
dateRange: null,
|
dateRange,
|
||||||
filter: filter,
|
filter: filter,
|
||||||
page: paginationController.page,
|
page: page,
|
||||||
rowsPerPage: paginationController.rowsPerPage,
|
rowsPerPage: rowsPerPage,
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
res = await networkService.getChecksByMonitor({
|
res = await networkService.getChecksByMonitor({
|
||||||
@@ -62,12 +53,13 @@ const IncidentTable = ({ monitors, selectedMonitor, filter }) => {
|
|||||||
monitorId: selectedMonitor,
|
monitorId: selectedMonitor,
|
||||||
sortOrder: "desc",
|
sortOrder: "desc",
|
||||||
limit: null,
|
limit: null,
|
||||||
dateRange: null,
|
dateRange,
|
||||||
filter: filter,
|
filter: filter,
|
||||||
page: paginationController.page,
|
page,
|
||||||
rowsPerPage: paginationController.rowsPerPage,
|
rowsPerPage,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
setChecks(res.data.data.checks);
|
setChecks(res.data.data.checks);
|
||||||
setChecksCount(res.data.data.checksCount);
|
setChecksCount(res.data.data.checksCount);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@@ -77,21 +69,14 @@ const IncidentTable = ({ monitors, selectedMonitor, filter }) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
fetchPage();
|
fetchPage();
|
||||||
}, [
|
}, [authToken, user, monitors, selectedMonitor, filter, page, rowsPerPage, dateRange]);
|
||||||
authToken,
|
|
||||||
user,
|
|
||||||
monitors,
|
|
||||||
selectedMonitor,
|
|
||||||
filter,
|
|
||||||
paginationController.page,
|
|
||||||
paginationController.rowsPerPage,
|
|
||||||
]);
|
|
||||||
|
|
||||||
const handlePageChange = (_, newPage) => {
|
const handlePageChange = (_, newPage) => {
|
||||||
setPaginationController({
|
setPage(newPage);
|
||||||
...paginationController,
|
};
|
||||||
page: newPage - 1, // 0-indexed
|
|
||||||
});
|
const handleChangeRowsPerPage = (event) => {
|
||||||
|
setRowsPerPage(event.target.value);
|
||||||
};
|
};
|
||||||
|
|
||||||
const headers = [
|
const headers = [
|
||||||
@@ -134,28 +119,6 @@ const IncidentTable = ({ monitors, selectedMonitor, filter }) => {
|
|||||||
{ id: "message", content: "Message", render: (row) => row.message },
|
{ id: "message", content: "Message", render: (row) => row.message },
|
||||||
];
|
];
|
||||||
|
|
||||||
let paginationComponent = <></>;
|
|
||||||
if (checksCount > paginationController.rowsPerPage) {
|
|
||||||
paginationComponent = (
|
|
||||||
<Pagination
|
|
||||||
count={Math.ceil(checksCount / paginationController.rowsPerPage)}
|
|
||||||
page={paginationController.page + 1} //0-indexed
|
|
||||||
onChange={handlePageChange}
|
|
||||||
shape="rounded"
|
|
||||||
renderItem={(item) => (
|
|
||||||
<PaginationItem
|
|
||||||
slots={{
|
|
||||||
previous: ArrowBackRoundedIcon,
|
|
||||||
next: ArrowForwardRoundedIcon,
|
|
||||||
}}
|
|
||||||
{...item}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
sx={{ mt: "auto" }}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let sharedStyles = {
|
let sharedStyles = {
|
||||||
border: 1,
|
border: 1,
|
||||||
borderColor: theme.palette.primary.lowContrast,
|
borderColor: theme.palette.primary.lowContrast,
|
||||||
@@ -198,8 +161,14 @@ const IncidentTable = ({ monitors, selectedMonitor, filter }) => {
|
|||||||
headers={headers}
|
headers={headers}
|
||||||
data={checks}
|
data={checks}
|
||||||
/>
|
/>
|
||||||
|
<Pagination
|
||||||
{paginationComponent}
|
paginationLabel="incidents"
|
||||||
|
itemCount={checksCount}
|
||||||
|
page={page}
|
||||||
|
rowsPerPage={rowsPerPage}
|
||||||
|
handleChangePage={handlePageChange}
|
||||||
|
handleChangeRowsPerPage={handleChangeRowsPerPage}
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</>
|
</>
|
||||||
@@ -210,6 +179,7 @@ IncidentTable.propTypes = {
|
|||||||
monitors: PropTypes.object.isRequired,
|
monitors: PropTypes.object.isRequired,
|
||||||
selectedMonitor: PropTypes.string.isRequired,
|
selectedMonitor: PropTypes.string.isRequired,
|
||||||
filter: PropTypes.string.isRequired,
|
filter: PropTypes.string.isRequired,
|
||||||
|
dateRange: PropTypes.string.isRequired,
|
||||||
};
|
};
|
||||||
|
|
||||||
export default IncidentTable;
|
export default IncidentTable;
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
.incidents h1.MuiTypography-root {
|
|
||||||
font-size: var(--env-var-font-size-large);
|
|
||||||
font-weight: 600;
|
|
||||||
}
|
|
||||||
.incidents button.MuiButtonBase-root,
|
|
||||||
.incidents p.MuiTypography-root {
|
|
||||||
font-size: var(--env-var-font-size-medium);
|
|
||||||
}
|
|
||||||
.incidents button.MuiButtonBase-root {
|
|
||||||
min-height: 34px;
|
|
||||||
}
|
|
||||||
@@ -8,7 +8,6 @@ import { useTheme } from "@emotion/react";
|
|||||||
import Select from "../../Components/Inputs/Select";
|
import Select from "../../Components/Inputs/Select";
|
||||||
import IncidentTable from "./IncidentTable";
|
import IncidentTable from "./IncidentTable";
|
||||||
import SkeletonLayout from "./skeleton";
|
import SkeletonLayout from "./skeleton";
|
||||||
import "./index.css";
|
|
||||||
|
|
||||||
const Incidents = () => {
|
const Incidents = () => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
@@ -21,6 +20,7 @@ const Incidents = () => {
|
|||||||
|
|
||||||
// TODO do something with these filters
|
// TODO do something with these filters
|
||||||
const [filter, setFilter] = useState("all");
|
const [filter, setFilter] = useState("all");
|
||||||
|
const [dateRange, setDateRange] = useState("hour");
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchMonitors = async () => {
|
const fetchMonitors = async () => {
|
||||||
@@ -77,62 +77,132 @@ const Incidents = () => {
|
|||||||
<>
|
<>
|
||||||
<Stack
|
<Stack
|
||||||
direction="row"
|
direction="row"
|
||||||
alignItems="center"
|
justifyContent="space-between"
|
||||||
gap={theme.spacing(6)}
|
gap={theme.spacing(6)}
|
||||||
>
|
>
|
||||||
<Typography
|
<Stack
|
||||||
display="inline-block"
|
direction="row"
|
||||||
component="h1"
|
alignItems="center"
|
||||||
color={theme.palette.primary.contrastTextSecondary}
|
gap={theme.spacing(6)}
|
||||||
>
|
>
|
||||||
Incidents for
|
<Typography
|
||||||
</Typography>
|
display="inline-block"
|
||||||
<Select
|
component="h1"
|
||||||
id="incidents-select-monitor"
|
color={theme.palette.primary.contrastTextSecondary}
|
||||||
placeholder="All servers"
|
>
|
||||||
value={selectedMonitor}
|
Incidents for
|
||||||
onChange={handleSelect}
|
</Typography>
|
||||||
items={Object.values(monitors)}
|
<Select
|
||||||
sx={{
|
id="incidents-select-monitor"
|
||||||
backgroundColor: theme.palette.primary.main,
|
placeholder="All servers"
|
||||||
color: theme.palette.primary.contrastTextSecondary,
|
value={selectedMonitor}
|
||||||
}}
|
onChange={handleSelect}
|
||||||
/>
|
items={Object.values(monitors)}
|
||||||
<ButtonGroup
|
sx={{
|
||||||
sx={{
|
backgroundColor: theme.palette.primary.main,
|
||||||
ml: "auto",
|
color: theme.palette.primary.contrastTextSecondary,
|
||||||
"& .MuiButtonBase-root, & .MuiButtonBase-root:hover": {
|
}}
|
||||||
borderColor: theme.palette.primary.lowContrast,
|
/>
|
||||||
},
|
</Stack>
|
||||||
}}
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
alignItems="center"
|
||||||
|
gap={theme.spacing(6)}
|
||||||
>
|
>
|
||||||
<Button
|
<Typography
|
||||||
variant="group"
|
display="inline-block"
|
||||||
filled={(filter === "all").toString()}
|
component="h1"
|
||||||
onClick={() => setFilter("all")}
|
color={theme.palette.primary.contrastTextSecondary}
|
||||||
>
|
>
|
||||||
All
|
Filter by:
|
||||||
</Button>
|
</Typography>
|
||||||
<Button
|
<ButtonGroup
|
||||||
variant="group"
|
sx={{
|
||||||
filled={(filter === "down").toString()}
|
ml: "auto",
|
||||||
onClick={() => setFilter("down")}
|
"& .MuiButtonBase-root, & .MuiButtonBase-root:hover": {
|
||||||
|
borderColor: theme.palette.primary.lowContrast,
|
||||||
|
},
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
Down
|
<Button
|
||||||
</Button>
|
variant="group"
|
||||||
<Button
|
filled={(filter === "all").toString()}
|
||||||
variant="group"
|
onClick={() => setFilter("all")}
|
||||||
filled={(filter === "resolve").toString()}
|
>
|
||||||
onClick={() => setFilter("resolve")}
|
All
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="group"
|
||||||
|
filled={(filter === "down").toString()}
|
||||||
|
onClick={() => setFilter("down")}
|
||||||
|
>
|
||||||
|
Down
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="group"
|
||||||
|
filled={(filter === "resolve").toString()}
|
||||||
|
onClick={() => setFilter("resolve")}
|
||||||
|
>
|
||||||
|
Cannot resolve
|
||||||
|
</Button>
|
||||||
|
</ButtonGroup>
|
||||||
|
</Stack>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
alignItems="center"
|
||||||
|
gap={theme.spacing(6)}
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
display="inline-block"
|
||||||
|
component="h1"
|
||||||
|
color={theme.palette.primary.contrastTextSecondary}
|
||||||
>
|
>
|
||||||
Cannot Resolve
|
Show:
|
||||||
</Button>
|
</Typography>
|
||||||
</ButtonGroup>
|
<ButtonGroup
|
||||||
|
sx={{
|
||||||
|
ml: "auto",
|
||||||
|
"& .MuiButtonBase-root, & .MuiButtonBase-root:hover": {
|
||||||
|
borderColor: theme.palette.primary.lowContrast,
|
||||||
|
},
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Button
|
||||||
|
variant="group"
|
||||||
|
filled={(dateRange === "hour").toString()}
|
||||||
|
onClick={() => setDateRange("hour")}
|
||||||
|
>
|
||||||
|
Last hour
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="group"
|
||||||
|
filled={(dateRange === "day").toString()}
|
||||||
|
onClick={() => setDateRange("day")}
|
||||||
|
>
|
||||||
|
Last day
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="group"
|
||||||
|
filled={(dateRange === "week").toString()}
|
||||||
|
onClick={() => setDateRange("week")}
|
||||||
|
>
|
||||||
|
Last week
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
variant="group"
|
||||||
|
filled={(dateRange === "all").toString()}
|
||||||
|
onClick={() => setDateRange("all")}
|
||||||
|
>
|
||||||
|
All
|
||||||
|
</Button>
|
||||||
|
</ButtonGroup>
|
||||||
|
</Stack>
|
||||||
</Stack>
|
</Stack>
|
||||||
<IncidentTable
|
<IncidentTable
|
||||||
monitors={monitors}
|
monitors={monitors}
|
||||||
selectedMonitor={selectedMonitor}
|
selectedMonitor={selectedMonitor}
|
||||||
filter={filter}
|
filter={filter}
|
||||||
|
dateRange={dateRange}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import { Box, Button, IconButton, Stack } from "@mui/material";
|
|||||||
import Breadcrumbs from "../../Components/Breadcrumbs";
|
import Breadcrumbs from "../../Components/Breadcrumbs";
|
||||||
import { StatusLabel } from "../../Components/Label";
|
import { StatusLabel } from "../../Components/Label";
|
||||||
import { Heading } from "../../Components/Heading";
|
import { Heading } from "../../Components/Heading";
|
||||||
import { Pagination } from "../../Components/Table/TablePagination/index.jsx";
|
import Pagination from "../../Components/Table/TablePagination/index.jsx";
|
||||||
// import { getInfrastructureMonitorsByTeamId } from "../../Features/InfrastructureMonitors/infrastructureMonitorsSlice";
|
// import { getInfrastructureMonitorsByTeamId } from "../../Features/InfrastructureMonitors/infrastructureMonitorsSlice";
|
||||||
import { networkService } from "../../Utils/NetworkService.js";
|
import { networkService } from "../../Utils/NetworkService.js";
|
||||||
import CustomGauge from "../../Components/Charts/CustomGauge/index.jsx";
|
import CustomGauge from "../../Components/Charts/CustomGauge/index.jsx";
|
||||||
@@ -269,7 +269,8 @@ function Infrastructure() {
|
|||||||
/>
|
/>
|
||||||
|
|
||||||
<Pagination
|
<Pagination
|
||||||
monitorCount={summary?.totalMonitors ?? 0}
|
itemCount={summary?.totalMonitors ?? 0}
|
||||||
|
paginationLabel="monitors"
|
||||||
page={page}
|
page={page}
|
||||||
rowsPerPage={rowsPerPage}
|
rowsPerPage={rowsPerPage}
|
||||||
handleChangePage={handleChangePage}
|
handleChangePage={handleChangePage}
|
||||||
|
|||||||
@@ -108,16 +108,16 @@ const CreateMonitor = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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({
|
// createToast({
|
||||||
body: "The endpoint you entered doesn't resolve. Check the URL again.",
|
// body: "The endpoint you entered doesn't resolve. Check the URL again.",
|
||||||
});
|
// });
|
||||||
setErrors({ url: "The entered URL is not reachable." });
|
// setErrors({ url: "The entered URL is not reachable." });
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
form = {
|
form = {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import SkeletonLayout from "./skeleton";
|
|||||||
import Fallback from "./fallback";
|
import Fallback from "./fallback";
|
||||||
import StatusBox from "./StatusBox";
|
import StatusBox from "./StatusBox";
|
||||||
import UptimeDataTable from "./UptimeDataTable";
|
import UptimeDataTable from "./UptimeDataTable";
|
||||||
import { Pagination } from "../../../Components/Table/TablePagination";
|
import Pagination from "../../../Components/Table/TablePagination";
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
import { useTheme } from "@emotion/react";
|
import { useTheme } from "@emotion/react";
|
||||||
@@ -225,7 +225,8 @@ const UptimeMonitors = () => {
|
|||||||
triggerUpdate={triggerUpdate}
|
triggerUpdate={triggerUpdate}
|
||||||
/>
|
/>
|
||||||
<Pagination
|
<Pagination
|
||||||
monitorCount={totalMonitors}
|
itemCount={totalMonitors}
|
||||||
|
paginationLabel="monitors"
|
||||||
page={page}
|
page={page}
|
||||||
rowsPerPage={rowsPerPage}
|
rowsPerPage={rowsPerPage}
|
||||||
handleChangePage={handleChangePage}
|
handleChangePage={handleChangePage}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class CheckController {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
getChecks = async (req, res, next) => {
|
getChecksByMonitor = async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
await getChecksParamValidation.validateAsync(req.params);
|
await getChecksParamValidation.validateAsync(req.params);
|
||||||
await getChecksQueryValidation.validateAsync(req.query);
|
await getChecksQueryValidation.validateAsync(req.query);
|
||||||
@@ -54,19 +54,18 @@ class CheckController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const checks = await this.db.getChecks(req);
|
const result = await this.db.getChecksByMonitor(req);
|
||||||
const checksCount = await this.db.getChecksCount(req);
|
|
||||||
|
|
||||||
return res.success({
|
return res.success({
|
||||||
msg: successMessages.CHECK_GET,
|
msg: successMessages.CHECK_GET,
|
||||||
data: { checksCount, checks },
|
data: result,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(handleError(error, SERVICE_NAME, "getChecks"));
|
next(handleError(error, SERVICE_NAME, "getChecks"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
getTeamChecks = async (req, res, next) => {
|
getChecksByTeam = async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
await getTeamChecksParamValidation.validateAsync(req.params);
|
await getTeamChecksParamValidation.validateAsync(req.params);
|
||||||
await getTeamChecksQueryValidation.validateAsync(req.query);
|
await getTeamChecksQueryValidation.validateAsync(req.query);
|
||||||
@@ -75,7 +74,7 @@ class CheckController {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const checkData = await this.db.getTeamChecks(req);
|
const checkData = await this.db.getChecksByTeam(req);
|
||||||
|
|
||||||
return res.success({
|
return res.success({
|
||||||
msg: successMessages.CHECK_GET,
|
msg: successMessages.CHECK_GET,
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ 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 axios from "axios";
|
import axios from "axios";
|
||||||
|
import seedDb from "../db/mongo/utils/seedDb.js";
|
||||||
const SERVICE_NAME = "monitorController";
|
const SERVICE_NAME = "monitorController";
|
||||||
|
|
||||||
class MonitorController {
|
class MonitorController {
|
||||||
@@ -495,6 +495,17 @@ class MonitorController {
|
|||||||
next(handleError(error, SERVICE_NAME, "getMonitorsByTeamId"));
|
next(handleError(error, SERVICE_NAME, "getMonitorsByTeamId"));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
seedDb = async (req, res, next) => {
|
||||||
|
try {
|
||||||
|
const token = getTokenFromHeaders(req.headers);
|
||||||
|
const { jwtSecret } = this.settingsService.getSettings();
|
||||||
|
const { _id, teamId } = jwt.verify(token, jwtSecret);
|
||||||
|
await seedDb(_id, teamId);
|
||||||
|
} catch (error) {
|
||||||
|
next(handleError(error, SERVICE_NAME, "seedDb"));
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export default MonitorController;
|
export default MonitorController;
|
||||||
@@ -12,6 +12,13 @@ const BaseCheckSchema = mongoose.Schema({
|
|||||||
immutable: true,
|
immutable: true,
|
||||||
index: true,
|
index: true,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
teamId: {
|
||||||
|
type: mongoose.Schema.Types.ObjectId,
|
||||||
|
ref: "Team",
|
||||||
|
immutable: true,
|
||||||
|
index: true,
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* Status of the check (true for up, false for down).
|
* Status of the check (true for up, false for down).
|
||||||
*
|
*
|
||||||
@@ -69,6 +76,8 @@ const CheckSchema = mongoose.Schema({ ...BaseCheckSchema.obj }, { timestamps: tr
|
|||||||
CheckSchema.index({ createdAt: 1 });
|
CheckSchema.index({ createdAt: 1 });
|
||||||
CheckSchema.index({ monitorId: 1, createdAt: 1 });
|
CheckSchema.index({ monitorId: 1, createdAt: 1 });
|
||||||
CheckSchema.index({ monitorId: 1, createdAt: -1 });
|
CheckSchema.index({ monitorId: 1, createdAt: -1 });
|
||||||
|
CheckSchema.index({ teamId: 1, createdAt: -1 });
|
||||||
|
CheckSchema.index({ teamId: 1 });
|
||||||
|
|
||||||
export default mongoose.model("Check", CheckSchema);
|
export default mongoose.model("Check", CheckSchema);
|
||||||
export { BaseCheckSchema };
|
export { BaseCheckSchema };
|
||||||
@@ -2,11 +2,15 @@ import Check from "../../models/Check.js";
|
|||||||
import Monitor from "../../models/Monitor.js";
|
import Monitor from "../../models/Monitor.js";
|
||||||
import User from "../../models/User.js";
|
import User from "../../models/User.js";
|
||||||
import logger from "../../../utils/logger.js";
|
import logger from "../../../utils/logger.js";
|
||||||
|
import { ObjectId } from "mongodb";
|
||||||
|
|
||||||
const SERVICE_NAME = "checkModule";
|
const SERVICE_NAME = "checkModule";
|
||||||
const dateRangeLookup = {
|
const dateRangeLookup = {
|
||||||
|
hour: new Date(new Date().setHours(new Date().getHours() - 1)),
|
||||||
day: new Date(new Date().setDate(new Date().getDate() - 1)),
|
day: new Date(new Date().setDate(new Date().getDate() - 1)),
|
||||||
week: new Date(new Date().setDate(new Date().getDate() - 7)),
|
week: new Date(new Date().setDate(new Date().getDate() - 7)),
|
||||||
month: new Date(new Date().setMonth(new Date().getMonth() - 1)),
|
month: new Date(new Date().setMonth(new Date().getMonth() - 1)),
|
||||||
|
all: undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -56,41 +60,6 @@ const createCheck = async (checkData) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getChecksCount = async (req) => {
|
|
||||||
const monitorId = req.params.monitorId;
|
|
||||||
const dateRange = req.query.dateRange;
|
|
||||||
const filter = req.query.filter;
|
|
||||||
// Build query
|
|
||||||
const checksQuery = { monitorId: monitorId };
|
|
||||||
// Filter checks by "day", "week", or "month"
|
|
||||||
if (dateRange !== undefined) {
|
|
||||||
checksQuery.createdAt = { $gte: dateRangeLookup[dateRange] };
|
|
||||||
}
|
|
||||||
|
|
||||||
if (filter !== undefined) {
|
|
||||||
checksQuery.status = false;
|
|
||||||
switch (filter) {
|
|
||||||
case "all":
|
|
||||||
break;
|
|
||||||
case "down":
|
|
||||||
break;
|
|
||||||
case "resolve":
|
|
||||||
checksQuery.statusCode = 5000;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
logger.warn({
|
|
||||||
message: "invalid filter",
|
|
||||||
service: SERVICE_NAME,
|
|
||||||
method: "getChecksCount",
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const count = await Check.countDocuments(checksQuery);
|
|
||||||
return count;
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all checks for a monitor
|
* Get all checks for a monitor
|
||||||
* @async
|
* @async
|
||||||
@@ -98,33 +67,31 @@ const getChecksCount = async (req) => {
|
|||||||
* @returns {Promise<Array<Check>>}
|
* @returns {Promise<Array<Check>>}
|
||||||
* @throws {Error}
|
* @throws {Error}
|
||||||
*/
|
*/
|
||||||
|
const getChecksByMonitor = async (req) => {
|
||||||
const getChecks = async (req) => {
|
|
||||||
try {
|
try {
|
||||||
const { monitorId } = req.params;
|
const { monitorId } = req.params;
|
||||||
let { sortOrder, limit, dateRange, filter, page, rowsPerPage } = req.query;
|
let { sortOrder, dateRange, filter, page, rowsPerPage } = req.query;
|
||||||
// Default limit to 0 if not provided
|
page = parseInt(page);
|
||||||
limit = limit === undefined ? 0 : limit;
|
rowsPerPage = parseInt(rowsPerPage);
|
||||||
|
// Match
|
||||||
|
const matchStage = {
|
||||||
|
monitorId: ObjectId.createFromHexString(monitorId),
|
||||||
|
status: false,
|
||||||
|
...(dateRangeLookup[dateRange] && {
|
||||||
|
createdAt: {
|
||||||
|
$gte: dateRangeLookup[dateRange],
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
// Default sort order is newest -> oldest
|
|
||||||
sortOrder = sortOrder === "asc" ? 1 : -1;
|
|
||||||
|
|
||||||
// Build query
|
|
||||||
const checksQuery = { monitorId: monitorId };
|
|
||||||
// Filter checks by "day", "week", or "month"
|
|
||||||
if (dateRange !== undefined) {
|
|
||||||
checksQuery.createdAt = { $gte: dateRangeLookup[dateRange] };
|
|
||||||
}
|
|
||||||
// Filter checks by status
|
|
||||||
if (filter !== undefined) {
|
if (filter !== undefined) {
|
||||||
checksQuery.status = false;
|
|
||||||
switch (filter) {
|
switch (filter) {
|
||||||
case "all":
|
case "all":
|
||||||
break;
|
break;
|
||||||
case "down":
|
case "down":
|
||||||
break;
|
break;
|
||||||
case "resolve":
|
case "resolve":
|
||||||
checksQuery.statusCode = 5000;
|
matchStage.statusCode = 5000;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
logger.warn({
|
logger.warn({
|
||||||
@@ -136,16 +103,33 @@ const getChecks = async (req) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Need to skip and limit here
|
//Sort
|
||||||
|
sortOrder = sortOrder === "asc" ? 1 : -1;
|
||||||
|
|
||||||
|
// Pagination
|
||||||
let skip = 0;
|
let skip = 0;
|
||||||
if (page && rowsPerPage) {
|
if (page && rowsPerPage) {
|
||||||
skip = page * rowsPerPage;
|
skip = page * rowsPerPage;
|
||||||
}
|
}
|
||||||
const checks = await Check.find(checksQuery)
|
|
||||||
.skip(skip)
|
const checks = await Check.aggregate([
|
||||||
.limit(rowsPerPage)
|
{ $match: matchStage },
|
||||||
.sort({ createdAt: sortOrder });
|
{ $sort: { createdAt: sortOrder } },
|
||||||
return checks;
|
{
|
||||||
|
$facet: {
|
||||||
|
summary: [{ $count: "checksCount" }],
|
||||||
|
checks: [{ $skip: skip }, { $limit: rowsPerPage }],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
$project: {
|
||||||
|
checksCount: { $arrayElemAt: ["$summary.checksCount", 0] },
|
||||||
|
checks: "$checks",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
return checks[0];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
error.service = SERVICE_NAME;
|
error.service = SERVICE_NAME;
|
||||||
error.method = "getChecks";
|
error.method = "getChecks";
|
||||||
@@ -153,64 +137,71 @@ const getChecks = async (req) => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const getTeamChecks = async (req) => {
|
const getChecksByTeam = async (req) => {
|
||||||
try {
|
try {
|
||||||
|
let { sortOrder, dateRange, filter, page, rowsPerPage } = req.query;
|
||||||
|
page = parseInt(page);
|
||||||
|
rowsPerPage = parseInt(rowsPerPage);
|
||||||
const { teamId } = req.params;
|
const { teamId } = req.params;
|
||||||
let { sortOrder, limit, dateRange, filter, page, rowsPerPage } = req.query;
|
const matchStage = {
|
||||||
|
teamId: ObjectId.createFromHexString(teamId),
|
||||||
// Get monitorIDs
|
status: false,
|
||||||
const userMonitors = await Monitor.find({ teamId: teamId }).select("_id");
|
...(dateRangeLookup[dateRange] && {
|
||||||
|
createdAt: {
|
||||||
//Build check query
|
$gte: dateRangeLookup[dateRange],
|
||||||
// Default limit to 0 if not provided
|
},
|
||||||
limit = limit === undefined ? 0 : limit;
|
}),
|
||||||
// Default sort order is newest -> oldest
|
};
|
||||||
sortOrder = sortOrder === "asc" ? 1 : -1;
|
// Add filter to match stage
|
||||||
|
|
||||||
const checksQuery = { monitorId: { $in: userMonitors } };
|
|
||||||
|
|
||||||
if (filter !== undefined) {
|
if (filter !== undefined) {
|
||||||
checksQuery.status = false;
|
|
||||||
switch (filter) {
|
switch (filter) {
|
||||||
case "all":
|
case "all":
|
||||||
break;
|
break;
|
||||||
case "down":
|
case "down":
|
||||||
checksQuery.status = false;
|
|
||||||
break;
|
break;
|
||||||
case "resolve":
|
case "resolve":
|
||||||
checksQuery.statusCode = 5000;
|
matchStage.statusCode = 5000;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
logger.warn({
|
logger.warn({
|
||||||
message: "invalid filter",
|
message: "invalid filter",
|
||||||
service: SERVICE_NAME,
|
service: SERVICE_NAME,
|
||||||
method: "getTeamChecks",
|
method: "getChecksByTeam",
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dateRange !== undefined) {
|
sortOrder = sortOrder === "asc" ? 1 : -1;
|
||||||
checksQuery.createdAt = { $gte: dateRangeLookup[dateRange] };
|
|
||||||
}
|
|
||||||
|
|
||||||
// Skip and limit for pagination
|
// pagination
|
||||||
let skip = 0;
|
let skip = 0;
|
||||||
if (page && rowsPerPage) {
|
if (page && rowsPerPage) {
|
||||||
skip = page * rowsPerPage;
|
skip = page * rowsPerPage;
|
||||||
}
|
}
|
||||||
|
|
||||||
const checksCount = await Check.countDocuments(checksQuery);
|
const checks = await Check.aggregate([
|
||||||
|
{ $match: matchStage },
|
||||||
|
{ $sort: { createdAt: sortOrder } },
|
||||||
|
|
||||||
const checks = await Check.find(checksQuery)
|
{
|
||||||
.skip(skip)
|
$facet: {
|
||||||
.limit(rowsPerPage)
|
summary: [{ $count: "checksCount" }],
|
||||||
.sort({ createdAt: sortOrder })
|
checks: [{ $skip: skip }, { $limit: rowsPerPage }],
|
||||||
.select(["monitorId", "status", "responseTime", "statusCode", "message"]);
|
},
|
||||||
return { checksCount, checks };
|
},
|
||||||
|
{
|
||||||
|
$project: {
|
||||||
|
checksCount: { $arrayElemAt: ["$summary.checksCount", 0] },
|
||||||
|
checks: "$checks",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
|
||||||
|
return checks[0];
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
error.service = SERVICE_NAME;
|
error.service = SERVICE_NAME;
|
||||||
error.method = "getTeamChecks";
|
error.method = "getChecksByTeam";
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -298,9 +289,8 @@ const updateChecksTTL = async (teamId, ttl) => {
|
|||||||
|
|
||||||
export {
|
export {
|
||||||
createCheck,
|
createCheck,
|
||||||
getChecksCount,
|
getChecksByMonitor,
|
||||||
getChecks,
|
getChecksByTeam,
|
||||||
getTeamChecks,
|
|
||||||
deleteChecks,
|
deleteChecks,
|
||||||
deleteChecksByTeamId,
|
deleteChecksByTeamId,
|
||||||
updateChecksTTL,
|
updateChecksTTL,
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
import Monitor from "../../models/Monitor.js";
|
||||||
|
import Check from "../../models/Check.js";
|
||||||
|
|
||||||
|
const generateRandomUrl = () => {
|
||||||
|
const domains = ["example.com", "test.org", "demo.net", "sample.io", "mock.dev"];
|
||||||
|
const paths = ["api", "status", "health", "ping", "check"];
|
||||||
|
return `https://${domains[Math.floor(Math.random() * domains.length)]}/${paths[Math.floor(Math.random() * paths.length)]}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const generateChecks = (monitorId, teamId, count) => {
|
||||||
|
const checks = [];
|
||||||
|
const endTime = new Date(Date.now() - 10 * 60 * 1000); // 10 minutes ago
|
||||||
|
const startTime = new Date(endTime - count * 60 * 1000); // count minutes before endTime
|
||||||
|
|
||||||
|
for (let i = 0; i < count; i++) {
|
||||||
|
const timestamp = new Date(startTime.getTime() + i * 60 * 1000);
|
||||||
|
const status = Math.random() > 0.05; // 95% chance of being up
|
||||||
|
|
||||||
|
checks.push({
|
||||||
|
monitorId,
|
||||||
|
teamId,
|
||||||
|
status,
|
||||||
|
responseTime: Math.floor(Math.random() * 1000), // Random response time between 0-1000ms
|
||||||
|
createdAt: timestamp,
|
||||||
|
updatedAt: timestamp,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return checks;
|
||||||
|
};
|
||||||
|
|
||||||
|
const seedDb = async (userId, teamId) => {
|
||||||
|
try {
|
||||||
|
console.log("Deleting all monitors and checks");
|
||||||
|
await Monitor.deleteMany({});
|
||||||
|
await Check.deleteMany({});
|
||||||
|
console.log("Adding monitors");
|
||||||
|
for (let i = 0; i < 300; i++) {
|
||||||
|
const monitor = await Monitor.create({
|
||||||
|
name: `Monitor ${i}`,
|
||||||
|
url: generateRandomUrl(),
|
||||||
|
type: "http",
|
||||||
|
userId,
|
||||||
|
teamId,
|
||||||
|
interval: 60000,
|
||||||
|
active: false,
|
||||||
|
});
|
||||||
|
console.log(`Adding monitor and checks for monitor ${i}`);
|
||||||
|
const checks = generateChecks(monitor._id, teamId, 10000);
|
||||||
|
await Check.insertMany(checks);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default seedDb;
|
||||||
@@ -11,7 +11,7 @@ class CheckRoutes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
initRoutes() {
|
initRoutes() {
|
||||||
this.router.get("/:monitorId", this.checkController.getChecks);
|
this.router.get("/:monitorId", this.checkController.getChecksByMonitor);
|
||||||
this.router.post(
|
this.router.post(
|
||||||
"/:monitorId",
|
"/:monitorId",
|
||||||
verifyOwnership(Monitor, "monitorId"),
|
verifyOwnership(Monitor, "monitorId"),
|
||||||
@@ -23,7 +23,7 @@ class CheckRoutes {
|
|||||||
this.checkController.deleteChecks
|
this.checkController.deleteChecks
|
||||||
);
|
);
|
||||||
|
|
||||||
this.router.get("/team/:teamId", this.checkController.getTeamChecks);
|
this.router.get("/team/:teamId", this.checkController.getChecksByTeam);
|
||||||
|
|
||||||
this.router.delete(
|
this.router.delete(
|
||||||
"/team/:teamId",
|
"/team/:teamId",
|
||||||
|
|||||||
@@ -75,6 +75,8 @@ class MonitorRoutes {
|
|||||||
isAllowed(["admin", "superadmin"]),
|
isAllowed(["admin", "superadmin"]),
|
||||||
this.monitorController.addDemoMonitors
|
this.monitorController.addDemoMonitors
|
||||||
);
|
);
|
||||||
|
|
||||||
|
this.router.post("/seed", isAllowed(["superadmin"]), this.monitorController.seedDb);
|
||||||
}
|
}
|
||||||
|
|
||||||
getRouter() {
|
getRouter() {
|
||||||
|
|||||||
@@ -131,6 +131,7 @@ class NetworkService {
|
|||||||
|
|
||||||
const httpResponse = {
|
const httpResponse = {
|
||||||
monitorId: job.data._id,
|
monitorId: job.data._id,
|
||||||
|
teamId: job.data.teamId,
|
||||||
type: job.data.type,
|
type: job.data.type,
|
||||||
responseTime,
|
responseTime,
|
||||||
payload: response?.data,
|
payload: response?.data,
|
||||||
|
|||||||
@@ -83,10 +83,11 @@ class StatusService {
|
|||||||
* @returns {Object} The check object.
|
* @returns {Object} The check object.
|
||||||
*/
|
*/
|
||||||
buildCheck = (networkResponse) => {
|
buildCheck = (networkResponse) => {
|
||||||
const { monitorId, type, status, responseTime, code, message, payload } =
|
const { monitorId, teamId, type, status, responseTime, code, message, payload } =
|
||||||
networkResponse;
|
networkResponse;
|
||||||
const check = {
|
const check = {
|
||||||
monitorId,
|
monitorId,
|
||||||
|
teamId,
|
||||||
status,
|
status,
|
||||||
statusCode: code,
|
statusCode: code,
|
||||||
responseTime,
|
responseTime,
|
||||||
|
|||||||
@@ -131,7 +131,7 @@ const getMonitorByIdQueryValidation = joi.object({
|
|||||||
status: joi.boolean(),
|
status: joi.boolean(),
|
||||||
sortOrder: joi.string().valid("asc", "desc"),
|
sortOrder: joi.string().valid("asc", "desc"),
|
||||||
limit: joi.number(),
|
limit: joi.number(),
|
||||||
dateRange: joi.string().valid("day", "week", "month"),
|
dateRange: joi.string().valid("hour", "day", "week", "month", "all"),
|
||||||
numToDisplay: joi.number(),
|
numToDisplay: joi.number(),
|
||||||
normalize: joi.boolean(),
|
normalize: joi.boolean(),
|
||||||
});
|
});
|
||||||
@@ -166,7 +166,7 @@ const getMonitorStatsByIdQueryValidation = joi.object({
|
|||||||
status: joi.string(),
|
status: joi.string(),
|
||||||
limit: joi.number(),
|
limit: joi.number(),
|
||||||
sortOrder: joi.string().valid("asc", "desc"),
|
sortOrder: joi.string().valid("asc", "desc"),
|
||||||
dateRange: joi.string().valid("day", "week", "month", "all"),
|
dateRange: joi.string().valid("hour", "day", "week", "month", "all"),
|
||||||
numToDisplay: joi.number(),
|
numToDisplay: joi.number(),
|
||||||
normalize: joi.boolean(),
|
normalize: joi.boolean(),
|
||||||
});
|
});
|
||||||
@@ -217,7 +217,7 @@ const getHardwareDetailsByIdParamValidation = joi.object({
|
|||||||
});
|
});
|
||||||
|
|
||||||
const getHardwareDetailsByIdQueryValidation = joi.object({
|
const getHardwareDetailsByIdQueryValidation = joi.object({
|
||||||
dateRange: joi.string().valid("day", "week", "month"),
|
dateRange: joi.string().valid("hour", "day", "week", "month", "all"),
|
||||||
});
|
});
|
||||||
|
|
||||||
//****************************************
|
//****************************************
|
||||||
@@ -288,7 +288,7 @@ const getChecksParamValidation = joi.object({
|
|||||||
const getChecksQueryValidation = joi.object({
|
const getChecksQueryValidation = joi.object({
|
||||||
sortOrder: joi.string().valid("asc", "desc"),
|
sortOrder: joi.string().valid("asc", "desc"),
|
||||||
limit: joi.number(),
|
limit: joi.number(),
|
||||||
dateRange: joi.string().valid("day", "week", "month"),
|
dateRange: joi.string().valid("hour", "day", "week", "month", "all"),
|
||||||
filter: joi.string().valid("all", "down", "resolve"),
|
filter: joi.string().valid("all", "down", "resolve"),
|
||||||
page: joi.number(),
|
page: joi.number(),
|
||||||
rowsPerPage: joi.number(),
|
rowsPerPage: joi.number(),
|
||||||
@@ -301,7 +301,7 @@ const getTeamChecksParamValidation = joi.object({
|
|||||||
const getTeamChecksQueryValidation = joi.object({
|
const getTeamChecksQueryValidation = joi.object({
|
||||||
sortOrder: joi.string().valid("asc", "desc"),
|
sortOrder: joi.string().valid("asc", "desc"),
|
||||||
limit: joi.number(),
|
limit: joi.number(),
|
||||||
dateRange: joi.string().valid("day", "week", "month"),
|
dateRange: joi.string().valid("hour", "day", "week", "month", "all"),
|
||||||
filter: joi.string().valid("all", "down", "resolve"),
|
filter: joi.string().valid("all", "down", "resolve"),
|
||||||
page: joi.number(),
|
page: joi.number(),
|
||||||
rowsPerPage: joi.number(),
|
rowsPerPage: joi.number(),
|
||||||
|
|||||||
Reference in new issue
Block a user