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:
Andrey Lutsenko
2026-04-09 21:58:30 +10:00
parent cca4477792
commit ec7abe384d
6 changed files with 212 additions and 5 deletions
+53
View File
@@ -413,3 +413,56 @@ limit $2`
}
return out
}
func (s *PostgresStore) SaveLLDPResult(scanID string, result LLDPResult) error {
query := `
insert into scan_lldp (scan_id, ip, local_port_num, remote_chassis_id, remote_port_id, remote_sys_name, checked_at)
values ($1, $2, $3, $4, $5, $6, $7)`
_, err := s.db.ExecContext(
context.Background(),
query,
scanID,
result.IP,
result.LocalPortNum,
result.RemoteChassisID,
result.RemotePortID,
result.RemoteSysName,
result.CheckedAt,
)
return err
}
func (s *PostgresStore) ListLLDPResults(scanID string, limit int) []LLDPResult {
if limit <= 0 {
limit = 2000
}
query := `
select ip::text, coalesce(local_port_num, ''), coalesce(remote_chassis_id, ''),
coalesce(remote_port_id, ''), coalesce(remote_sys_name, ''), checked_at
from scan_lldp
where scan_id = $1
order by checked_at desc
limit $2`
rows, err := s.db.QueryContext(context.Background(), query, scanID, limit)
if err != nil {
return nil
}
defer rows.Close()
out := make([]LLDPResult, 0, limit)
for rows.Next() {
var lr LLDPResult
if err = rows.Scan(
&lr.IP,
&lr.LocalPortNum,
&lr.RemoteChassisID,
&lr.RemotePortID,
&lr.RemoteSysName,
&lr.CheckedAt,
); err != nil {
return nil
}
out = append(out, lr)
}
return out
}