-
-
Notifications
You must be signed in to change notification settings - Fork 599
feat: allow updating monitor URL and type via Configure #2752
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
46579cd
db754cb
38fe814
da4b5c9
81ec448
3776441
94d171c
4da2ebe
4fec374
6e3c8b8
d5e4fe0
ab177d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -76,6 +76,22 @@ const CreateInfrastructureMonitor = () => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { name: "Configure", path: `/infrastructure/configure/${monitorId}` }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const METRICS = ["cpu", "memory", "disk", "temperature"]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const METRIC_PREFIX = "usage_"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const MS_PER_MINUTE = 60000; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const hasAlertError = (errors) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return Object.keys(errors).filter((k) => k.startsWith(METRIC_PREFIX)).length > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const getAlertError = (errors) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const errorKey = Object.keys(errors).find((key) => key.startsWith(METRIC_PREFIX)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return errorKey ? errors[errorKey] : null; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const pageSchema = infrastructureMonitorValidation.fork(["url"], (s) => | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| isCreate ? s.required() : s.optional() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Populate form fields if editing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| useEffect(() => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (isCreate) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -96,6 +112,35 @@ const CreateInfrastructureMonitor = () => { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Build the thresholds for the form | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cpu, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| usage_cpu, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| memory, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| usage_memory, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| disk, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| usage_disk, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| temperature, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| usage_temperature, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...rest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } = form; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const thresholds = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...(cpu ? { usage_cpu: usage_cpu / 100 } : {}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...(memory ? { usage_memory: usage_memory / 100 } : {}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...(disk ? { usage_disk: usage_disk / 100 } : {}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...(temperature ? { usage_temperature: usage_temperature / 100 } : {}), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| form = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...(isCreate ? {} : { _id: monitorId }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...rest, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| url: `http${https ? "s" : ""}://` + infrastructureMonitor.url, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| description: form.name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: "hardware", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| notifications: infrastructureMonitor.notifications, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| thresholds, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| submitInfrastructureForm(infrastructureMonitor, form, isCreate, monitorId); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+128
to
144
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix: const reassignment of form (compile error). You reassign form after declaring it as const. Let's not trigger a cross-border incident between const and let—just build a separate payload. - form = {
+ const payload = {
...(isCreate ? {} : { _id: monitorId }),
...rest,
url: `http${https ? "s" : ""}://` + infrastructureMonitor.url,
description: form.name,
type: "hardware",
notifications: infrastructureMonitor.notifications,
thresholds,
};
- submitInfrastructureForm(infrastructureMonitor, form, isCreate, monitorId);
+ submitInfrastructureForm(infrastructureMonitor, payload, isCreate, monitorId);Optional: to harden threshold math, coerce numbers and bound to [0, 1] when the toggle is on (prevents accidental NaN/negatives sneaking in). 📝 Committable suggestion
Suggested change
🧰 Tools🪛 Biome (2.1.2)[error] 135-135: Can't assign form because it's a constant. This is where the variable is defined as constant. Unsafe fix: Replace const with let if you assign it to a new value. (lint/correctness/noConstAssign) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -217,31 +262,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" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.