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