notify

package
v0.1.0-alpha.8 Latest Latest
Warning

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

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

Documentation

Overview

Package notify is the alert engine (T-74): the leader evaluates AlertRules against metrics (TSDB/livestate) and cluster events, and delivers firing and resolved notifications to NotificationChannels (webhook, Slack, email) with per-rule dedupe. Notifier failures never stall evaluation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Store     Store
	Metrics   MetricSource
	Opener    Opener
	Clock     clock.Clock
	Logger    *slog.Logger
	HTTP      *http.Client
	EmitEvent func(kind, severity, message string)
}

Config wires an Engine.

type Email

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

Email delivers notifications over SMTP. It is intentionally best-effort — SMTP is the flakiest channel — and honors the caller's context deadline for the initial connection.

func NewEmail

func NewEmail(cfg EmailConfig) *Email

NewEmail builds an SMTP notifier from a resolved config.

func (*Email) Send

func (e *Email) Send(ctx context.Context, n Notification) error

type EmailConfig

type EmailConfig struct {
	Host     string
	Port     uint32
	Username string
	Password string
	From     string
	To       string
	StartTLS bool
}

EmailConfig is a resolved (secrets already unsealed) SMTP target.

type Engine

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

Engine evaluates alert rules and delivers notifications (T-74).

func NewEngine

func NewEngine(cfg Config) *Engine

NewEngine builds the engine.

func (*Engine) Reset

func (e *Engine) Reset()

Reset clears per-term state and marks all existing events as already seen, so a freshly elected leader does not replay history as fresh alerts.

func (*Engine) Tick

func (e *Engine) Tick(ctx context.Context)

Tick performs one evaluation pass: metric rules (with sustained + dedupe) and event rules (new events since the last pass).

type MetricSource

type MetricSource interface {
	Value(metric, scope string) (value float64, ok bool)
}

MetricSource resolves the current value of a metric for a scope ("node:<id>" | "env:<id>" | "cluster"). ok is false when no data is available.

type Notification

type Notification struct {
	Rule     string    // rule name
	Firing   bool      // true = firing, false = resolved
	Severity string    // "info" | "warning" | "error"
	Scope    string    // "node:<id>" | "env:<id>" | "cluster" | event scope
	Summary  string    // human-readable one-liner
	At       time.Time // when the engine decided this

	// Metric rules only:
	Metric    string
	Value     float64
	Threshold float64
	Op        string

	// Event rules only:
	EventKind string
}

Notification is one alert delivery — a rule firing or resolving.

type Notifier

type Notifier interface {
	Send(ctx context.Context, n Notification) error
}

Notifier delivers a Notification to one channel type.

type Opener

type Opener interface {
	Open(*zatterav1.EncryptedValue) ([]byte, error)
}

Opener decrypts a channel's sealed secret values.

type Slack

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

Slack posts a notification to a Slack Incoming Webhook URL as a simple text message. The URL itself is the secret and is never echoed into the payload.

func NewSlack

func NewSlack(url string, client *http.Client) *Slack

NewSlack builds a Slack notifier over an incoming-webhook URL.

func (*Slack) Send

func (s *Slack) Send(ctx context.Context, n Notification) error

type Store

type Store interface {
	ListAlertRules() []*zatterav1.AlertRule
	ListNotificationChannels() []*zatterav1.NotificationChannel
	ListEvents(limit int) []*zatterav1.Event
}

Store is the read side the engine needs (the leader's replicated state).

type Telegram

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

Telegram delivers notifications via the Telegram Bot API sendMessage method. The bot token is the secret and is never echoed into the message body.

func NewTelegram

func NewTelegram(token, chatID string, client *http.Client) *Telegram

NewTelegram builds a Telegram notifier for a bot token + target chat id.

func (*Telegram) Send

func (t *Telegram) Send(ctx context.Context, n Notification) error

type Webhook

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

Webhook posts a JSON notification to a URL, optionally HMAC-signing the body. The payload never contains secret values.

func NewWebhook

func NewWebhook(url string, secret []byte, client *http.Client) *Webhook

NewWebhook builds a webhook notifier. secret may be nil (unsigned).

func (*Webhook) Send

func (w *Webhook) Send(ctx context.Context, n Notification) error

Jump to

Keyboard shortcuts

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