fix(ui): проверять каталоги дашборда и сохранять неизвестный статус серверов
This commit is contained in:
1 parent
9e0f695684
commit
8f65d1620d
8 files changed
+63
-41
No files matched your search
+12
-33
@@ -12,8 +12,6 @@ import {
|
||||
type GreTunnel,
|
||||
type PingProbe,
|
||||
type Server,
|
||||
type ServerStatus,
|
||||
type ServerType,
|
||||
} from "@/lib/data"
|
||||
import { useDataSource } from "@/lib/data-source"
|
||||
import { requestJson } from "@/shared/api/http-client"
|
||||
@@ -32,6 +30,7 @@ import type { FiltersRulesetRow, RouteOptimizerSpeedProbe } from "@/lib/route-op
|
||||
import { updateDashboardSource, type DashboardSource, type DashboardSources } from "@/lib/dashboard-source-state"
|
||||
|
||||
import {can,ensureAuthConfig} from "@/lib/auth"
|
||||
import {parseDashboardServers,parseDashboardProbes,type DashboardServerRow} from "@/lib/dashboard-readers"
|
||||
import {parseDashboardTraffic,type DashboardTraffic} from "@/lib/dashboard-traffic"
|
||||
import {parseDashboardBgp,type DashboardBgp} from "@/lib/dashboard-bgp"
|
||||
import {dashboardRequestPermission} from "@/lib/dashboard-permissions"
|
||||
@@ -62,30 +61,7 @@ function readMockDashboardStarIds(): Set<string> {
|
||||
}
|
||||
}
|
||||
|
||||
interface BackendServerRow {
|
||||
id: number
|
||||
name: string
|
||||
host: string
|
||||
site: string
|
||||
country: string
|
||||
asn: string
|
||||
type: ServerType
|
||||
enabled: boolean
|
||||
status: "online" | "offline" | null
|
||||
latency: number | null
|
||||
os: string | null
|
||||
model: string | null
|
||||
sessions?: number
|
||||
wanUplinks?: Array<{
|
||||
id: string
|
||||
name: string
|
||||
isp: string
|
||||
iface: string
|
||||
ip: string
|
||||
maxDl: number
|
||||
maxUl: number
|
||||
}>
|
||||
}
|
||||
type BackendServerRow=DashboardServerRow
|
||||
|
||||
interface ApiGreTunnelRow {
|
||||
id: string
|
||||
@@ -190,9 +166,9 @@ function mapBackendToServer(s: BackendServerRow): Server {
|
||||
asn: s.asn,
|
||||
type: s.type,
|
||||
enabled: s.enabled,
|
||||
status: (s.status ?? "offline") as ServerStatus,
|
||||
status: s.status ?? "unknown",
|
||||
latency: s.latency != null ? Math.round(s.latency) : null,
|
||||
sessions: s.sessions ?? 0,
|
||||
sessions: s.sessions,
|
||||
wanUplinks,
|
||||
}
|
||||
}
|
||||
@@ -267,8 +243,8 @@ export function useDashboardLive() {
|
||||
if(!can("mm:network:read"))setInternetPath(null)
|
||||
setOverlayItems(previous=>previous?.filter(item=>can(item.kind==="gre"?"mm:filters:read":item.kind==="wg"?"mm:network:read":"mm:dashboard:read"))??null)
|
||||
const [overviewRes, serversRes, fr, br, ipRes, greRes, wgRes, trafficRes, vxRes] = await Promise.allSettled([
|
||||
apiFetch<{ probes: PingProbe[] }>("/api/uptime/overview?range=1h"),
|
||||
apiFetch<BackendServerRow[]>("/api/servers"),
|
||||
apiFetch<unknown>("/api/uptime/overview?range=1h").then(parseDashboardProbes),
|
||||
apiFetch<unknown>("/api/servers").then(parseDashboardServers),
|
||||
apiFetch<{ rulesets: Array<{ rules?: unknown[] }> }>("/api/filters/rules"),
|
||||
apiFetch<unknown>("/api/bgp/catalog").then(parseDashboardBgp),
|
||||
apiFetch<{ snapshot: InternetPathSnapshotPayload | null }>("/api/internet-path/latest"),
|
||||
@@ -607,9 +583,9 @@ export function useDashboardLive() {
|
||||
.map((s) => ({
|
||||
id: s.id,
|
||||
title: s.name,
|
||||
hint: s.status === "degraded" ? "Ухудшение" : "Не в сети",
|
||||
hint: s.status === "unknown" ? "Статус неизвестен" : s.status === "degraded" ? "Ухудшение" : "Не в сети",
|
||||
href: "/servers?server=" + encodeURIComponent(s.id),
|
||||
tone: s.status === "degraded" ? ("warning" as const) : ("destructive" as const),
|
||||
tone: s.status === "degraded" || s.status === "unknown" ? ("warning" as const) : ("destructive" as const),
|
||||
}))
|
||||
}, [servers])
|
||||
|
||||
@@ -668,7 +644,7 @@ export function useDashboardLive() {
|
||||
overlay: !isLive || ["gre", "wg", "vxlan"].every(key => sources[key as DashboardSource]?.receivedAt != null),
|
||||
},
|
||||
reliable: {
|
||||
servers: !isLive || (liveServers !== null && !sources.servers?.error),
|
||||
servers: !isLive || (liveServers !== null && !sources.servers?.error && liveServers.every(s=>s.status!=="unknown")),
|
||||
probes: !isLive || (liveProbes !== null && !sources.probes?.error),
|
||||
overlay: !isLive || ["gre", "wg", "vxlan"].every(key => sources[key as DashboardSource]?.receivedAt != null && !sources[key as DashboardSource]?.error),
|
||||
},
|
||||
@@ -682,6 +658,9 @@ export function useDashboardLive() {
|
||||
bgp: isLive ? bgp : { prefixSum: 8432, establishedCount: 3 },
|
||||
traffic,
|
||||
onlineCount,
|
||||
offlineCount:servers.filter(s=>s.status==="offline").length,
|
||||
degradedServerCount:servers.filter(s=>s.status==="degraded").length,
|
||||
unknownServerCount:servers.filter(s=>s.status==="unknown").length,
|
||||
totalServers: servers.length,
|
||||
probeDown,
|
||||
probeWarn,
|
||||
|
||||
Reference in new issue
Block a user