feat: MAC lookup in scan FDB (API mac-locations, UI table, index)
Made-with: Cursor
This commit is contained in:
@@ -534,6 +534,37 @@ limit $2`,
|
||||
return out
|
||||
}
|
||||
|
||||
func (s *PostgresStore) ListPortDevicesByMac(scanID string, mac string, limit int) []PortDeviceResult {
|
||||
if limit <= 0 {
|
||||
limit = 5000
|
||||
}
|
||||
if mac == "" {
|
||||
return nil
|
||||
}
|
||||
query := `
|
||||
select ip::text, if_index, bridge_port, vlan, coalesce(mac, ''), coalesce(learned_ip::text, ''), checked_at
|
||||
from scan_port_devices
|
||||
where scan_id = $1
|
||||
and lower(replace(trim(coalesce(mac, '')), '-', ':')) = lower(replace(trim($2::text), '-', ':'))
|
||||
order by ip::text asc, if_index asc, vlan asc, mac asc, learned_ip asc
|
||||
limit $3`
|
||||
rows, err := s.db.QueryContext(context.Background(), query, scanID, mac, limit)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
out := make([]PortDeviceResult, 0, 32)
|
||||
for rows.Next() {
|
||||
var r PortDeviceResult
|
||||
if err = rows.Scan(&r.IP, &r.IfIndex, &r.BridgePort, &r.Vlan, &r.MAC, &r.LearnedIP, &r.CheckedAt); err != nil {
|
||||
return nil
|
||||
}
|
||||
out = append(out, r)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (s *PostgresStore) PurgeAllScanData() error {
|
||||
// Дочерние таблицы ссылаются на scan_jobs — CASCADE очищает всё; RESTART IDENTITY сбрасывает bigserial.
|
||||
_, err := s.db.ExecContext(context.Background(), `truncate table scan_jobs restart identity cascade`)
|
||||
|
||||
Reference in New Issue
Block a user