ListProtectionEventsByAgent returns an agent's most recent screening events (newest first, capped by limit) for the security/analytics view.
(ctx context.Context, agentID string, limit int)
| 104 | // ListProtectionEventsByAgent returns an agent's most recent screening events |
| 105 | // (newest first, capped by limit) for the security/analytics view. |
| 106 | func (s *Store) ListProtectionEventsByAgent(ctx context.Context, agentID string, limit int) ([]ProtectionEvent, error) { |
| 107 | if limit <= 0 || limit > 1000 { |
| 108 | limit = 100 |
| 109 | } |
| 110 | rows, err := s.pool.Query(ctx, |
| 111 | `SELECT id, message_id, agent_id, direction, source, reason, action, |
| 112 | subject_addr, detector, score, categories, spans, raw, created_at |
| 113 | FROM protection_events |
| 114 | WHERE agent_id = $1 |
| 115 | ORDER BY created_at DESC, id |
| 116 | LIMIT $2`, |
| 117 | agentID, limit, |
| 118 | ) |
| 119 | if err != nil { |
| 120 | return nil, fmt.Errorf("list screening events by agent: %w", err) |
| 121 | } |
| 122 | defer rows.Close() |
| 123 | return scanProtectionEvents(rows) |
| 124 | } |
| 125 | |
| 126 | // rowScanner is the minimal surface of pgx.Rows used here, so scanProtectionEvents |
| 127 | // stays decoupled from the concrete driver type. |