alerts

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AlertCallback

type AlertCallback func(event model.AlertEvent, isResolved bool)

AlertCallback is a function invoked when an alert fires or resolves.

type AlertState

type AlertState struct {
	RuleID           string
	FirstTriggeredAt time.Time
	LastFiredAt      time.Time
	SilencedUntil    time.Time
	IsActive         bool
	CurrentEvent     *model.AlertEvent
}

AlertState maintains the temporal lifecycle for a single alert rule.

type BuiltinRulesEvaluator

type BuiltinRulesEvaluator struct{}

BuiltinRulesEvaluator evaluates standard thresholds configured in config.AlertsConfig.

func (*BuiltinRulesEvaluator) Evaluate

func (b *BuiltinRulesEvaluator) Evaluate(snapshot *model.SystemSnapshot, cfg *config.Config) []EvaluatedAlert

Evaluate checks CPU, Memory, Disk, Process, and Network thresholds.

type CustomRuleEvaluator

type CustomRuleEvaluator struct {
	Rules []model.AlertRule
}

CustomRuleEvaluator evaluates user-defined AlertRules.

func (*CustomRuleEvaluator) Evaluate

func (c *CustomRuleEvaluator) Evaluate(snapshot *model.SystemSnapshot, cfg *config.Config) []EvaluatedAlert

Evaluate checks user-defined AlertRules against the snapshot.

type Engine

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

Engine orchestrates alert evaluation, cooldown state, storage persistence, and notifications.

func NewEngine

func NewEngine(cfg *config.Config, store storage.Storage) *Engine

NewEngine creates a new alert engine.

func (*Engine) AddCallback

func (e *Engine) AddCallback(cb AlertCallback)

AddCallback registers a listener for alert events.

func (*Engine) Evaluate

func (e *Engine) Evaluate(ctx context.Context, snapshot *model.SystemSnapshot) ([]model.AlertEvent, []model.AlertEvent, error)

Evaluate runs all rule evaluations against the snapshot and processes cooldowns and resolutions.

func (*Engine) GetActiveAlerts

func (e *Engine) GetActiveAlerts() []model.AlertEvent

GetActiveAlerts returns currently firing alerts.

func (*Engine) RegisterRule

func (e *Engine) RegisterRule(rule model.AlertRule)

RegisterRule adds a custom user-defined AlertRule.

func (*Engine) Reset

func (e *Engine) Reset()

Reset clears all tracker states.

func (*Engine) Silence

func (e *Engine) Silence(ruleID string, dur time.Duration)

Silence mutes alerts for the specified rule for a duration.

type EvaluatedAlert

type EvaluatedAlert struct {
	RuleID      string
	RuleName    string
	MetricName  string
	Severity    model.Severity
	Triggered   bool
	ActualValue float64
	Threshold   float64
	Duration    time.Duration
	Cooldown    time.Duration
	Message     string
}

EvaluatedAlert represents the raw result of a rule evaluation before cooldown checks.

type RuleEvaluator

type RuleEvaluator interface {
	Evaluate(snapshot *model.SystemSnapshot, cfg *config.Config) []EvaluatedAlert
}

RuleEvaluator evaluates a specific metric or custom condition against a snapshot.

type StateTracker

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

StateTracker manages active alerts, cooldown periods, and resolution state.

func NewStateTracker

func NewStateTracker() *StateTracker

NewStateTracker creates an empty alert state tracker.

func (*StateTracker) GetActiveEvents

func (st *StateTracker) GetActiveEvents() []model.AlertEvent

GetActiveEvents returns all currently active alert events.

func (*StateTracker) ProcessEvaluation

func (st *StateTracker) ProcessEvaluation(eval EvaluatedAlert, now time.Time) (fired *model.AlertEvent, resolved *model.AlertEvent)

ProcessEvaluation updates the internal state for an evaluated rule and returns any fired or resolved events.

func (*StateTracker) Reset

func (st *StateTracker) Reset()

Reset clears all alert states.

func (*StateTracker) Silence

func (st *StateTracker) Silence(ruleID string, until time.Time)

Silence mutes alerts for a rule until the given expiration time.

Jump to

Keyboard shortcuts

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