Merge pull request #1149 from bluewave-labs/1067-fe-hardware-monitoring-create-hardware-monitor
1067 fe hardware monitoring create hardware monitor
This commit is contained in:
14 files changed
+1015
-12
No files matched your search
+5
-1
@@ -10,6 +10,7 @@ import Register from "./Pages/Auth/Register/Register";
|
|||||||
import Account from "./Pages/Account";
|
import Account from "./Pages/Account";
|
||||||
import Monitors from "./Pages/Monitors/Home";
|
import Monitors from "./Pages/Monitors/Home";
|
||||||
import CreateMonitor from "./Pages/Monitors/CreateMonitor";
|
import CreateMonitor from "./Pages/Monitors/CreateMonitor";
|
||||||
|
import CreateInfrastructureMonitor from "./Pages/Infrastructure/CreateMonitor";
|
||||||
import Incidents from "./Pages/Incidents";
|
import Incidents from "./Pages/Incidents";
|
||||||
import Status from "./Pages/Status";
|
import Status from "./Pages/Status";
|
||||||
import Integrations from "./Pages/Integrations";
|
import Integrations from "./Pages/Integrations";
|
||||||
@@ -127,7 +128,10 @@ function App() {
|
|||||||
path="infrastructure"
|
path="infrastructure"
|
||||||
element={<ProtectedRoute Component={Infrastructure} />}
|
element={<ProtectedRoute Component={Infrastructure} />}
|
||||||
/>
|
/>
|
||||||
|
<Route
|
||||||
|
path="infrastructure/create"
|
||||||
|
element={<ProtectedRoute Component={CreateInfrastructureMonitor} />}
|
||||||
|
/>
|
||||||
<Route
|
<Route
|
||||||
path="incidents/:monitorId?"
|
path="incidents/:monitorId?"
|
||||||
element={<ProtectedRoute Component={Incidents} />}
|
element={<ProtectedRoute Component={Incidents} />}
|
||||||
|
|||||||
@@ -40,7 +40,6 @@ const Checkbox = ({
|
|||||||
/* TODO move sizes to theme */
|
/* TODO move sizes to theme */
|
||||||
const sizes = { small: "14px", medium: "16px", large: "18px" };
|
const sizes = { small: "14px", medium: "16px", large: "18px" };
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FormControlLabel
|
<FormControlLabel
|
||||||
className="checkbox-wrapper"
|
className="checkbox-wrapper"
|
||||||
@@ -58,6 +57,7 @@ const Checkbox = ({
|
|||||||
sx={{
|
sx={{
|
||||||
"&:hover": { backgroundColor: "transparent" },
|
"&:hover": { backgroundColor: "transparent" },
|
||||||
"& svg": { width: sizes[size], height: sizes[size] },
|
"& svg": { width: sizes[size], height: sizes[size] },
|
||||||
|
alignSelf: "flex-start",
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
@@ -66,7 +66,6 @@ const Checkbox = ({
|
|||||||
sx={{
|
sx={{
|
||||||
borderRadius: theme.shape.borderRadius,
|
borderRadius: theme.shape.borderRadius,
|
||||||
p: theme.spacing(2.5),
|
p: theme.spacing(2.5),
|
||||||
m: theme.spacing(-2.5),
|
|
||||||
"& .MuiButtonBase-root": {
|
"& .MuiButtonBase-root": {
|
||||||
width: theme.spacing(10),
|
width: theme.spacing(10),
|
||||||
p: 0,
|
p: 0,
|
||||||
@@ -90,7 +89,7 @@ const Checkbox = ({
|
|||||||
|
|
||||||
Checkbox.propTypes = {
|
Checkbox.propTypes = {
|
||||||
id: PropTypes.string.isRequired,
|
id: PropTypes.string.isRequired,
|
||||||
label: PropTypes.string.isRequired,
|
label: PropTypes.oneOfType([PropTypes.string, PropTypes.node]).isRequired,
|
||||||
size: PropTypes.oneOf(["small", "medium", "large"]),
|
size: PropTypes.oneOf(["small", "medium", "large"]),
|
||||||
isChecked: PropTypes.bool.isRequired,
|
isChecked: PropTypes.bool.isRequired,
|
||||||
value: PropTypes.string,
|
value: PropTypes.string,
|
||||||
|
|||||||
@@ -1,6 +1,15 @@
|
|||||||
.field {
|
.field {
|
||||||
min-width: 250px;
|
min-width: var(--env-var-width-3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.field-infrastructure-alert {
|
||||||
|
max-width: var(--env-var-width-4);
|
||||||
|
}
|
||||||
|
|
||||||
|
.field-infrastructure-alert .MuiInputBase-root:has(input) {
|
||||||
|
height: var(--env-var-height-2);
|
||||||
|
}
|
||||||
|
|
||||||
.field h3.MuiTypography-root,
|
.field h3.MuiTypography-root,
|
||||||
.field h5.MuiTypography-root,
|
.field h5.MuiTypography-root,
|
||||||
.field input,
|
.field input,
|
||||||
@@ -14,7 +23,7 @@
|
|||||||
padding-right: var(--env-var-spacing-1-minus);
|
padding-right: var(--env-var-spacing-1-minus);
|
||||||
}
|
}
|
||||||
.field .MuiInputBase-root:has(input) {
|
.field .MuiInputBase-root:has(input) {
|
||||||
height: 34px;
|
height: var(--env-var-height-2);
|
||||||
}
|
}
|
||||||
.field .MuiInputBase-root:has(.MuiInputAdornment-root) {
|
.field .MuiInputBase-root:has(.MuiInputAdornment-root) {
|
||||||
padding-right: var(--env-var-spacing-1-minus);
|
padding-right: var(--env-var-spacing-1-minus);
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ const Field = forwardRef(
|
|||||||
error,
|
error,
|
||||||
disabled,
|
disabled,
|
||||||
hidden,
|
hidden,
|
||||||
|
className
|
||||||
},
|
},
|
||||||
ref
|
ref
|
||||||
) => {
|
) => {
|
||||||
@@ -56,7 +57,7 @@ const Field = forwardRef(
|
|||||||
return (
|
return (
|
||||||
<Stack
|
<Stack
|
||||||
gap={theme.spacing(2)}
|
gap={theme.spacing(2)}
|
||||||
className={`field field-${type}`}
|
className={`${className ?? `field field-${type}`}`}
|
||||||
sx={{
|
sx={{
|
||||||
"& fieldset": {
|
"& fieldset": {
|
||||||
borderColor: theme.palette.border.dark,
|
borderColor: theme.palette.border.dark,
|
||||||
@@ -185,10 +186,11 @@ const Field = forwardRef(
|
|||||||
),
|
),
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
{error && (
|
{ error && (
|
||||||
<Typography
|
<Typography
|
||||||
component="span"
|
component="span"
|
||||||
className="input-error"
|
className="input-error"
|
||||||
|
hidden={className? true: false}
|
||||||
color={theme.palette.error.main}
|
color={theme.palette.error.main}
|
||||||
mt={theme.spacing(2)}
|
mt={theme.spacing(2)}
|
||||||
sx={{
|
sx={{
|
||||||
@@ -223,6 +225,7 @@ Field.propTypes = {
|
|||||||
error: PropTypes.string,
|
error: PropTypes.string,
|
||||||
disabled: PropTypes.bool,
|
disabled: PropTypes.bool,
|
||||||
hidden: PropTypes.bool,
|
hidden: PropTypes.bool,
|
||||||
|
className: PropTypes.string
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Field;
|
export default Field;
|
||||||
@@ -90,6 +90,7 @@ const URL_MAP = {
|
|||||||
const PATH_MAP = {
|
const PATH_MAP = {
|
||||||
monitors: "Dashboard",
|
monitors: "Dashboard",
|
||||||
pagespeed: "Dashboard",
|
pagespeed: "Dashboard",
|
||||||
|
infrastructure: "Dashboard",
|
||||||
account: "Account",
|
account: "Account",
|
||||||
settings: "Other",
|
settings: "Other",
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,406 @@
|
|||||||
|
import { createAsyncThunk, createSlice } from "@reduxjs/toolkit";
|
||||||
|
import { jwtDecode } from "jwt-decode";
|
||||||
|
import { networkService } from "../../main";
|
||||||
|
const initialState = {
|
||||||
|
isLoading: false,
|
||||||
|
monitorsSummary: [],
|
||||||
|
success: null,
|
||||||
|
msg: null,
|
||||||
|
};
|
||||||
|
|
||||||
|
export const createInfrastructureMonitor = createAsyncThunk(
|
||||||
|
"infrastructureMonitors/createMonitor",
|
||||||
|
async (data, thunkApi) => {
|
||||||
|
try {
|
||||||
|
const { authToken, monitor } = data;
|
||||||
|
const res = await networkService.createMonitor({
|
||||||
|
authToken: authToken,
|
||||||
|
monitor: monitor,
|
||||||
|
});
|
||||||
|
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 checkInfrastructureEndpointResolution = createAsyncThunk(
|
||||||
|
"infrastructureMonitors/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 getInfrastructureMonitorById = createAsyncThunk(
|
||||||
|
"infrastructureMonitors/getMonitorById",
|
||||||
|
async (data, thunkApi) => {
|
||||||
|
try {
|
||||||
|
const { authToken, monitorId } = data;
|
||||||
|
const res = await networkService.getMonitorById({
|
||||||
|
authToken: authToken,
|
||||||
|
monitorId: monitorId,
|
||||||
|
});
|
||||||
|
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 getInfrastructureMonitorsByTeamId = createAsyncThunk(
|
||||||
|
"infrastructureMonitors/getMonitorsByTeamId",
|
||||||
|
async (token, thunkApi) => {
|
||||||
|
const user = jwtDecode(token);
|
||||||
|
try {
|
||||||
|
const res = await networkService.getMonitorsAndSummaryByTeamId({
|
||||||
|
authToken: token,
|
||||||
|
teamId: user.teamId,
|
||||||
|
types: ["hardware"],
|
||||||
|
});
|
||||||
|
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 updateInfrastructureMonitor = createAsyncThunk(
|
||||||
|
"infrastructureMonitors/updateMonitor",
|
||||||
|
async (data, thunkApi) => {
|
||||||
|
try {
|
||||||
|
const { authToken, monitor } = data;
|
||||||
|
const updatedFields = {
|
||||||
|
name: monitor.name,
|
||||||
|
description: monitor.description,
|
||||||
|
interval: monitor.interval,
|
||||||
|
notifications: monitor.notifications,
|
||||||
|
threshold: monitor.threshold
|
||||||
|
};
|
||||||
|
const res = await networkService.updateMonitor({
|
||||||
|
authToken: authToken,
|
||||||
|
monitorId: monitor._id,
|
||||||
|
updatedFields: updatedFields,
|
||||||
|
});
|
||||||
|
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 deleteInfrastructureMonitor = createAsyncThunk(
|
||||||
|
"infrastructureMonitors/deleteMonitor",
|
||||||
|
async (data, thunkApi) => {
|
||||||
|
try {
|
||||||
|
const { authToken, monitor } = data;
|
||||||
|
const res = await networkService.deleteMonitorById({
|
||||||
|
authToken: authToken,
|
||||||
|
monitorId: monitor._id,
|
||||||
|
});
|
||||||
|
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 pauseInfrastructureMonitor = createAsyncThunk(
|
||||||
|
"infrastructureMonitors/pauseMonitor",
|
||||||
|
async (data, thunkApi) => {
|
||||||
|
try {
|
||||||
|
const { authToken, monitorId } = data;
|
||||||
|
const res = await networkService.pauseMonitorById({
|
||||||
|
authToken: authToken,
|
||||||
|
monitorId: monitorId,
|
||||||
|
});
|
||||||
|
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 deleteInfrastructureMonitorChecksByTeamId = createAsyncThunk(
|
||||||
|
"infrastructureMonitors/deleteChecksByTeamId",
|
||||||
|
async (data, thunkApi) => {
|
||||||
|
try {
|
||||||
|
const { authToken, teamId } = data;
|
||||||
|
const res = await networkService.deleteChecksByTeamId({
|
||||||
|
authToken: authToken,
|
||||||
|
teamId: teamId,
|
||||||
|
});
|
||||||
|
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 deleteAllInfrastructureMonitors = createAsyncThunk(
|
||||||
|
"infrastructureMonitors/deleteAllMonitors",
|
||||||
|
async (data, thunkApi) => {
|
||||||
|
try {
|
||||||
|
const { authToken } = data;
|
||||||
|
const res = await networkService.deleteAllMonitors({
|
||||||
|
authToken: authToken,
|
||||||
|
});
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
const infrastructureMonitorsSlice = createSlice({
|
||||||
|
name: "infrastructureMonitors",
|
||||||
|
initialState,
|
||||||
|
reducers: {
|
||||||
|
clearInfrastructureMonitorState: (state) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.monitorsSummary = [];
|
||||||
|
state.success = null;
|
||||||
|
state.msg = null;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
extraReducers: (builder) => {
|
||||||
|
builder
|
||||||
|
// *****************************************************
|
||||||
|
// Monitors by teamId
|
||||||
|
// *****************************************************
|
||||||
|
|
||||||
|
.addCase(getInfrastructureMonitorsByTeamId.pending, (state) => {
|
||||||
|
state.isLoading = true;
|
||||||
|
})
|
||||||
|
.addCase(getInfrastructureMonitorsByTeamId.fulfilled, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.success = action.payload.msg;
|
||||||
|
state.monitorsSummary = action.payload.data;
|
||||||
|
})
|
||||||
|
.addCase(getInfrastructureMonitorsByTeamId.rejected, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.success = false;
|
||||||
|
state.msg = action.payload
|
||||||
|
? action.payload.msg
|
||||||
|
: "Getting infrastructure monitors failed";
|
||||||
|
})
|
||||||
|
|
||||||
|
// *****************************************************
|
||||||
|
// Create Monitor
|
||||||
|
// *****************************************************
|
||||||
|
.addCase(createInfrastructureMonitor.pending, (state) => {
|
||||||
|
state.isLoading = true;
|
||||||
|
})
|
||||||
|
.addCase(createInfrastructureMonitor.fulfilled, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.success = action.payload.success;
|
||||||
|
state.msg = action.payload.msg;
|
||||||
|
})
|
||||||
|
.addCase(createInfrastructureMonitor.rejected, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.success = false;
|
||||||
|
state.msg = action.payload
|
||||||
|
? action.payload.msg
|
||||||
|
: "Failed to create infrastructure monitor";
|
||||||
|
})
|
||||||
|
// *****************************************************
|
||||||
|
// Resolve Endpoint
|
||||||
|
// *****************************************************
|
||||||
|
.addCase(checkInfrastructureEndpointResolution.pending, (state) => {
|
||||||
|
state.isLoading = true;
|
||||||
|
})
|
||||||
|
.addCase(checkInfrastructureEndpointResolution.fulfilled, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.success = action.payload.success;
|
||||||
|
state.msg = action.payload.msg;
|
||||||
|
})
|
||||||
|
.addCase(checkInfrastructureEndpointResolution.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
|
||||||
|
// *****************************************************
|
||||||
|
.addCase(getInfrastructureMonitorById.pending, (state) => {
|
||||||
|
state.isLoading = true;
|
||||||
|
})
|
||||||
|
.addCase(getInfrastructureMonitorById.fulfilled, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.success = action.payload.success;
|
||||||
|
state.msg = action.payload.msg;
|
||||||
|
})
|
||||||
|
.addCase(getInfrastructureMonitorById.rejected, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.success = false;
|
||||||
|
state.msg = action.payload ? action.payload.msg : "Failed to get infrastructure monitor";
|
||||||
|
})
|
||||||
|
// *****************************************************
|
||||||
|
// update Monitor
|
||||||
|
// *****************************************************
|
||||||
|
.addCase(updateInfrastructureMonitor.pending, (state) => {
|
||||||
|
state.isLoading = true;
|
||||||
|
})
|
||||||
|
.addCase(updateInfrastructureMonitor.fulfilled, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.success = action.payload.success;
|
||||||
|
state.msg = action.payload.msg;
|
||||||
|
})
|
||||||
|
.addCase(updateInfrastructureMonitor.rejected, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.success = false;
|
||||||
|
state.msg = action.payload
|
||||||
|
? action.payload.msg
|
||||||
|
: "Failed to update infrastructure monitor";
|
||||||
|
})
|
||||||
|
|
||||||
|
// *****************************************************
|
||||||
|
// Delete Monitor
|
||||||
|
// *****************************************************
|
||||||
|
.addCase(deleteInfrastructureMonitor.pending, (state) => {
|
||||||
|
state.isLoading = true;
|
||||||
|
})
|
||||||
|
.addCase(deleteInfrastructureMonitor.fulfilled, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.success = action.payload.success;
|
||||||
|
state.msg = action.payload.msg;
|
||||||
|
})
|
||||||
|
.addCase(deleteInfrastructureMonitor.rejected, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.success = false;
|
||||||
|
state.msg = action.payload
|
||||||
|
? action.payload.msg
|
||||||
|
: "Failed to delete infrastructure monitor";
|
||||||
|
})
|
||||||
|
// *****************************************************
|
||||||
|
// Delete Monitor checks by Team ID
|
||||||
|
// *****************************************************
|
||||||
|
.addCase(deleteInfrastructureMonitorChecksByTeamId.pending, (state) => {
|
||||||
|
state.isLoading = true;
|
||||||
|
})
|
||||||
|
.addCase(deleteInfrastructureMonitorChecksByTeamId.fulfilled, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.success = action.payload.success;
|
||||||
|
state.msg = action.payload.msg;
|
||||||
|
})
|
||||||
|
.addCase(deleteInfrastructureMonitorChecksByTeamId.rejected, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.success = false;
|
||||||
|
state.msg = action.payload
|
||||||
|
? action.payload.msg
|
||||||
|
: "Failed to delete monitor checks";
|
||||||
|
})
|
||||||
|
// *****************************************************
|
||||||
|
// Pause Monitor
|
||||||
|
// *****************************************************
|
||||||
|
.addCase(pauseInfrastructureMonitor.pending, (state) => {
|
||||||
|
state.isLoading = true;
|
||||||
|
})
|
||||||
|
.addCase(pauseInfrastructureMonitor.fulfilled, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.success = action.payload.success;
|
||||||
|
state.msg = action.payload.msg;
|
||||||
|
})
|
||||||
|
.addCase(pauseInfrastructureMonitor.rejected, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.success = false;
|
||||||
|
state.msg = action.payload
|
||||||
|
? action.payload.msg
|
||||||
|
: "Failed to pause infrastructure monitor";
|
||||||
|
})
|
||||||
|
// *****************************************************
|
||||||
|
// Delete all Monitors
|
||||||
|
// *****************************************************
|
||||||
|
.addCase(deleteAllInfrastructureMonitors.pending, (state) => {
|
||||||
|
state.isLoading = true;
|
||||||
|
})
|
||||||
|
.addCase(deleteAllInfrastructureMonitors.fulfilled, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.success = action.payload.success;
|
||||||
|
state.msg = action.payload.msg;
|
||||||
|
})
|
||||||
|
.addCase(deleteAllInfrastructureMonitors.rejected, (state, action) => {
|
||||||
|
state.isLoading = false;
|
||||||
|
state.success = false;
|
||||||
|
state.msg = action.payload ? action.payload.msg : "Failed to delete all monitors";
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
export const { setInfrastructureMonitors, clearInfrastructureMonitorState } = infrastructureMonitorsSlice.actions;
|
||||||
|
|
||||||
|
export default infrastructureMonitorsSlice.reducer;
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
import { Box, Stack, Typography } from "@mui/material";
|
||||||
|
import Field from "../../../../Components/Inputs/Field";
|
||||||
|
import Checkbox from "../../../../Components/Inputs/Checkbox";
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import PropTypes from "prop-types";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* `CustomThreshold` is a functional React component that displays a
|
||||||
|
* group of CheckBox with a label and its correspondant threshold input field.
|
||||||
|
*
|
||||||
|
* @param {{ checkboxId: any; checkboxLabel: any; onCheckboxChange: any; fieldId: any; onFieldChange: any; onFieldBlur: any; alertUnit: any; infrastructureMonitor: any; errors: any; }} param0
|
||||||
|
* @param {string} param0.checkboxId - The text is the id of the checkbox.
|
||||||
|
* @param {string} param0.checkboxLabel - The text to be displayed as the label next to the check icon.
|
||||||
|
* @param {func} param0.onCheckboxChange - The function to invoke when checkbox is checked or unchecked.
|
||||||
|
* @param {string} param0.fieldId - The text is the id of the input field.
|
||||||
|
* @param {func} param0.onFieldChange - The function to invoke when input field is changed.
|
||||||
|
* @param {func} param0.onFieldBlur - The function to invoke when input field is losing focus.
|
||||||
|
* @param {string} param0.alertUnit the threshold unit such as usage percentage '%' etc
|
||||||
|
* @param {object} param0.infrastructureMonitor the form object of the create infrastrcuture monitor page
|
||||||
|
* @param {object} param0.errors the object that holds all the errors of the form page
|
||||||
|
* @returns A compound React component that renders the custom threshold alert section
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
export const CustomThreshold = ({
|
||||||
|
checkboxId,
|
||||||
|
checkboxLabel,
|
||||||
|
onCheckboxChange,
|
||||||
|
fieldId,
|
||||||
|
onFieldChange,
|
||||||
|
onFieldBlur,
|
||||||
|
alertUnit,
|
||||||
|
infrastructureMonitor,
|
||||||
|
errors
|
||||||
|
}) =>
|
||||||
|
{
|
||||||
|
const theme = useTheme();
|
||||||
|
return (
|
||||||
|
<Stack
|
||||||
|
direction={"row"}
|
||||||
|
sx={{
|
||||||
|
width: "50%",
|
||||||
|
justifyContent: "space-between",
|
||||||
|
flexWrap: "wrap"
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Box>
|
||||||
|
<Checkbox
|
||||||
|
id={checkboxId}
|
||||||
|
label={checkboxLabel}
|
||||||
|
isChecked={infrastructureMonitor[checkboxId]}
|
||||||
|
onChange={onCheckboxChange}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
<Stack
|
||||||
|
direction={"row"}
|
||||||
|
sx={{
|
||||||
|
justifyContent: "flex-end",
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Field
|
||||||
|
type="number"
|
||||||
|
className="field-infrastructure-alert"
|
||||||
|
id={fieldId}
|
||||||
|
value={infrastructureMonitor[fieldId]}
|
||||||
|
onBlur={onFieldBlur}
|
||||||
|
onChange={onFieldChange}
|
||||||
|
error={errors[fieldId]}
|
||||||
|
disabled={!infrastructureMonitor[checkboxId]}
|
||||||
|
></Field>
|
||||||
|
<Typography
|
||||||
|
component="p"
|
||||||
|
m={theme.spacing(3)}
|
||||||
|
>
|
||||||
|
{alertUnit}
|
||||||
|
</Typography>
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
)}
|
||||||
|
|
||||||
|
CustomThreshold.propTypes = {
|
||||||
|
checkboxId: PropTypes.string.isRequired,
|
||||||
|
checkboxLabel: PropTypes.string.isRequired,
|
||||||
|
onCheckboxChange: PropTypes.func.isRequired,
|
||||||
|
fieldId: PropTypes.string.isRequired,
|
||||||
|
onFieldChange: PropTypes.func.isRequired,
|
||||||
|
onFieldBlur: PropTypes.func.isRequired,
|
||||||
|
alertUnit: PropTypes.string.isRequired,
|
||||||
|
infrastructureMonitor: PropTypes.object.isRequired,
|
||||||
|
errors: PropTypes.object.isRequired,
|
||||||
|
};
|
||||||
@@ -0,0 +1,413 @@
|
|||||||
|
import { useState } from "react";
|
||||||
|
import { Box, Stack, Typography } from "@mui/material";
|
||||||
|
import LoadingButton from "@mui/lab/LoadingButton";
|
||||||
|
import { useSelector, useDispatch } from "react-redux";
|
||||||
|
import { infrastructureMonitorValidation } from "../../../Validation/validation";
|
||||||
|
import {
|
||||||
|
createInfrastructureMonitor,
|
||||||
|
checkInfrastructureEndpointResolution,
|
||||||
|
} from "../../../Features/InfrastructureMonitors/infrastructureMonitorsSlice";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
import { useTheme } from "@emotion/react";
|
||||||
|
import { createToast } from "../../../Utils/toastUtils";
|
||||||
|
import { logger } from "../../../Utils/Logger";
|
||||||
|
import { ConfigBox } from "../../Monitors/styled";
|
||||||
|
import Field from "../../../Components/Inputs/Field";
|
||||||
|
import Select from "../../../Components/Inputs/Select";
|
||||||
|
import Checkbox from "../../../Components/Inputs/Checkbox";
|
||||||
|
import Breadcrumbs from "../../../Components/Breadcrumbs";
|
||||||
|
import { buildErrors, hasValidationErrors } from "../../../Validation/error";
|
||||||
|
import { capitalizeFirstLetter } from "../../../Utils/stringUtils";
|
||||||
|
import { CustomThreshold } from "../CreateMonitor/CustomThreshold";
|
||||||
|
|
||||||
|
const CreateInfrastructureMonitor = () => {
|
||||||
|
const [infrastructureMonitor, setInfrastructureMonitor] = useState({
|
||||||
|
url: "",
|
||||||
|
name: "",
|
||||||
|
notifications: [],
|
||||||
|
interval: 0.25,
|
||||||
|
cpu: false,
|
||||||
|
usage_cpu: "",
|
||||||
|
memory: false,
|
||||||
|
usage_memory: "",
|
||||||
|
disk: false,
|
||||||
|
usage_disk: "",
|
||||||
|
secret: "",
|
||||||
|
});
|
||||||
|
|
||||||
|
const MS_PER_MINUTE = 60000;
|
||||||
|
const THRESHOLD_FIELD_PREFIX = "usage_";
|
||||||
|
const HARDWARE_MONITOR_TYPES = ["cpu", "memory", "disk"];
|
||||||
|
const { user, authToken } = useSelector((state) => state.auth);
|
||||||
|
const monitorState = useSelector((state) => state.infrastructureMonitor);
|
||||||
|
const dispatch = useDispatch();
|
||||||
|
const navigate = useNavigate();
|
||||||
|
const theme = useTheme();
|
||||||
|
|
||||||
|
const idMap = {
|
||||||
|
"notify-email-default": "notification-email",
|
||||||
|
};
|
||||||
|
|
||||||
|
const [errors, setErrors] = useState({});
|
||||||
|
|
||||||
|
const alertErrKeyLen = Object.keys(errors).filter((k) =>
|
||||||
|
k.startsWith(THRESHOLD_FIELD_PREFIX)
|
||||||
|
).length;
|
||||||
|
|
||||||
|
const handleCustomAlertCheckChange = (event) => {
|
||||||
|
const { value, id } = event.target;
|
||||||
|
setInfrastructureMonitor((prev) => {
|
||||||
|
const newState = {
|
||||||
|
[id]: prev[id] == undefined && value == "on" ? true : !prev[id],
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
...prev,
|
||||||
|
...newState,
|
||||||
|
[THRESHOLD_FIELD_PREFIX + id]: newState[id]
|
||||||
|
? prev[THRESHOLD_FIELD_PREFIX + id]
|
||||||
|
: "",
|
||||||
|
};
|
||||||
|
});
|
||||||
|
// Remove the error if unchecked
|
||||||
|
setErrors((prev) => {
|
||||||
|
return buildErrors(prev, [THRESHOLD_FIELD_PREFIX + id]);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleBlur = (event, appenedID) => {
|
||||||
|
event.preventDefault();
|
||||||
|
const { value, id } = event.target;
|
||||||
|
if (id?.startsWith("notify-email-")) return;
|
||||||
|
const { error } = infrastructureMonitorValidation.validate(
|
||||||
|
{ [id ?? appenedID]: value },
|
||||||
|
{
|
||||||
|
abortEarly: false,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
setErrors((prev) => {
|
||||||
|
return buildErrors(prev, id ?? appenedID, error);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleChange = (event, appendedId) => {
|
||||||
|
event.preventDefault();
|
||||||
|
const { value, id } = event.target;
|
||||||
|
let name = appendedId ?? idMap[id] ?? id;
|
||||||
|
|
||||||
|
if (name.includes("notification-")) {
|
||||||
|
name = name.replace("notification-", "");
|
||||||
|
let hasNotif = infrastructureMonitor.notifications.some(
|
||||||
|
(notification) => notification.type === name
|
||||||
|
);
|
||||||
|
setInfrastructureMonitor((prev) => {
|
||||||
|
const notifs = [...prev.notifications];
|
||||||
|
if (hasNotif) {
|
||||||
|
return {
|
||||||
|
...prev,
|
||||||
|
notifications: notifs.filter((notif) => notif.type !== name),
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
...prev,
|
||||||
|
notifications: [
|
||||||
|
...notifs,
|
||||||
|
name === "email"
|
||||||
|
? { type: name, address: value }
|
||||||
|
: // TODO - phone number
|
||||||
|
{ type: name, phone: value },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
setInfrastructureMonitor((prev) => ({
|
||||||
|
...prev,
|
||||||
|
[name]: value,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const generatePayload = (form) => {
|
||||||
|
let thresholds = {};
|
||||||
|
Object.keys(form)
|
||||||
|
.filter((k) => k.startsWith(THRESHOLD_FIELD_PREFIX))
|
||||||
|
.map((k) => {
|
||||||
|
if (form[k]) thresholds[k] = form[k];
|
||||||
|
delete form[k];
|
||||||
|
delete form[k.substring(THRESHOLD_FIELD_PREFIX.length)];
|
||||||
|
});
|
||||||
|
|
||||||
|
form = {
|
||||||
|
...form,
|
||||||
|
description: form.name,
|
||||||
|
teamId: user.teamId,
|
||||||
|
userId: user._id,
|
||||||
|
type: "hardware",
|
||||||
|
notifications: infrastructureMonitor.notifications,
|
||||||
|
thresholds,
|
||||||
|
};
|
||||||
|
return form;
|
||||||
|
};
|
||||||
|
const handleCreateInfrastructureMonitor = async (event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
let form = {
|
||||||
|
...infrastructureMonitor,
|
||||||
|
name:
|
||||||
|
infrastructureMonitor.name === ""
|
||||||
|
? infrastructureMonitor.url
|
||||||
|
: infrastructureMonitor.name,
|
||||||
|
interval: infrastructureMonitor.interval * MS_PER_MINUTE,
|
||||||
|
};
|
||||||
|
delete form.notifications;
|
||||||
|
if (hasValidationErrors(form, infrastructureMonitorValidation, setErrors)) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
const checkEndpointAction = await dispatch(
|
||||||
|
checkInfrastructureEndpointResolution({ 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;
|
||||||
|
}
|
||||||
|
const action = await dispatch(
|
||||||
|
createInfrastructureMonitor({ authToken, monitor: generatePayload(form) })
|
||||||
|
);
|
||||||
|
if (action.meta.requestStatus === "fulfilled") {
|
||||||
|
createToast({ body: "Infrastructure monitor created successfully!" });
|
||||||
|
navigate("/infrastructure");
|
||||||
|
} else {
|
||||||
|
createToast({ body: "Failed to create monitor." });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
//select values
|
||||||
|
const frequencies = [
|
||||||
|
{ _id: 0.25, name: "15 seconds" },
|
||||||
|
{ _id: 0.5, name: "30 seconds" },
|
||||||
|
{ _id: 1, name: "1 minute" },
|
||||||
|
{ _id: 2, name: "2 minutes" },
|
||||||
|
{ _id: 5, name: "5 minutes" },
|
||||||
|
{ _id: 10, name: "10 minutes" },
|
||||||
|
];
|
||||||
|
|
||||||
|
const NOTIFY_MULTIPLE_EMAIL_LABEL = (
|
||||||
|
<Box>
|
||||||
|
<Typography mb={theme.spacing(4)}>
|
||||||
|
Also notify via email to multiple addresses (coming soon)
|
||||||
|
</Typography>
|
||||||
|
<Field
|
||||||
|
id="notify-email-list"
|
||||||
|
type="text"
|
||||||
|
placeholder="name@gmail.com"
|
||||||
|
value=""
|
||||||
|
onChange={() => logger.warn("disabled")}
|
||||||
|
onBlur={handleBlur}
|
||||||
|
/>
|
||||||
|
<Typography mt={theme.spacing(4)}>
|
||||||
|
You can separate multiple emails with a comma
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Box className="create-infrastructure-monitor">
|
||||||
|
<Breadcrumbs
|
||||||
|
list={[
|
||||||
|
{ name: "Infrastructure monitors", path: "infrastructure" },
|
||||||
|
{ name: "create", path: `infrastructure/create` },
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
<Stack
|
||||||
|
component="form"
|
||||||
|
className="create-infrastructure-monitor-form"
|
||||||
|
onSubmit={handleCreateInfrastructureMonitor}
|
||||||
|
noValidate
|
||||||
|
spellCheck="false"
|
||||||
|
gap={theme.spacing(12)}
|
||||||
|
mt={theme.spacing(6)}
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
component="h1"
|
||||||
|
variant="h1"
|
||||||
|
>
|
||||||
|
<Typography
|
||||||
|
component="span"
|
||||||
|
fontSize="inherit"
|
||||||
|
>
|
||||||
|
Create your{" "}
|
||||||
|
</Typography>
|
||||||
|
<Typography
|
||||||
|
component="span"
|
||||||
|
variant="h2"
|
||||||
|
fontSize="inherit"
|
||||||
|
fontWeight="inherit"
|
||||||
|
>
|
||||||
|
infrastructure monitor
|
||||||
|
</Typography>
|
||||||
|
</Typography>
|
||||||
|
<ConfigBox>
|
||||||
|
<Box>
|
||||||
|
<Typography component="h2">General settings</Typography>
|
||||||
|
<Typography component="p">
|
||||||
|
Here you can select the URL of the host, together with the type of monitor.
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
<Stack gap={theme.spacing(15)}>
|
||||||
|
<Field
|
||||||
|
type="text"
|
||||||
|
id="url"
|
||||||
|
label="Server URL"
|
||||||
|
placeholder="https://"
|
||||||
|
value={infrastructureMonitor.url}
|
||||||
|
onBlur={handleBlur}
|
||||||
|
onChange={handleChange}
|
||||||
|
error={errors["url"]}
|
||||||
|
/>
|
||||||
|
<Field
|
||||||
|
type="text"
|
||||||
|
id="name"
|
||||||
|
label="Friendly name"
|
||||||
|
isOptional={true}
|
||||||
|
value={infrastructureMonitor.name}
|
||||||
|
onBlur={handleBlur}
|
||||||
|
onChange={handleChange}
|
||||||
|
error={errors["name"]}
|
||||||
|
/>
|
||||||
|
<Field
|
||||||
|
type="text"
|
||||||
|
id="secret"
|
||||||
|
label="Authorization secret"
|
||||||
|
value={infrastructureMonitor.secret}
|
||||||
|
onBlur={handleBlur}
|
||||||
|
onChange={handleChange}
|
||||||
|
error={errors["secret"]}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
</ConfigBox>
|
||||||
|
<ConfigBox>
|
||||||
|
<Box>
|
||||||
|
<Typography component="h2">Incident notifications</Typography>
|
||||||
|
<Typography component="p">
|
||||||
|
When there is an incident, notify users.
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
<Stack gap={theme.spacing(6)}>
|
||||||
|
<Typography component="p">When there is a new incident,</Typography>
|
||||||
|
<Checkbox
|
||||||
|
id="notify-email-default"
|
||||||
|
label={`Notify via email (to ${user.email})`}
|
||||||
|
isChecked={infrastructureMonitor.notifications.some(
|
||||||
|
(notification) => notification.type === "email"
|
||||||
|
)}
|
||||||
|
value={user?.email}
|
||||||
|
onChange={(e) => handleChange(e)}
|
||||||
|
onBlur={handleBlur}
|
||||||
|
/>
|
||||||
|
<Checkbox
|
||||||
|
id="notify-email"
|
||||||
|
label={NOTIFY_MULTIPLE_EMAIL_LABEL}
|
||||||
|
isChecked={false}
|
||||||
|
value=""
|
||||||
|
onChange={() => logger.warn("disabled")}
|
||||||
|
onBlur={handleBlur}
|
||||||
|
isDisabled={true}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
</ConfigBox>
|
||||||
|
|
||||||
|
<ConfigBox>
|
||||||
|
<Box>
|
||||||
|
<Typography component="h2">Customize alerts</Typography>
|
||||||
|
<Typography component="p">
|
||||||
|
Send a notification to user(s) When the thresholds exceed a certain number
|
||||||
|
or percentage.
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
<Stack gap={theme.spacing(6)}>
|
||||||
|
{HARDWARE_MONITOR_TYPES.map((type, idx) => (
|
||||||
|
<CustomThreshold
|
||||||
|
key={idx}
|
||||||
|
checkboxId={type}
|
||||||
|
checkboxLabel={
|
||||||
|
type !== "cpu" ? capitalizeFirstLetter(type) : type.toUpperCase()
|
||||||
|
}
|
||||||
|
onCheckboxChange={handleCustomAlertCheckChange}
|
||||||
|
fieldId={THRESHOLD_FIELD_PREFIX + type}
|
||||||
|
fieldValue={infrastructureMonitor[THRESHOLD_FIELD_PREFIX + type] ?? ""}
|
||||||
|
onFieldChange={handleChange}
|
||||||
|
onFieldBlur={handleBlur}
|
||||||
|
// TODO: need BE, maybe in another PR
|
||||||
|
alertUnit={type == "temperature" ? "°C" : "%"}
|
||||||
|
infrastructureMonitor={infrastructureMonitor}
|
||||||
|
errors={errors}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
{alertErrKeyLen > 0 && (
|
||||||
|
<Typography
|
||||||
|
component="span"
|
||||||
|
className="input-error"
|
||||||
|
color={theme.palette.error.main}
|
||||||
|
mt={theme.spacing(2)}
|
||||||
|
sx={{
|
||||||
|
opacity: 0.8,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{
|
||||||
|
errors[
|
||||||
|
THRESHOLD_FIELD_PREFIX +
|
||||||
|
HARDWARE_MONITOR_TYPES.filter(
|
||||||
|
(type) => errors[THRESHOLD_FIELD_PREFIX + type]
|
||||||
|
)[0]
|
||||||
|
]
|
||||||
|
}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
</Stack>
|
||||||
|
</ConfigBox>
|
||||||
|
<ConfigBox>
|
||||||
|
<Box>
|
||||||
|
<Typography component="h2">Advanced settings</Typography>
|
||||||
|
</Box>
|
||||||
|
<Stack gap={theme.spacing(12)}>
|
||||||
|
<Select
|
||||||
|
id="interval"
|
||||||
|
label="Check frequency"
|
||||||
|
value={infrastructureMonitor.interval || 15}
|
||||||
|
onChange={(e) => handleChange(e, "interval")}
|
||||||
|
onBlur={(e) => handleBlur(e, "interval")}
|
||||||
|
items={frequencies}
|
||||||
|
/>
|
||||||
|
{/* <Field
|
||||||
|
type={"number"}
|
||||||
|
id="monitor-retries"
|
||||||
|
label="Maximum retries before the service is marked as down"
|
||||||
|
value={infrastructureMonitor.url}
|
||||||
|
onChange={handleChange}
|
||||||
|
onBlur={handleBlur}
|
||||||
|
error={errors["url"]}
|
||||||
|
/> */}
|
||||||
|
</Stack>
|
||||||
|
</ConfigBox>
|
||||||
|
<Stack
|
||||||
|
direction="row"
|
||||||
|
justifyContent="flex-end"
|
||||||
|
>
|
||||||
|
<LoadingButton
|
||||||
|
variant="contained"
|
||||||
|
color="primary"
|
||||||
|
onClick={handleCreateInfrastructureMonitor}
|
||||||
|
loading={monitorState?.isLoading}
|
||||||
|
>
|
||||||
|
Create infrastructure monitor
|
||||||
|
</LoadingButton>
|
||||||
|
</Stack>
|
||||||
|
</Stack>
|
||||||
|
</Box>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default CreateInfrastructureMonitor;
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { Box, Button } from "@mui/material";
|
import { Box, Button } from "@mui/material";
|
||||||
import { Heading } from "../../Components/Heading";
|
import { Heading } from "../../Components/Heading";
|
||||||
|
import { useNavigate } from "react-router-dom";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the Infrastructure monitoring page. This is a work in progress
|
* This is the Infrastructure monitoring page. This is a work in progress
|
||||||
@@ -9,13 +10,14 @@ import { Heading } from "../../Components/Heading";
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function Infrastructure() {
|
function Infrastructure() {
|
||||||
|
const navigate = useNavigate();
|
||||||
return (
|
return (
|
||||||
<Box component="main">
|
<Box component="main">
|
||||||
<Button
|
<Button
|
||||||
variant="contained"
|
variant="contained"
|
||||||
color="primary"
|
color="primary"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
// navigate("/monitors/create");
|
navigate("/infrastructure/create");
|
||||||
}}
|
}}
|
||||||
sx={{ fontWeight: 500 }}
|
sx={{ fontWeight: 500 }}
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
/**
|
||||||
|
* Helper function to get first letter capitalized string
|
||||||
|
* @param {string} str String whose first letter is to be capitalized
|
||||||
|
* @returns A string with first letter capitalized
|
||||||
|
*/
|
||||||
|
export const capitalizeFirstLetter = (str) => {
|
||||||
|
if (str === null || str === undefined) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
if (typeof str !== "string") {
|
||||||
|
throw new TypeError("Input must be a string");
|
||||||
|
}
|
||||||
|
if (str.length === 0) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
return str.charAt(0).toUpperCase() + str.slice(1);
|
||||||
|
};
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
const buildErrors = (prev, id, error) => {
|
const buildErrors = (prev, id, error) => {
|
||||||
const updatedErrors = { ...prev };
|
const updatedErrors = { ...prev };
|
||||||
if (error) {
|
if (error) {
|
||||||
updatedErrors[id] = error.details[0].message?? "Validation error";
|
updatedErrors[id] = error.details[0].message ?? "Validation error";
|
||||||
} else {
|
} else {
|
||||||
delete updatedErrors[id];
|
delete updatedErrors[id];
|
||||||
}
|
}
|
||||||
@@ -22,15 +22,29 @@ const hasValidationErrors = (form, validation, setErrors) => {
|
|||||||
"dbConnectionString",
|
"dbConnectionString",
|
||||||
"refreshTokenTTL",
|
"refreshTokenTTL",
|
||||||
"jwtTTL",
|
"jwtTTL",
|
||||||
|
"notify-email-list",
|
||||||
].includes(err.path[0])
|
].includes(err.path[0])
|
||||||
) {
|
) {
|
||||||
newErrors[err.path[0]] = err.message ?? "Validation error";
|
newErrors[err.path[0]] = err.message ?? "Validation error";
|
||||||
}
|
}
|
||||||
|
// Handle conditionally usage number required cases
|
||||||
|
if (!form.cpu || form.usage_cpu) {
|
||||||
|
newErrors["usage_cpu"] = null;
|
||||||
|
}
|
||||||
|
if (!form.memory || form.usage_memory) {
|
||||||
|
newErrors["usage_memory"] = null;
|
||||||
|
}
|
||||||
|
if (!form.disk || form.usage_disk) {
|
||||||
|
newErrors["usage_disk"] = null;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
if (Object.keys(newErrors).length > 0) {
|
if (Object.values(newErrors).some(v=> v)) {
|
||||||
setErrors(newErrors);
|
setErrors(newErrors);
|
||||||
return true;
|
return true;
|
||||||
} else return false;
|
} else {
|
||||||
|
setErrors({});
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import joi from "joi";
|
import joi from "joi";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
|
const THRESHOLD_COMMON_BASE_MSG = "Threshold must be a number.";
|
||||||
|
|
||||||
const nameSchema = joi
|
const nameSchema = joi
|
||||||
.string()
|
.string()
|
||||||
.max(50)
|
.max(50)
|
||||||
@@ -173,6 +175,42 @@ const advancedSettingsValidation = joi.object({
|
|||||||
pagespeedApiKey: joi.string().allow(""),
|
pagespeedApiKey: joi.string().allow(""),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const infrastructureMonitorValidation = joi.object({
|
||||||
|
url: joi.string().uri({ allowRelative: true }).trim().messages({
|
||||||
|
"string.empty": "This field is required.",
|
||||||
|
"string.uri": "The URL you provided is not valid.",
|
||||||
|
}),
|
||||||
|
name: joi.string().trim().max(50).allow("").messages({
|
||||||
|
"string.max": "This field should not exceed the 50 characters limit.",
|
||||||
|
}),
|
||||||
|
secret: joi.string().trim().messages({ "string.empty": "This field is required." }),
|
||||||
|
usage_cpu: joi.number().messages({
|
||||||
|
"number.base": THRESHOLD_COMMON_BASE_MSG,
|
||||||
|
}),
|
||||||
|
cpu: joi.boolean(),
|
||||||
|
memory: joi.boolean(),
|
||||||
|
disk: joi.boolean(),
|
||||||
|
usage_memory: joi.number().messages({
|
||||||
|
"number.base": THRESHOLD_COMMON_BASE_MSG,
|
||||||
|
}),
|
||||||
|
usage_disk: joi.number().messages({
|
||||||
|
"number.base": THRESHOLD_COMMON_BASE_MSG,
|
||||||
|
}),
|
||||||
|
// usage_temperature: joi.number().messages({
|
||||||
|
// "number.base": "Temperature must be a number.",
|
||||||
|
// }),
|
||||||
|
// usage_system: joi.number().messages({
|
||||||
|
// "number.base": "System load must be a number.",
|
||||||
|
// }),
|
||||||
|
// usage_swap: joi.number().messages({
|
||||||
|
// "number.base": "Swap used must be a number.",
|
||||||
|
// }),
|
||||||
|
interval: joi.number().messages({
|
||||||
|
"number.base": "Frequency must be a number.",
|
||||||
|
"any.required": "Frequency is required.",
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
export {
|
export {
|
||||||
credentials,
|
credentials,
|
||||||
imageValidation,
|
imageValidation,
|
||||||
@@ -180,4 +218,5 @@ export {
|
|||||||
settingsValidation,
|
settingsValidation,
|
||||||
maintenanceWindowValidation,
|
maintenanceWindowValidation,
|
||||||
advancedSettingsValidation,
|
advancedSettingsValidation,
|
||||||
|
infrastructureMonitorValidation,
|
||||||
};
|
};
|
||||||
@@ -20,6 +20,8 @@ html {
|
|||||||
|
|
||||||
--env-var-width-1: 100vw;
|
--env-var-width-1: 100vw;
|
||||||
--env-var-width-2: 360px;
|
--env-var-width-2: 360px;
|
||||||
|
--env-var-width-3: 250px;
|
||||||
|
--env-var-width-4: 100px;
|
||||||
|
|
||||||
--env-var-height-1: 100vh;
|
--env-var-height-1: 100vh;
|
||||||
--env-var-height-2: 34px;
|
--env-var-height-2: 34px;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { configureStore, combineReducers } from "@reduxjs/toolkit";
|
import { configureStore, combineReducers } from "@reduxjs/toolkit";
|
||||||
|
|
||||||
import uptimeMonitorsReducer from "./Features/UptimeMonitors/uptimeMonitorsSlice";
|
import uptimeMonitorsReducer from "./Features/UptimeMonitors/uptimeMonitorsSlice";
|
||||||
|
import infrastructureMonitorsReducer from "./Features/InfrastructureMonitors/infrastructureMonitorsSlice";
|
||||||
import pageSpeedMonitorReducer from "./Features/PageSpeedMonitor/pageSpeedMonitorSlice";
|
import pageSpeedMonitorReducer from "./Features/PageSpeedMonitor/pageSpeedMonitorSlice";
|
||||||
import authReducer from "./Features/Auth/authSlice";
|
import authReducer from "./Features/Auth/authSlice";
|
||||||
import uiReducer from "./Features/UI/uiSlice";
|
import uiReducer from "./Features/UI/uiSlice";
|
||||||
@@ -28,6 +29,7 @@ const persistConfig = {
|
|||||||
|
|
||||||
const rootReducer = combineReducers({
|
const rootReducer = combineReducers({
|
||||||
uptimeMonitors: uptimeMonitorsReducer,
|
uptimeMonitors: uptimeMonitorsReducer,
|
||||||
|
infrastructureMonitors: infrastructureMonitorsReducer,
|
||||||
auth: authReducer,
|
auth: authReducer,
|
||||||
pageSpeedMonitors: pageSpeedMonitorReducer,
|
pageSpeedMonitors: pageSpeedMonitorReducer,
|
||||||
ui: uiReducer,
|
ui: uiReducer,
|
||||||
|
|||||||
Reference in new issue
Block a user