alert

package
v0.15.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package alert is Mooring's read-and-notify alert engine (plan §8): ONE evaluator that reads the poller's snapshot (zero network I/O, zero docker writes, side-effect-free) and drives a per-(rule,target) state machine, and a SEPARATE rate-limited notifier that drains an outbox. It defers to an app that already alerts — with a down-only safety net so a dark app still pages on liveness.

Index

Constants

View Source
const (
	LevelWarning  = "warning"
	LevelCritical = "critical"
)

Levels.

View Source
const (
	KindContainerDown = "container_down"
	KindHostCPU       = "host_cpu"
	KindHostMem       = "host_mem"
	KindHostDisk      = "host_disk"
	KindDepDown       = "dep_down"
	KindRestartStorm  = "restart_storm"
)

Kinds (the read-detectable v1 set; the §8.4 infra taxonomy extends this engine).

Variables

This section is empty.

Functions

func Evaluate

func Evaluate(now int64, rules []Rule, snap *monitor.Snapshot, prior []State) ([]State, []Outbox)

Evaluate runs every enabled rule against the snapshot and the prior state, returning the new states and any outbox notifications to enqueue. It is PURE (no I/O); the caller persists + signals the notifier. now is unix seconds.

func SortStates

func SortStates(s []State)

SortStates orders states deterministically (rule, then target).

func ValidChannelKind

func ValidChannelKind(kind string) bool

ValidChannelKind reports whether kind is supported.

func ValidKind

func ValidKind(kind string) bool

ValidKind reports whether kind is known.

Types

type Channel

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

Channel delivers a Notification. Implementations use std-lib only.

func BuildChannel

func BuildChannel(kind string, configJSON []byte) (Channel, error)

BuildChannel constructs a channel from its kind + decrypted JSON config.

type Notification

type Notification struct {
	Title string
	Body  string
	Level string
}

Notification is the rendered alert handed to a channel. Title/Body are plain-text with minimal markdown — there is no template engine (plan §8: never one that could execute code).

type Outbox

type Outbox struct {
	RuleID     int64
	Target     string
	Kind       string
	Level      string
	Transition string // firing | resolved
	Summary    string
	DedupeKey  string
}

Outbox is one notification handoff the evaluator appends (it never sends).

type Phase

type Phase string

Phase is the per-(rule,target) state-machine phase.

const (
	PhaseOK       Phase = "ok"
	PhasePending  Phase = "pending"  // condition true, sustain window not yet elapsed
	PhaseFiring   Phase = "firing"   // sustained → alert is open
	PhaseResolved Phase = "resolved" // condition cleared, clear window not yet elapsed
)

type Rule

type Rule struct {
	ID                   int64
	Name                 string
	Kind                 string
	Scope                string // "" = all apps; else a project slug
	Threshold            float64
	ForSeconds           int
	Level                string
	DeferWhenSelfManaged bool
	ChannelID            int64 // 0 = all enabled channels
	Enabled              bool
}

Rule is one alert rule (operator-defined).

type State

type State struct {
	RuleID        int64
	Target        string
	Phase         Phase
	Since         int64
	Level         string
	Detail        string
	Acked         bool
	SilencedUntil int64
}

State is the persisted per-(rule,target) state.

Jump to

Keyboard shortcuts

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