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:
@@ -358,3 +358,58 @@ limit $2`
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func (s *PostgresStore) SaveSNMPResult(scanID string, result SNMPResult) error {
|
||||
query := `
|
||||
insert into scan_snmp (scan_id, ip, success, sys_name, sys_descr, sys_object_id, error_text, checked_at)
|
||||
values ($1, $2, $3, $4, $5, $6, $7, $8)`
|
||||
_, err := s.db.ExecContext(
|
||||
context.Background(),
|
||||
query,
|
||||
scanID,
|
||||
result.IP,
|
||||
result.Success,
|
||||
result.SysName,
|
||||
result.SysDescr,
|
||||
result.SysObjectID,
|
||||
result.Error,
|
||||
result.CheckedAt,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *PostgresStore) ListSNMPResults(scanID string, limit int) []SNMPResult {
|
||||
if limit <= 0 {
|
||||
limit = 1000
|
||||
}
|
||||
query := `
|
||||
select ip::text, success, coalesce(sys_name, ''), coalesce(sys_descr, ''), coalesce(sys_object_id, ''),
|
||||
coalesce(error_text, ''), checked_at
|
||||
from scan_snmp
|
||||
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([]SNMPResult, 0, limit)
|
||||
for rows.Next() {
|
||||
var sres SNMPResult
|
||||
if err = rows.Scan(
|
||||
&sres.IP,
|
||||
&sres.Success,
|
||||
&sres.SysName,
|
||||
&sres.SysDescr,
|
||||
&sres.SysObjectID,
|
||||
&sres.Error,
|
||||
&sres.CheckedAt,
|
||||
); err != nil {
|
||||
return nil
|
||||
}
|
||||
out = append(out, sres)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user