diff --git a/internal/hub/systems/system.go b/internal/hub/systems/system.go index b47e07f0..7100d8ee 100644 --- a/internal/hub/systems/system.go +++ b/internal/hub/systems/system.go @@ -319,18 +319,18 @@ func updateNetworkProbesRecords(app core.App, data map[string]probe.Result, syst return nil } collectionName := "network_probes" + nowString := time.Now().UTC().Format(types.DefaultDateLayout) for key := range data { probe := data[key] id := MakeStableHashId(systemId, key) params := dbx.Params{ - // "system": systemId, "latency": probe[0], "loss": probe[3], - "updated": time.Now().UTC().Format(types.DefaultDateLayout), + "updated": nowString, } _, err := app.DB().Update(collectionName, params, dbx.HashExp{"id": id}).Execute() if err != nil { - app.Logger().Warn("Failed to update network probe record", "system", systemId, "probe", key, "err", err) + app.Logger().Warn("Failed to update probe", "system", systemId, "probe", key, "err", err) } } return nil diff --git a/internal/site/src/components/navbar.tsx b/internal/site/src/components/navbar.tsx index 5352fd7a..0446f4b2 100644 --- a/internal/site/src/components/navbar.tsx +++ b/internal/site/src/components/navbar.tsx @@ -8,6 +8,7 @@ import { LogOutIcon, LogsIcon, MenuIcon, + NetworkIcon, PlusIcon, SearchIcon, ServerIcon, @@ -109,6 +110,10 @@ export default function Navbar() { S.M.A.R.T. + navigate(getPagePath($router, "probes"))} className="flex items-center"> + + Network Probes + navigate(getPagePath($router, "settings", { name: "general" }))} className="flex items-center" @@ -180,6 +185,21 @@ export default function Navbar() { S.M.A.R.T. + + + import("@/components/routes/probes")} + > + + + + + Network Probes + + diff --git a/internal/site/src/components/network-probes-table/network-probes-table.tsx b/internal/site/src/components/network-probes-table/network-probes-table.tsx index e334c7f0..58553dbe 100644 --- a/internal/site/src/components/network-probes-table/network-probes-table.tsx +++ b/internal/site/src/components/network-probes-table/network-probes-table.tsx @@ -195,7 +195,7 @@ export default function NetworkProbesTableNew({ systemId }: { systemId?: string className="ms-auto px-4 w-full max-w-full md:w-64" /> )} - {systemId && !isReadOnlyUser() ? : null} + {!isReadOnlyUser() ? : null} diff --git a/internal/site/src/components/network-probes-table/probe-dialog.tsx b/internal/site/src/components/network-probes-table/probe-dialog.tsx index 6b357bc1..04d0b1cb 100644 --- a/internal/site/src/components/network-probes-table/probe-dialog.tsx +++ b/internal/site/src/components/network-probes-table/probe-dialog.tsx @@ -1,5 +1,6 @@ import { useState } from "react" import { Trans, useLingui } from "@lingui/react/macro" +import { useStore } from "@nanostores/react" import { pb } from "@/lib/api" import { Dialog, @@ -16,8 +17,9 @@ import { Label } from "@/components/ui/label" import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select" import { PlusIcon } from "lucide-react" import { useToast } from "@/components/ui/use-toast" +import { $systems } from "@/lib/stores" -export function AddProbeDialog({ systemId }: { systemId: string }) { +export function AddProbeDialog({ systemId }: { systemId?: string }) { const [open, setOpen] = useState(false) const [protocol, setProtocol] = useState("icmp") const [target, setTarget] = useState("") @@ -25,6 +27,8 @@ export function AddProbeDialog({ systemId }: { systemId: string }) { const [probeInterval, setProbeInterval] = useState("60") const [name, setName] = useState("") const [loading, setLoading] = useState(false) + const [selectedSystemId, setSelectedSystemId] = useState("") + const systems = useStore($systems) const { toast } = useToast() const { t } = useLingui() @@ -34,6 +38,7 @@ export function AddProbeDialog({ systemId }: { systemId: string }) { setPort("") setProbeInterval("60") setName("") + setSelectedSystemId("") } const handleSubmit = async (e: React.FormEvent) => { @@ -41,7 +46,7 @@ export function AddProbeDialog({ systemId }: { systemId: string }) { setLoading(true) try { await pb.collection("network_probes").create({ - system: systemId, + system: systemId ?? selectedSystemId, name, target, protocol, @@ -76,6 +81,25 @@ export function AddProbeDialog({ systemId }: { systemId: string }) {
+ {!systemId && ( +
+ + +
+ )}
- diff --git a/internal/site/src/components/router.tsx b/internal/site/src/components/router.tsx index fb525972..15415705 100644 --- a/internal/site/src/components/router.tsx +++ b/internal/site/src/components/router.tsx @@ -4,6 +4,7 @@ const routes = { home: "/", containers: "/containers", smart: "/smart", + probes: "/probes", system: `/system/:id`, settings: `/settings/:name?`, forgot_password: `/forgot-password`, diff --git a/internal/site/src/components/routes/probes.tsx b/internal/site/src/components/routes/probes.tsx new file mode 100644 index 00000000..35f2ee48 --- /dev/null +++ b/internal/site/src/components/routes/probes.tsx @@ -0,0 +1,26 @@ +import { useLingui } from "@lingui/react/macro" +import { memo, useEffect, useMemo } from "react" +import NetworkProbesTableNew from "@/components/network-probes-table/network-probes-table" +import { ActiveAlerts } from "@/components/active-alerts" +import { FooterRepoLink } from "@/components/footer-repo-link" + +export default memo(() => { + const { t } = useLingui() + + useEffect(() => { + document.title = `${t`Network Probes`} / Beszel` + }, [t]) + + return useMemo( + () => ( + <> +
+ + +
+ + + ), + [] + ) +}) diff --git a/internal/site/src/main.tsx b/internal/site/src/main.tsx index bcb1f8cb..78599f4b 100644 --- a/internal/site/src/main.tsx +++ b/internal/site/src/main.tsx @@ -30,6 +30,7 @@ const LoginPage = lazy(() => import("@/components/login/login.tsx")) const Home = lazy(() => import("@/components/routes/home.tsx")) const Containers = lazy(() => import("@/components/routes/containers.tsx")) const Smart = lazy(() => import("@/components/routes/smart.tsx")) +const Probes = lazy(() => import("@/components/routes/probes.tsx")) const SystemDetail = lazy(() => import("@/components/routes/system.tsx")) const CopyToClipboardDialog = lazy(() => import("@/components/copy-to-clipboard.tsx")) @@ -79,6 +80,8 @@ const App = memo(() => { return } else if (page.route === "smart") { return + } else if (page.route === "probes") { + return } else if (page.route === "settings") { return }