feat(ui,snmp): IF-MIB интерфейсы в табл.1 связей, слияние с LLDP, сортировка по локальному порту

Made-with: Cursor
This commit is contained in:
Луценко Андрей Анатольевич
2026-04-10 16:04:16 +10:00
parent 2388b5f3ff
commit a7f80eac9a
7 changed files with 448 additions and 40 deletions
+32 -2
View File
@@ -67,6 +67,7 @@ func (h *Handler) Routes() http.Handler {
mux.HandleFunc("GET /api/scans/{id}/ports", h.getScanPorts)
mux.HandleFunc("GET /api/scans/{id}/snmp", h.getScanSNMP)
mux.HandleFunc("GET /api/scans/{id}/lldp", h.getScanLLDP)
mux.HandleFunc("GET /api/scans/{id}/interfaces", h.getScanInterfaces)
mux.HandleFunc("GET /api/scans/{id}/links", h.getScanLinks)
mux.HandleFunc("GET /api/scans/{id}/topology", h.getScanTopology)
return withJSON(mux)
@@ -274,6 +275,35 @@ func (h *Handler) getScanLLDP(w http.ResponseWriter, r *http.Request) {
})
}
func (h *Handler) getScanInterfaces(w http.ResponseWriter, r *http.Request) {
id := r.PathValue("id")
if id == "" {
writeError(w, http.StatusBadRequest, "scan id is required")
return
}
if _, ok := h.store.GetScan(id); !ok {
writeError(w, http.StatusNotFound, "scan not found")
return
}
ip := strings.TrimSpace(r.URL.Query().Get("ip"))
if ip == "" {
writeError(w, http.StatusBadRequest, "query parameter ip is required")
return
}
limit := 4096
if raw := r.URL.Query().Get("limit"); raw != "" {
n, err := strconv.Atoi(raw)
if err != nil || n <= 0 || n > 10000 {
writeError(w, http.StatusBadRequest, "limit must be between 1 and 10000")
return
}
limit = n
}
writeJSON(w, http.StatusOK, map[string]any{
"items": h.store.ListInterfaceResults(id, ip, limit),
})
}
func (h *Handler) getScanLinks(w http.ResponseWriter, r *http.Request) {
id := r.PathValue("id")
if id == "" {
@@ -295,7 +325,7 @@ func (h *Handler) getScanLinks(w http.ResponseWriter, r *http.Request) {
limit = n
}
snmpItems := h.store.ListSNMPResults(id, 10000)
snmpItems := h.store.ListSNMPResults(id, 200000)
lldpItems := h.store.ListLLDPResults(id, limit)
sysNameToIP := make(map[string]string, len(snmpItems))
@@ -358,7 +388,7 @@ func (h *Handler) getScanTopology(w http.ResponseWriter, r *http.Request) {
limit = n
}
snmpItems := h.store.ListSNMPResults(id, 10000)
snmpItems := h.store.ListSNMPResults(id, 200000)
lldpItems := h.store.ListLLDPResults(id, limit)
sysNameToIP := make(map[string]string, len(snmpItems))