Add LLDP neighbor collection and endpoint.
Collect LLDP-MIB neighbor fields during SNMP scans, persist records, and expose LLDP results via REST. Made-with: Cursor
This commit is contained in:
@@ -65,6 +65,8 @@ type Store interface {
|
||||
ListOpenPortResults(scanID string, limit int) []OpenPortResult
|
||||
SaveSNMPResult(scanID string, result SNMPResult) error
|
||||
ListSNMPResults(scanID string, limit int) []SNMPResult
|
||||
SaveLLDPResult(scanID string, result LLDPResult) error
|
||||
ListLLDPResults(scanID string, limit int) []LLDPResult
|
||||
}
|
||||
|
||||
type HostResult struct {
|
||||
@@ -90,12 +92,22 @@ type SNMPResult struct {
|
||||
CheckedAt time.Time `json:"checked_at"`
|
||||
}
|
||||
|
||||
type LLDPResult struct {
|
||||
IP string `json:"ip"`
|
||||
LocalPortNum string `json:"local_port_num"`
|
||||
RemoteChassisID string `json:"remote_chassis_id"`
|
||||
RemotePortID string `json:"remote_port_id"`
|
||||
RemoteSysName string `json:"remote_sys_name"`
|
||||
CheckedAt time.Time `json:"checked_at"`
|
||||
}
|
||||
|
||||
type MemoryStore struct {
|
||||
mu sync.RWMutex
|
||||
jobs map[string]ScanJob
|
||||
hosts map[string][]HostResult
|
||||
ports map[string][]OpenPortResult
|
||||
snmp map[string][]SNMPResult
|
||||
lldp map[string][]LLDPResult
|
||||
}
|
||||
|
||||
func NewMemoryStore() *MemoryStore {
|
||||
@@ -104,6 +116,7 @@ func NewMemoryStore() *MemoryStore {
|
||||
hosts: make(map[string][]HostResult),
|
||||
ports: make(map[string][]OpenPortResult),
|
||||
snmp: make(map[string][]SNMPResult),
|
||||
lldp: make(map[string][]LLDPResult),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -283,6 +296,35 @@ func (s *MemoryStore) ListSNMPResults(scanID string, limit int) []SNMPResult {
|
||||
return out
|
||||
}
|
||||
|
||||
func (s *MemoryStore) SaveLLDPResult(scanID string, result LLDPResult) error {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
|
||||
if _, ok := s.jobs[scanID]; !ok {
|
||||
return errors.New("scan not found")
|
||||
}
|
||||
s.lldp[scanID] = append(s.lldp[scanID], result)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *MemoryStore) ListLLDPResults(scanID string, limit int) []LLDPResult {
|
||||
if limit <= 0 {
|
||||
limit = 2000
|
||||
}
|
||||
s.mu.RLock()
|
||||
defer s.mu.RUnlock()
|
||||
|
||||
items := s.lldp[scanID]
|
||||
if len(items) <= limit {
|
||||
out := make([]LLDPResult, len(items))
|
||||
copy(out, items)
|
||||
return out
|
||||
}
|
||||
out := make([]LLDPResult, limit)
|
||||
copy(out, items[:limit])
|
||||
return out
|
||||
}
|
||||
|
||||
func applyDefaultOptions(opts *ScanOptions) {
|
||||
if opts.PingTimeoutMS <= 0 {
|
||||
opts.PingTimeoutMS = 700
|
||||
|
||||
Reference in New Issue
Block a user