feat(ui,snmp): IF-MIB интерфейсы в табл.1 связей, слияние с LLDP, сортировка по локальному порту
Made-with: Cursor
This commit is contained in:
@@ -475,3 +475,60 @@ limit $2`
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (s *PostgresStore) SaveInterfaceResult(scanID string, result InterfaceResult) error {
|
||||
query := `
|
||||
insert into scan_interfaces (scan_id, ip, if_index, if_descr, if_name, if_oper_status, checked_at)
|
||||
values ($1, $2, $3, $4, $5, $6, $7)`
|
||||
_, err := s.db.ExecContext(
|
||||
context.Background(),
|
||||
query,
|
||||
scanID,
|
||||
result.IP,
|
||||
result.IfIndex,
|
||||
result.IfDescr,
|
||||
result.IfName,
|
||||
result.IfOperStatus,
|
||||
result.CheckedAt,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *PostgresStore) ListInterfaceResults(scanID string, filterIP string, limit int) []InterfaceResult {
|
||||
if limit <= 0 {
|
||||
limit = 4096
|
||||
}
|
||||
var rows *sql.Rows
|
||||
var err error
|
||||
if filterIP != "" {
|
||||
rows, err = s.db.QueryContext(context.Background(), `
|
||||
select ip::text, if_index, coalesce(if_descr, ''), coalesce(if_name, ''), coalesce(if_oper_status, ''), checked_at
|
||||
from scan_interfaces
|
||||
where scan_id = $1 and ip = $2::inet
|
||||
order by if_index asc
|
||||
limit $3`,
|
||||
scanID, filterIP, limit)
|
||||
} else {
|
||||
rows, err = s.db.QueryContext(context.Background(), `
|
||||
select ip::text, if_index, coalesce(if_descr, ''), coalesce(if_name, ''), coalesce(if_oper_status, ''), checked_at
|
||||
from scan_interfaces
|
||||
where scan_id = $1
|
||||
order by ip asc, if_index asc
|
||||
limit $2`,
|
||||
scanID, limit)
|
||||
}
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
out := make([]InterfaceResult, 0, 256)
|
||||
for rows.Next() {
|
||||
var r InterfaceResult
|
||||
if err = rows.Scan(&r.IP, &r.IfIndex, &r.IfDescr, &r.IfName, &r.IfOperStatus, &r.CheckedAt); err != nil {
|
||||
return nil
|
||||
}
|
||||
out = append(out, r)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user