fix(ui): сохранить неизвестные данные и ошибки BGP на дашборде

This commit is contained in:
Denozordec committed 2026-10-03 22:55:15 +07:00
1 parent c343ce62c8
commit f0eaa94e02
11 files changed
+78 -24

No files matched your search

+16
View File
@@ -0,0 +1,16 @@
import {bgpCatalogSchema} from "@/lib/bgp/response"
export interface DashboardBgp {prefixSum:number|null;establishedCount:number|null}
/** A failed device cannot be counted as having no sessions in the global KPI. */
export function parseDashboardBgp(raw:unknown):DashboardBgp {
const catalog=bgpCatalogSchema.safeParse(raw)
if(!catalog.success)throw Error("Некорректный ответ каталога BGP")
if(catalog.data.failures.length)throw Error("Не опрошены устройства BGP: "+catalog.data.failures.map(f=>f.serverName+": "+f.error).join("; "))
let prefixSum=0,establishedCount=0,missingPrefix=false,unknownState=false
for(const session of catalog.data.sessions){
const state=session.state.toLowerCase()
if(state==="established"){establishedCount++;if(session.prefixesRx===null)missingPrefix=true;else prefixSum+=session.prefixesRx}
else if(!["active","idle","connect","opensent","openconfirm"].includes(state))unknownState=true
}
if(!Number.isSafeInteger(prefixSum))throw Error("Суммарный счётчик BGP превышает допустимый диапазон")
return {prefixSum:unknownState||missingPrefix?null:prefixSum,establishedCount:unknownState?null:establishedCount}
}