fix(api): показывать подтверждённые метрики OSPF
This commit is contained in:
1 parent
e3791f3496
commit
af05ad5cda
13 files changed
+120
-55
No files matched your search
@@ -3,9 +3,12 @@ import type { OspfNeighborRead, OspfInterfaceRead, OspfInstanceRead, BfdSessionR
|
||||
export type NullableFields<T, K extends keyof T> = Omit<T, K> & { [P in K]: T[P] | null }
|
||||
export type CatalogNeighbor = NullableFields<OspfNeighborRead, "priority" | "stateChanges">
|
||||
export type CatalogBfdSession = NullableFields<BfdSessionRead, "multiplier" | "txInterval" | "rxInterval" | "holdTime" | "packetsRx" | "packetsTx" | "stateChanges">
|
||||
export type CatalogInterface = NullableFields<OspfInterfaceRead, "cost" | "type" | "priority" | "helloInterval" | "deadInterval" | "disabled" | "inactive" | "useBfd">
|
||||
export type CatalogInstance = NullableFields<OspfInstanceRead, "version" | "routerId" | "disabled" | "inactive">
|
||||
export type CatalogRoute = NullableFields<OspfRouteRead, "cost">
|
||||
export interface OspfCatalogCollections {
|
||||
neighbors: CatalogNeighbor[]; interfaces: OspfInterfaceRead[]; instances: OspfInstanceRead[];
|
||||
bfdSessions: CatalogBfdSession[]; routes: OspfRouteRead[];
|
||||
neighbors: CatalogNeighbor[]; interfaces: CatalogInterface[]; instances: CatalogInstance[];
|
||||
bfdSessions: CatalogBfdSession[]; routes: CatalogRoute[];
|
||||
}
|
||||
export const emptyOspfCatalog = (): OspfCatalogCollections => ({ neighbors: [], interfaces: [], instances: [], bfdSessions: [], routes: [] })
|
||||
export async function readOspfCatalogRaw(client: Pick<MikrotikClient, "getOspfNeighbors" | "getOspfAreas" | "getOspfInterfaceTemplates" | "getOspfInstances" | "getBfdSessions" | "getIpRoutes">) {
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
import assert from "node:assert/strict"
|
||||
import { observedInteger, observedDurationMs } from "./ospf-observed-values.js"
|
||||
import { observedInteger, observedDurationMs, observedBoolean } from "./ospf-observed-values.js"
|
||||
for (const raw of [undefined, "", " ", "1x", "-1", "1.5", "9007199254740992"]) assert.equal(observedInteger(raw), null)
|
||||
assert.equal(observedInteger("0"), 0); assert.equal(observedInteger("255", 0, 255), 255); assert.equal(observedInteger("256", 0, 255), null)
|
||||
for (const raw of [undefined, "", "-1s", "12junk", "200", "1s2s", "60:00", "00:99:00", "1s junk"]) assert.equal(observedDurationMs(raw), null)
|
||||
for (const [raw, ms] of [["0ms", 0], ["0", 0], ["1us", 0.001], ["1s200ms", 1200], ["1h2m3s", 3723000], ["01:02:03.5", 3723500], ["02:03", 123000]] as const) assert.equal(observedDurationMs(raw), ms)
|
||||
console.log("OSPF observed values: absent/zero/invalid/unsafe/units/clock passed")
|
||||
|
||||
for (const raw of [undefined, "", "junk"]) assert.equal(observedBoolean(raw), null)
|
||||
for (const raw of ["true", "yes"]) assert.equal(observedBoolean(raw), true)
|
||||
for (const raw of ["false", "no"]) assert.equal(observedBoolean(raw), false)
|
||||
@@ -26,3 +26,9 @@ export function observedDurationMs(value: string | undefined): number | null {
|
||||
}
|
||||
return cursor === text.length && Number.isFinite(total) && total <= Number.MAX_SAFE_INTEGER ? total : null
|
||||
}
|
||||
|
||||
export function observedBoolean(value: string | undefined): boolean | null {
|
||||
if (value === "true" || value === "yes") return true
|
||||
if (value === "false" || value === "no") return false
|
||||
return null
|
||||
}
|
||||
Reference in new issue
Block a user