notifier

package
v1.70.0 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2021 License: Apache-2.0 Imports: 18 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExecTemplate added in v1.50.2

func ExecTemplate(q QueryFn, annotations map[string]string, tpl AlertTplData) (map[string]string, error)

ExecTemplate executes the given template for given annotations map.

func InitTemplateFunc

func InitTemplateFunc(externalURL *url.URL)

InitTemplateFunc initiates template helper functions

func ValidateTemplates added in v1.35.0

func ValidateTemplates(annotations map[string]string) error

ValidateTemplates validate annotations for possible template error, uses empty data for template population

Types

type Alert

type Alert struct {
	// GroupID contains the ID of the parent rules group
	GroupID uint64
	// Name represents Alert name
	Name string
	// Labels is the list of label-value pairs attached to the Alert
	Labels map[string]string
	// Annotations is the list of annotations generated on Alert evaluation
	Annotations map[string]string
	// State represents the current state of the Alert
	State AlertState
	// Expr contains expression that was executed to generate the Alert
	Expr string
	// Start defines the moment of time when Alert has triggered
	Start time.Time
	// End defines the moment of time when Alert supposed to expire
	End time.Time
	// Value stores the value returned from evaluating expression from Expr field
	Value float64
	// ID is the unique identifer for the Alert
	ID uint64
	// Restored is true if Alert was restored after restart
	Restored bool
}

Alert the triggered alert TODO: Looks like alert name isn't unique

func (*Alert) ExecTemplate

func (a *Alert) ExecTemplate(q QueryFn, annotations map[string]string) (map[string]string, error)

ExecTemplate executes the Alert template for given map of annotations. Every alert could have a different datasource, so function requires a queryFunction as an argument.

type AlertManager

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

AlertManager represents integration provider with Prometheus alert manager https://github.com/prometheus/alertmanager

func NewAlertManager

func NewAlertManager(alertManagerURL, user, pass string, fn AlertURLGenerator, c *http.Client) *AlertManager

NewAlertManager is a constructor for AlertManager

func (AlertManager) Addr added in v1.65.0

func (am AlertManager) Addr() string

Addr returns address where alerts are sent.

func (*AlertManager) Send

func (am *AlertManager) Send(ctx context.Context, alerts []Alert) error

Send an alert or resolve message

type AlertState

type AlertState int

AlertState type indicates the Alert state

const (
	// StateInactive is the state of an alert that is neither firing nor pending.
	StateInactive AlertState = iota
	// StatePending is the state of an alert that has been active for less than
	// the configured threshold duration.
	StatePending
	// StateFiring is the state of an alert that has been active for longer than
	// the configured threshold duration.
	StateFiring
)

func (AlertState) String

func (as AlertState) String() string

String stringer for AlertState

type AlertTplData added in v1.50.2

type AlertTplData struct {
	Labels map[string]string
	Value  float64
	Expr   string
}

AlertTplData is used to execute templating

type AlertURLGenerator

type AlertURLGenerator func(Alert) string

AlertURLGenerator returns URL to single alert by given name

type Notifier

type Notifier interface {
	// Send sends the given list of alerts.
	// Returns an error if fails to send the alerts.
	// Must unblock if the given ctx is cancelled.
	Send(ctx context.Context, alerts []Alert) error
	// Addr returns address where alerts are sent.
	Addr() string
}

Notifier is a common interface for alert manager provider

func Init added in v1.37.4

func Init(gen AlertURLGenerator) ([]Notifier, error)

Init creates a Notifier object based on provided flags.

type QueryFn added in v1.50.0

type QueryFn func(query string) ([]datasource.Metric, error)

QueryFn is used to wrap a call to datasource into simple-to-use function for templating functions.

type Time

type Time int64

Time is the number of milliseconds since the epoch (1970-01-01 00:00 UTC) excluding leap seconds.

func TimeFromUnixNano

func TimeFromUnixNano(t int64) Time

TimeFromUnixNano returns the Time equivalent to the Unix Time t provided in nanoseconds.

func (Time) Time

func (t Time) Time() time.Time

Time returns the time.Time representation of t.

Jump to

Keyboard shortcuts

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