Documentation ¶
Index ¶
- type Alert
- type Channel
- type ConditionEvaluator
- type ErrorMode
- type NoDataMode
- type Operator
- type Option
- func Description(content string) Option
- func EvaluateEvery(interval string) Option
- func For(duration string) Option
- func If(reducer QueryReducer, queryRef string, evaluator ConditionEvaluator) Option
- func IfOr(reducer QueryReducer, queryRef string, evaluator ConditionEvaluator) Option
- func OnExecutionError(mode ErrorMode) Option
- func OnNoData(mode NoDataMode) Option
- func Runbook(url string) Option
- func Summary(content string) Option
- func Tags(tags map[string]string) Option
- func WithGraphiteQuery(ref string, query string, options ...graphite.Option) Option
- func WithInfluxDBQuery(ref string, query string, options ...influxdb.Option) Option
- func WithLokiQuery(ref string, query string, options ...loki.Option) Option
- func WithPrometheusQuery(ref string, query string, options ...prometheus.Option) Option
- func WithStackdriverQuery(query *stackdriver.Stackdriver) Option
- type QueryReducer
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 (*Alert) HookDashboardUID ¶ added in v0.21.0
func (*Alert) HookDatasourceUID ¶ added in v0.21.0
func (*Alert) HookPanelID ¶ added in v0.21.0
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
Description sets the description associated to the alert.
func EvaluateEvery ¶
EvaluateEvery defines the evaluation interval.
func For ¶
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 ¶
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 Tags ¶ added in v0.12.6
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
WithGraphiteQuery adds a graphite query to the alert.
func WithInfluxDBQuery ¶ added in v0.21.0
WithInfluxDBQuery adds an InfluxDB query to the alert.
func WithLokiQuery ¶ added in v0.21.0
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" )