postgres

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 31, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package postgres provides PostgreSQL persistence for the SENTINEL SOC.

Uses pgx/v5 driver (pure Go, no CGO) with connection pooling. Migrations managed by goose.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DB

type DB struct {
	// contains filtered or unexported fields
}

DB wraps a PostgreSQL connection pool.

func Open

func Open(dsn string, logger *slog.Logger) (*DB, error)

Open connects to PostgreSQL and runs any pending goose migrations.

dsn example: "postgres://sentinel:pass@localhost:5432/sentinel_soc?sslmode=disable"

func (*DB) Close

func (db *DB) Close() error

Close releases the connection pool.

func (*DB) Pool

func (db *DB) Pool() *sql.DB

Pool returns the underlying *sql.DB for direct queries.

type SOCRepo

type SOCRepo struct {
	// contains filtered or unexported fields
}

SOCRepo provides PostgreSQL persistence for SOC events, incidents, and sensors. Implements domain/soc.SOCRepository.

func NewSOCRepo

func NewSOCRepo(db *DB) *SOCRepo

NewSOCRepo creates a PostgreSQL-backed SOC repository. Unlike SQLite, tables are created via goose migrations (not inline DDL).

func (*SOCRepo) CountEvents

func (r *SOCRepo) CountEvents(tenantID string) (int, error)

CountEvents returns total event count.

func (*SOCRepo) CountEventsSince

func (r *SOCRepo) CountEventsSince(tenantID string, since time.Time) (int, error)

CountEventsSince returns events in the given time window.

func (*SOCRepo) CountOpenIncidents

func (r *SOCRepo) CountOpenIncidents(tenantID string) (int, error)

CountOpenIncidents returns count of non-resolved incidents.

func (*SOCRepo) CountSensorsByStatus

func (r *SOCRepo) CountSensorsByStatus(tenantID string) (map[soc.SensorStatus]int, error)

CountSensorsByStatus returns sensor count grouped by status.

func (*SOCRepo) EventExistsByHash

func (r *SOCRepo) EventExistsByHash(contentHash string) (bool, error)

EventExistsByHash checks if an event with the given content hash already exists (§5.2 dedup).

func (*SOCRepo) GetEvent

func (r *SOCRepo) GetEvent(id string) (*soc.SOCEvent, error)

GetEvent retrieves a single event by ID.

func (*SOCRepo) GetIncident

func (r *SOCRepo) GetIncident(id string) (*soc.Incident, error)

GetIncident retrieves an incident by ID.

func (*SOCRepo) GetSensor

func (r *SOCRepo) GetSensor(id string) (*soc.Sensor, error)

GetSensor retrieves a sensor by ID.

func (*SOCRepo) InsertEvent

func (r *SOCRepo) InsertEvent(e soc.SOCEvent) error

InsertEvent persists a SOC event.

func (*SOCRepo) InsertIncident

func (r *SOCRepo) InsertIncident(inc soc.Incident) error

InsertIncident persists a new incident.

func (*SOCRepo) ListEvents

func (r *SOCRepo) ListEvents(tenantID string, limit int) ([]soc.SOCEvent, error)

ListEvents returns events ordered by timestamp (newest first), with limit.

func (*SOCRepo) ListEventsByCategory

func (r *SOCRepo) ListEventsByCategory(tenantID string, category string, limit int) ([]soc.SOCEvent, error)

ListEventsByCategory returns events filtered by category.

func (*SOCRepo) ListIncidents

func (r *SOCRepo) ListIncidents(tenantID string, status string, limit int) ([]soc.Incident, error)

ListIncidents returns incidents, optionally filtered by status.

func (*SOCRepo) ListSensors

func (r *SOCRepo) ListSensors(tenantID string) ([]soc.Sensor, error)

ListSensors returns all registered sensors.

func (*SOCRepo) PurgeExpiredEvents

func (r *SOCRepo) PurgeExpiredEvents(retentionDays int) (int64, error)

PurgeExpiredEvents deletes events older than the retention period.

func (*SOCRepo) PurgeExpiredIncidents

func (r *SOCRepo) PurgeExpiredIncidents(retentionDays int) (int64, error)

PurgeExpiredIncidents deletes resolved incidents older than the retention period.

func (*SOCRepo) UpdateIncident

func (r *SOCRepo) UpdateIncident(inc *soc.Incident) error

UpdateIncident persists full incident state (case management).

func (*SOCRepo) UpdateIncidentStatus

func (r *SOCRepo) UpdateIncidentStatus(id string, status soc.IncidentStatus) error

UpdateIncidentStatus updates status (and optionally resolved_at).

func (*SOCRepo) UpsertSensor

func (r *SOCRepo) UpsertSensor(s soc.Sensor) error

UpsertSensor creates or updates a sensor entry.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL