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 ¶
- type ChannelMeta
- type NtfyManagedInfo
- type OutboxRow
- type Store
- func (s *Store) Ack(ctx context.Context, ruleID int64, target string) error
- func (s *Store) AllChannels() ([]alert.Channel, error)
- func (s *Store) ChannelByID(id int64) (alert.Channel, error)
- func (s *Store) ChannelKind(id int64) (string, error)
- func (s *Store) ChannelsForRule(channelID int64) ([]alert.Channel, error)
- func (s *Store) DeleteApp(ctx context.Context, slug string) error
- func (s *Store) DeleteChannel(ctx context.Context, id int64) error
- func (s *Store) DeleteRule(ctx context.Context, id int64) error
- func (s *Store) EnqueueInfra(ctx context.Context, o alert.Outbox) error
- func (s *Store) EnqueueOutbox(ctx context.Context, items []alert.Outbox) error
- func (s *Store) FiringStates() ([]alert.State, error)
- func (s *Store) IsSilenced(ruleID int64, target string, now int64) bool
- func (s *Store) ListChannels() ([]ChannelMeta, error)
- func (s *Store) ListRules() ([]alert.Rule, error)
- func (s *Store) LoadStates() ([]alert.State, error)
- func (s *Store) ManagedNtfy() (NtfyManagedInfo, bool, error)
- func (s *Store) MarkSent(ctx context.Context, id int64, ok bool, maxAttempts int)
- func (s *Store) PendingOutbox(limit int) ([]OutboxRow, error)
- func (s *Store) PruneOutbox(ctx context.Context, olderThan int64)
- func (s *Store) RuleByID(id int64) (alert.Rule, bool)
- func (s *Store) SaveChannel(ctx context.Context, name, kind string, configJSON []byte) error
- func (s *Store) SaveRule(ctx context.Context, r alert.Rule) error
- func (s *Store) SaveStates(ctx context.Context, states []alert.State) error
- func (s *Store) Silence(ctx context.Context, ruleID int64, target string, until int64) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChannelMeta ¶
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 (*Store) AllChannels ¶
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 ¶
ChannelByID builds a single channel (for the "send test" button).
func (*Store) ChannelKind ¶
ChannelKind returns a channel's kind by id (for delete-time teardown decisions).
func (*Store) ChannelsForRule ¶
ChannelsForRule returns the channels a rule routes to (its channel_id, or all enabled channels when channel_id is NULL/0).
func (*Store) DeleteApp ¶
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) EnqueueInfra ¶
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 ¶
EnqueueOutbox appends notifications the evaluator produced (it never sends).
func (*Store) FiringStates ¶
FiringStates returns the currently-open (firing) states for the UI.
func (*Store) IsSilenced ¶
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) 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 ¶
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 ¶
PendingOutbox returns unsent rows, oldest first.
func (*Store) PruneOutbox ¶
PruneOutbox drops sent rows older than the cutoff (bounded growth).
func (*Store) SaveChannel ¶
SaveChannel validates + encrypts a channel config and upserts by name.
func (*Store) SaveStates ¶
SaveStates upserts the state set and prunes ok rows to keep the table bounded.