alert

package
v0.21.7 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2022 License: MIT Imports: 6 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Alert

type Alert struct {
	Builder *sdk.Alert

	// For internal use only
	Datasource   string
	DashboardUID string
	PanelID      string
}

Alert represents an alert that can be triggered by a query.

func New

func New(name string, options ...Option) *Alert

New creates a new alert.

func (*Alert) HookDashboardUID added in v0.21.0

func (alert *Alert) HookDashboardUID(uid string)

func (*Alert) HookDatasourceUID added in v0.21.0

func (alert *Alert) HookDatasourceUID(uid string)

func (*Alert) HookPanelID added in v0.21.0

func (alert *Alert) HookPanelID(id string)

type Channel

type Channel struct {
	ID   uint   `json:"id"`
	UID  string `json:"uid"`
	Name string `json:"Name"`
	Type string `json:"type"`
}

Channel represents an alert notification channel. See https://grafana.com/docs/grafana/latest/alerting/notifications/#notification-channel-setup

type ConditionEvaluator added in v0.21.0

type ConditionEvaluator func(condition *condition)

ConditionEvaluator represents an option that can be used to configure a condition.

func HasNoValue

func HasNoValue() ConditionEvaluator

HasNoValue will match queries returning no value.

func IsAbove

func IsAbove(value float64) ConditionEvaluator

IsAbove will match queries returning a value above the given threshold.

func IsBelow

func IsBelow(value float64) ConditionEvaluator

IsBelow will match queries returning a value below the given threshold.

func IsOutsideRange

func IsOutsideRange(min float64, max float64) ConditionEvaluator

IsOutsideRange will match queries returning a value outside the given range.

func IsWithinRange

func IsWithinRange(min float64, max float64) ConditionEvaluator

IsWithinRange will match queries returning a value within the given range.

type ErrorMode

type ErrorMode string

ErrorMode represents the behavior of an alert in case of execution error.

const ErrorAlerting ErrorMode = "Alerting"

Alerting will set the alert state to "alerting".

const ErrorKO ErrorMode = "Error"

LastState will set the alert state to its previous state.

const ErrorOK ErrorMode = "OK"

LastState will set the alert state to its previous state.

type NoDataMode

type NoDataMode string

NoDataMode represents the behavior of an alert when no data is returned by the query.

const NoDataAlerting NoDataMode = "Alerting"

Error will set the alert state to "alerting".

const NoDataEmpty NoDataMode = "NoData"

NoData will set the alert state to "no data".

const NoDataOK NoDataMode = "OK"

OK will set the alert state to "ok".

type Operator

type Operator string

Operator represents a logical operator used to chain conditions.

const And Operator = "and"

And chains conditions with a logical AND

const Or Operator = "or"

Or chains conditions with a logical OR

type Option

type Option func(alert *Alert)

Option represents an option that can be used to configure an alert.

func Description added in v0.21.0

func Description(content string) Option

Description sets the description associated to the alert.

func EvaluateEvery

func EvaluateEvery(interval string) Option

EvaluateEvery defines the evaluation interval.

func For

func For(duration string) Option

For sets the time interval during which a query violating the threshold before the alert being actually triggered. See https://grafana.com/docs/grafana/latest/alerting/rules/#for

func If

func If(reducer QueryReducer, queryRef string, evaluator ConditionEvaluator) Option

If defines a single condition that will trigger the alert. See https://grafana.com/docs/grafana/latest/alerting/rules/#conditions

func IfOr added in v0.21.0

func IfOr(reducer QueryReducer, queryRef string, evaluator ConditionEvaluator) Option

IfOr defines a single condition that will trigger the alert. See https://grafana.com/docs/grafana/latest/alerting/rules/#conditions

func OnExecutionError

func OnExecutionError(mode ErrorMode) Option

OnExecutionError defines the behavior on execution error. See https://grafana.com/docs/grafana/latest/alerting/rules/#execution-errors-or-timeouts

func OnNoData

func OnNoData(mode NoDataMode) Option

OnNoData defines the behavior when the query returns no data. See https://grafana.com/docs/grafana/latest/alerting/rules/#no-data-null-values

func Runbook added in v0.21.0

func Runbook(url string) Option

Runbook sets the runbook URL associated to the alert.

func Summary added in v0.21.0

func Summary(content string) Option

Summary sets the summary associated to the alert.

func Tags added in v0.12.6

func Tags(tags map[string]string) Option

Tags defines a set of tags that will be forwarded to the notifications channels when the alert will tbe triggered or used to route the alert.

func WithGraphiteQuery added in v0.21.0

func WithGraphiteQuery(ref string, query string, options ...graphite.Option) Option

WithGraphiteQuery adds a graphite query to the alert.

func WithInfluxDBQuery added in v0.21.0

func WithInfluxDBQuery(ref string, query string, options ...influxdb.Option) Option

WithInfluxDBQuery adds an InfluxDB query to the alert.

func WithLokiQuery added in v0.21.0

func WithLokiQuery(ref string, query string, options ...loki.Option) Option

WithLokiQuery adds a loki query to the alert.

func WithPrometheusQuery added in v0.21.0

func WithPrometheusQuery(ref string, query string, options ...prometheus.Option) Option

WithPrometheusQuery adds a prometheus query to the alert.

func WithStackdriverQuery added in v0.21.0

func WithStackdriverQuery(query *stackdriver.Stackdriver) Option

WithStackdriverQuery adds a Stackdriver query to the alert.

type QueryReducer added in v0.21.0

type QueryReducer string

QueryReducer represents a function used to reduce a query to a single value that can then be fed to the evaluator to determine if the alert will be triggered or not.

const (
	// Avg defines the query to execute and computes the average of the results.
	// See https://grafana.com/docs/grafana/latest/alerting/rules/#query-condition-example
	Avg QueryReducer = "avg"

	// Sum defines the query to execute and computes the sum of the results.
	// See https://grafana.com/docs/grafana/latest/alerting/rules/#query-condition-example
	Sum QueryReducer = "sum"

	// Count defines the query to execute and counts the results.
	// See https://grafana.com/docs/grafana/latest/alerting/rules/#query-condition-example
	Count QueryReducer = "count"

	// Last defines the query to execute and takes the last result.
	// See https://grafana.com/docs/grafana/latest/alerting/rules/#query-condition-example
	Last QueryReducer = "last"

	// Min defines the query to execute and takes the smallest result.
	// See https://grafana.com/docs/grafana/latest/alerting/rules/#query-condition-example
	Min QueryReducer = "min"

	// Max defines the query to execute and takes the largest result.
	// See https://grafana.com/docs/grafana/latest/alerting/rules/#query-condition-example
	Max QueryReducer = "max"

	// Median defines the query to execute and computes the mediam of the results.
	// See https://grafana.com/docs/grafana/latest/alerting/rules/#query-condition-example
	Median QueryReducer = "median"

	// Diff defines the query to execute.
	// See https://grafana.com/docs/grafana/latest/alerting/rules/#query-condition-example
	Diff QueryReducer = "diff"

	// PercentDiff defines the query to execute.
	// See https://grafana.com/docs/grafana/latest/alerting/rules/#query-condition-example
	PercentDiff QueryReducer = "percent_diff"
)

Directories

Path Synopsis
queries

Jump to

Keyboard shortcuts

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