2016-06-06 11:56:58 +02:00
|
|
|
package alerting
|
|
|
|
|
|
2018-06-29 15:15:31 +02:00
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"time"
|
2018-09-27 14:32:54 +02:00
|
|
|
|
2023-01-23 08:19:25 -05:00
|
|
|
"github.com/grafana/grafana/pkg/services/alerting/models"
|
2021-11-10 11:52:16 +01:00
|
|
|
"github.com/grafana/grafana/pkg/tsdb/legacydata"
|
2018-06-29 15:15:31 +02:00
|
|
|
)
|
2016-06-06 11:56:58 +02:00
|
|
|
|
2019-05-20 12:13:32 +02:00
|
|
|
type evalHandler interface {
|
2016-10-03 09:38:03 +02:00
|
|
|
Eval(evalContext *EvalContext)
|
2016-06-06 11:56:58 +02:00
|
|
|
}
|
|
|
|
|
|
2019-05-20 12:13:32 +02:00
|
|
|
type scheduler interface {
|
2016-07-27 16:29:28 +02:00
|
|
|
Tick(time time.Time, execQueue chan *Job)
|
|
|
|
|
Update(rules []*Rule)
|
2016-06-06 11:56:58 +02:00
|
|
|
}
|
2016-06-15 09:19:22 +02:00
|
|
|
|
2019-05-20 12:13:32 +02:00
|
|
|
// Notifier is responsible for sending alert notifications.
|
2016-06-15 09:19:22 +02:00
|
|
|
type Notifier interface {
|
2016-10-03 09:38:03 +02:00
|
|
|
Notify(evalContext *EvalContext) error
|
2016-07-25 13:52:17 +02:00
|
|
|
GetType() string
|
2016-07-29 14:55:02 +02:00
|
|
|
NeedsImage() bool
|
2018-06-05 12:07:02 +02:00
|
|
|
|
|
|
|
|
// ShouldNotify checks this evaluation should send an alert notification
|
2018-09-27 14:32:54 +02:00
|
|
|
ShouldNotify(ctx context.Context, evalContext *EvalContext, notificationState *models.AlertNotificationState) bool
|
2016-10-11 10:13:19 +02:00
|
|
|
|
2019-06-03 10:25:58 +02:00
|
|
|
GetNotifierUID() string
|
2016-10-11 10:13:19 +02:00
|
|
|
GetIsDefault() bool
|
2018-06-05 10:27:29 +02:00
|
|
|
GetSendReminder() bool
|
2018-10-17 10:41:18 +02:00
|
|
|
GetDisableResolveMessage() bool
|
2018-05-19 16:21:00 -04:00
|
|
|
GetFrequency() time.Duration
|
2016-06-15 09:19:22 +02:00
|
|
|
}
|
2016-07-19 17:45:37 +02:00
|
|
|
|
2018-10-02 14:03:30 +02:00
|
|
|
type notifierState struct {
|
2018-09-27 14:32:54 +02:00
|
|
|
notifier Notifier
|
|
|
|
|
state *models.AlertNotificationState
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 14:03:30 +02:00
|
|
|
type notifierStateSlice []*notifierState
|
2017-02-13 12:43:12 +01:00
|
|
|
|
2018-10-02 14:03:30 +02:00
|
|
|
func (notifiers notifierStateSlice) ShouldUploadImage() bool {
|
2018-09-27 14:32:54 +02:00
|
|
|
for _, ns := range notifiers {
|
|
|
|
|
if ns.notifier.NeedsImage() {
|
2017-02-13 12:43:12 +01:00
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
2019-05-20 12:13:32 +02:00
|
|
|
// ConditionResult is the result of a condition evaluation.
|
2016-11-03 15:26:17 +01:00
|
|
|
type ConditionResult struct {
|
|
|
|
|
Firing bool
|
|
|
|
|
NoDataFound bool
|
2016-11-15 06:35:25 -08:00
|
|
|
Operator string
|
2016-11-03 15:26:17 +01:00
|
|
|
EvalMatches []*EvalMatch
|
2022-04-13 17:04:10 -03:00
|
|
|
AllMatches []*EvalMatch
|
2016-11-03 15:26:17 +01:00
|
|
|
}
|
|
|
|
|
|
2019-05-20 12:13:32 +02:00
|
|
|
// Condition is responsible for evaluating an alert condition.
|
2016-07-27 16:29:28 +02:00
|
|
|
type Condition interface {
|
2021-11-10 11:52:16 +01:00
|
|
|
Eval(result *EvalContext, requestHandler legacydata.RequestHandler) (*ConditionResult, error)
|
2016-07-19 17:45:37 +02:00
|
|
|
}
|