Add SNMP v2c probing and results endpoint.

Probe sysName/sysDescr/sysObjectID for alive hosts, persist SNMP outcomes, and expose scan SNMP data via REST.

Made-with: Cursor
This commit is contained in:
Andrey Lutsenko
2026-04-09 21:56:31 +10:00
parent e9452dcc0a
commit cca4477792
10 changed files with 234 additions and 3 deletions
+27
View File
@@ -27,6 +27,7 @@ func (h *Handler) Routes() http.Handler {
mux.HandleFunc("GET /api/scans/{id}", h.getScan)
mux.HandleFunc("GET /api/scans/{id}/hosts", h.getScanHosts)
mux.HandleFunc("GET /api/scans/{id}/ports", h.getScanPorts)
mux.HandleFunc("GET /api/scans/{id}/snmp", h.getScanSNMP)
return withJSON(mux)
}
@@ -148,6 +149,32 @@ func (h *Handler) getScanPorts(w http.ResponseWriter, r *http.Request) {
})
}
func (h *Handler) getScanSNMP(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
}
limit := 1000
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.ListSNMPResults(id, limit),
})
}
func withJSON(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")