alerts

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2025 License: AGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AlertPayload

type AlertPayload struct {
	Labels       map[string]string `json:"labels"`
	Annotations  map[string]string `json:"annotations,omitempty"`
	StartsAt     time.Time         `json:"startsAt"`
	EndsAt       *time.Time        `json:"endsAt,omitempty"`
	GeneratorURL string            `json:"generatorURL,omitempty"`
}

AlertPayload represents the data sent to Alertmanager's /api/v2/alerts endpoint.

type AlertSender

type AlertSender interface {
	Send(ctx context.Context, alerts []AlertPayload) error
}

AlertSender abstracts the delivery mechanism for alert notifications.

type Client

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

Client sends alerts to an Alertmanager instance.

func NewAlertmanagerClient

func NewAlertmanagerClient(opts ClientOptions) (*Client, error)

NewAlertmanagerClient constructs a new Alertmanager client with sane defaults.

func (*Client) HealthCheck

func (c *Client) HealthCheck(ctx context.Context) error

HealthCheck verifies connectivity to the Alertmanager instance. It makes a GET request to the /api/v2/status endpoint to check if Alertmanager is reachable.

func (*Client) Send

func (c *Client) Send(ctx context.Context, alerts []AlertPayload) error

Send publishes the provided alerts to Alertmanager with retry logic.

type ClientOptions

type ClientOptions struct {
	BaseURL           string
	Timeout           time.Duration
	SkipTLSVerify     bool
	Logger            *slog.Logger
	AdditionalHeaders http.Header
	MaxRetries        int           // Maximum number of retry attempts (default: 2)
	RetryDelay        time.Duration // Initial retry delay (default: 500ms)
}

ClientOptions configures the Alertmanager client.

type Manager

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

Manager coordinates alert evaluation and dispatches notifications when thresholds are met.

func NewManager

func NewManager(opts Options) *Manager

NewManager constructs a new alert manager instance.

func (*Manager) ManualResolve

func (m *Manager) ManualResolve(ctx context.Context, alertID models.AlertID, message string) error

ManualResolve allows a user to manually resolve an active alert and notifies Alertmanager. This should be called when a user clicks "Resolve" in the UI.

func (*Manager) Start

func (m *Manager) Start(ctx context.Context)

Start launches the evaluation loop. It is a no-op when alerting is disabled.

func (*Manager) Stop

func (m *Manager) Stop()

Stop signals the manager to stop evaluating alerts.

type Options

type Options struct {
	Config     config.AlertsConfig
	DB         *sqlite.DB
	ClickHouse *clickhouse.Manager
	Logger     *slog.Logger
	Sender     AlertSender
}

Options encapsulates the dependencies required to run the alerting manager.

Jump to

Keyboard shortcuts

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