Docker images / prepare-release (push) Successful in 7s
Docker images / backend-test (push) Successful in 1m40s
Docker images / frontend-image (push) Successful in 2m50s
Docker images / updater-image (push) Successful in 42s
Docker images / backend-image (push) Successful in 2m40s
Docker images / notify-webhook (push) Skipped
Docker images / publish-release (push) Successful in 10s
- Added support for fetching and displaying server data in BGP, VXLAN, and OSPF pages, improving the overall user experience. - Introduced new backend routes for OSPF and VXLAN, allowing for better data management and retrieval. - Implemented mapping functions for backend server data to frontend types, ensuring consistency across components. - Enhanced the sidebar to display counts for BGP sessions, VXLAN tunnels, and containers, providing users with quick insights into their network status. - Updated tests to cover new functionalities and ensure reliability. Co-authored-by: Cursor <cursoragent@cursor.com>
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import { eq } from "drizzle-orm"
|
|
import { db } from "../db/index.js"
|
|
import { servers } from "../db/schema.js"
|
|
import type { BgpSessionRead } from "../types/server.js"
|
|
import { parseBgpSessions } from "./bgp-parse-sessions.js"
|
|
import { MikrotikClient } from "./mikrotik.js"
|
|
|
|
/** Как в UI `/alerts`: `serverName: peerName`. */
|
|
export function bgpPeerAlertKey(s: BgpSessionRead): string {
|
|
const sn = String(s.serverName ?? "").trim()
|
|
const nm = String(s.name ?? "").trim()
|
|
return `${sn}: ${nm}`.trim()
|
|
}
|
|
|
|
/** Агрегат BGP-сессий с включённых серверов — как `/api/bgp/sessions`. */
|
|
export async function fetchBgpSessionsForAlerts(): Promise<BgpSessionRead[]> {
|
|
const allServers = await db.select().from(servers).where(eq(servers.enabled, true))
|
|
const results = await Promise.all(
|
|
allServers.map(async (server) => {
|
|
try {
|
|
const client = MikrotikClient.fromServer(server)
|
|
const raw = await client.getBgpSessions()
|
|
return parseBgpSessions(server, raw)
|
|
} catch {
|
|
return [] as BgpSessionRead[]
|
|
}
|
|
}),
|
|
)
|
|
return results.flat()
|
|
}
|
|
|
|
export async function countBgpSessions(): Promise<number> {
|
|
try {
|
|
const result = await Promise.race([
|
|
fetchBgpSessionsForAlerts(),
|
|
new Promise<null>((resolve) => setTimeout(() => resolve(null), 8_000)),
|
|
])
|
|
if (!result) return 0
|
|
return result.length
|
|
} catch {
|
|
return 0
|
|
}
|
|
}
|