alertstore

package
v0.4.2 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package alertstore persists the alert engine's channels (AES-256-GCM encrypted config), rules, per-(rule,target) state, and the outbox (plan §8/§9). Channel secrets are never stored or returned in plaintext except to the notifier at send time.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChannelMeta

type ChannelMeta struct {
	ID      int64
	Name    string
	Kind    string
	Enabled bool
}

ChannelMeta is a channel without its (encrypted) config.

type NtfyManagedInfo

type NtfyManagedInfo struct {
	Name     string
	BaseURL  string
	Topic    string
	Username string
	Password string
}

NtfyManagedInfo is the display-safe subset of a Mooring-hosted ntfy channel — the subscribe URL, topic, and the read-only USERNAME+PASSWORD the operator signs into the ntfy app/web UI with. The publisher's write token is never returned.

type OutboxRow

type OutboxRow struct {
	ID         int64
	RuleID     int64
	Target     string
	Kind       string
	Level      string
	Transition string
	Summary    string
	DedupeKey  string
	Attempts   int
}

OutboxRow is one pending notification.

type Store

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

Store persists alerting state.

func New

func New(db *store.DB, cipher *secret.Cipher) *Store

New builds a Store.

func (*Store) Ack

func (s *Store) Ack(ctx context.Context, ruleID int64, target string) error

func (*Store) AllChannels

func (s *Store) AllChannels() ([]alert.Channel, error)

AllChannels builds every enabled channel. Used for Mooring-originated infra alerts (plan §8.4), which are never deferred and route to all channels. A channel that fails to build is skipped (a broken channel can't block the others).

func (*Store) ChannelByID

func (s *Store) ChannelByID(id int64) (alert.Channel, error)

ChannelByID builds a single channel (for the "send test" button).

func (*Store) ChannelKind

func (s *Store) ChannelKind(id int64) (string, error)

ChannelKind returns a channel's kind by id (for delete-time teardown decisions).

func (*Store) ChannelsForRule

func (s *Store) ChannelsForRule(channelID int64) ([]alert.Channel, error)

ChannelsForRule returns the channels a rule routes to (its channel_id, or all enabled channels when channel_id is NULL/0).

func (*Store) DeleteApp

func (s *Store) DeleteApp(ctx context.Context, slug string) error

DeleteApp removes everything alerting holds for one app: rules scoped to the app (and their live state/outbox), plus any per-target state/outbox for the app's containers under GLOBAL rules (target is "<slug>" or "<slug>/<service>"). Global channels and all-app rules are left untouched. Used by the app-delete teardown. Each statement runs on its own; the subqueries resolve before the rules are dropped.

func (*Store) DeleteChannel

func (s *Store) DeleteChannel(ctx context.Context, id int64) error

func (*Store) DeleteRule

func (s *Store) DeleteRule(ctx context.Context, id int64) error

func (*Store) EnqueueInfra

func (s *Store) EnqueueInfra(ctx context.Context, o alert.Outbox) error

EnqueueInfra appends a Mooring-originated infra notification (rule_id=0 sentinel, never deferred). It is deduped against pending rows so a re-paged condition each tick can't pile up — at most one un-sent row per (dedupe_key, transition).

func (*Store) EnqueueOutbox

func (s *Store) EnqueueOutbox(ctx context.Context, items []alert.Outbox) error

EnqueueOutbox appends notifications the evaluator produced (it never sends).

func (*Store) FiringStates

func (s *Store) FiringStates() ([]alert.State, error)

FiringStates returns the currently-open (firing) states for the UI.

func (*Store) IsSilenced

func (s *Store) IsSilenced(ruleID int64, target string, now int64) bool

IsSilenced reports whether a (rule,target) is silenced at now.

func (*Store) ListChannels

func (s *Store) ListChannels() ([]ChannelMeta, error)

ListChannels returns channel metadata (no config).

func (*Store) ListRules

func (s *Store) ListRules() ([]alert.Rule, error)

func (*Store) LoadStates

func (s *Store) LoadStates() ([]alert.State, error)

func (*Store) ManagedNtfy

func (s *Store) ManagedNtfy() (NtfyManagedInfo, bool, error)

ManagedNtfy returns the configured Mooring-hosted ntfy channel's subscribe info, or ok=false if none is configured. Decrypts the channel config but exposes only the read-only subscriber credentials (the operator must see them to subscribe), never the publisher write token.

func (*Store) MarkSent

func (s *Store) MarkSent(ctx context.Context, id int64, ok bool, maxAttempts int)

MarkSent finalizes an outbox row: ok → sent; otherwise bump attempts, and after maxAttempts mark sent anyway so a permanently-failing channel can't wedge the queue (a separate infra alert would surface a broken channel).

func (*Store) PendingOutbox

func (s *Store) PendingOutbox(limit int) ([]OutboxRow, error)

PendingOutbox returns unsent rows, oldest first.

func (*Store) PruneOutbox

func (s *Store) PruneOutbox(ctx context.Context, olderThan int64)

PruneOutbox drops sent rows older than the cutoff (bounded growth).

func (*Store) RuleByID

func (s *Store) RuleByID(id int64) (alert.Rule, bool)

RuleByID returns one rule (the notifier needs its channel routing).

func (*Store) SaveChannel

func (s *Store) SaveChannel(ctx context.Context, name, kind string, configJSON []byte) error

SaveChannel validates + encrypts a channel config and upserts by name.

func (*Store) SaveRule

func (s *Store) SaveRule(ctx context.Context, r alert.Rule) error

func (*Store) SaveStates

func (s *Store) SaveStates(ctx context.Context, states []alert.State) error

SaveStates upserts the state set and prunes ok rows to keep the table bounded.

func (*Store) Silence

func (s *Store) Silence(ctx context.Context, ruleID int64, target string, until int64) error

Jump to

Keyboard shortcuts

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