fix(ui): сохранить неизвестные данные и ошибки BGP на дашборде
This commit is contained in:
1 parent
c343ce62c8
commit
f0eaa94e02
11 files changed
+78
-24
No files matched your search
@@ -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}
|
||||
}
|
||||
Reference in new issue
Block a user