Persist per-host scan results and expose hosts endpoint.

Store checked hosts for each scan and add API to fetch host-level up/down probe results.

Made-with: Cursor
This commit is contained in:
Andrey Lutsenko
2026-04-09 21:51:35 +10:00
parent 43cb339605
commit 9afbbbb762
6 changed files with 127 additions and 3 deletions
+35
View File
@@ -280,3 +280,38 @@ where id = $1`
return current, true
}
func (s *PostgresStore) SaveHostResult(scanID string, host HostResult) error {
query := `
insert into scan_hosts (scan_id, ip, is_up, checked_at)
values ($1, $2, $3, $4)`
_, err := s.db.ExecContext(context.Background(), query, scanID, host.IP, host.IsUp, host.CheckedAt)
return err
}
func (s *PostgresStore) ListHostResults(scanID string, limit int) []HostResult {
if limit <= 0 {
limit = 500
}
query := `
select ip::text, is_up, checked_at
from scan_hosts
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([]HostResult, 0, limit)
for rows.Next() {
var h HostResult
if err = rows.Scan(&h.IP, &h.IsUp, &h.CheckedAt); err != nil {
return nil
}
out = append(out, h)
}
return out
}