Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions client/src/Hooks/monitorHooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ const useDeleteMonitor = () => {

const useUpdateMonitor = () => {
const [isLoading, setIsLoading] = useState(false);

const navigate = useNavigate();
const updateMonitor = async ({ monitor, redirect }) => {
try {
Expand All @@ -357,6 +358,7 @@ const useUpdateMonitor = () => {
expectedValue: monitor.expectedValue,
ignoreTlsErrors: monitor.ignoreTlsErrors,
jsonPath: monitor.jsonPath,
url: monitor.url,
...(monitor.type === "port" && { port: monitor.port }),
...(monitor.type === "hardware" && {
thresholds: monitor.thresholds,
Expand Down
49 changes: 25 additions & 24 deletions client/src/Pages/Infrastructure/Create/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { useSelector } from "react-redux";
import { useState, useEffect } from "react";
import { useTheme } from "@emotion/react";
import { useTranslation } from "react-i18next";
import { normalizeUrl } from "../../../Utils/url";
import {
useCreateMonitor,
useDeleteMonitor,
Expand Down Expand Up @@ -234,6 +235,7 @@ const CreateInfrastructureMonitor = () => {
form = {
...(isCreate ? {} : { _id: monitorId }),
...rest,
url: normalizeUrl(infrastructureMonitor.url, https),
description: form.name,
type: "hardware",
notifications: infrastructureMonitor.notifications,
Expand Down Expand Up @@ -470,31 +472,30 @@ const CreateInfrastructureMonitor = () => {
onChange={onChange}
error={errors["url"] ? true : false}
helperText={errors["url"]}
disabled={!isCreate}
/>
{isCreate && (
<FieldWrapper
label={t("infrastructureProtocol")}
labelVariant="p"
>
<ButtonGroup>
<Button
variant="group"
filled={https.toString()}
onClick={() => setHttps(true)}
>
{t("https")}
</Button>
<Button
variant="group"
filled={(!https).toString()}
onClick={() => setHttps(false)}
>
{t("http")}
</Button>
</ButtonGroup>
</FieldWrapper>
)}

<FieldWrapper
label={t("infrastructureProtocol")}
labelVariant="p"
>
<ButtonGroup>
<Button
variant="group"
filled={https.toString()}
onClick={() => setHttps(true)}
>
{t("https")}
</Button>
<Button
variant="group"
filled={(!https).toString()}
onClick={() => setHttps(false)}
>
{t("http")}
</Button>
</ButtonGroup>
</FieldWrapper>

<TextInput
type="text"
id="name"
Expand Down
5 changes: 5 additions & 0 deletions client/src/Utils/url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const normalizeUrl = (input, useHttps) => {
const raw = String(input ?? "").trim();
const cleaned = raw.replace(/^(?:https?:)?\/\//i, "");
return `http${useHttps ? "s" : ""}://${cleaned}`;
};
4 changes: 4 additions & 0 deletions server/src/validation/joi.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ const createMonitorsBodyValidation = joi.array().items(
);

const editMonitorBodyValidation = joi.object({
url: joi
.string()
.uri({ scheme: ["http", "https"] })
.optional(),
name: joi.string(),
description: joi.string(),
interval: joi.number(),
Expand Down