mirror of
https://github.com/grafana/grafana.git
synced 2024-11-27 03:11:01 -06:00
5fb80498b1
* OK notifications using previous evaluation data * copy rule.EvalMatches to avoid changes to the underlying array * test cases added/modified * delete trailing newline * fix double newline in go import * add change to the changelog * specify that this only affects legacy alerting (changelog) * use current eval data instead of prev eval data * create evalMatch just once * code comments, renamings, getTemplateMatches() function * changelog and docs updated
66 lines
1.4 KiB
Go
66 lines
1.4 KiB
Go
package alerting
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/grafana/grafana/pkg/models"
|
|
"github.com/grafana/grafana/pkg/tsdb/legacydata"
|
|
)
|
|
|
|
type evalHandler interface {
|
|
Eval(evalContext *EvalContext)
|
|
}
|
|
|
|
type scheduler interface {
|
|
Tick(time time.Time, execQueue chan *Job)
|
|
Update(rules []*Rule)
|
|
}
|
|
|
|
// Notifier is responsible for sending alert notifications.
|
|
type Notifier interface {
|
|
Notify(evalContext *EvalContext) error
|
|
GetType() string
|
|
NeedsImage() bool
|
|
|
|
// ShouldNotify checks this evaluation should send an alert notification
|
|
ShouldNotify(ctx context.Context, evalContext *EvalContext, notificationState *models.AlertNotificationState) bool
|
|
|
|
GetNotifierUID() string
|
|
GetIsDefault() bool
|
|
GetSendReminder() bool
|
|
GetDisableResolveMessage() bool
|
|
GetFrequency() time.Duration
|
|
}
|
|
|
|
type notifierState struct {
|
|
notifier Notifier
|
|
state *models.AlertNotificationState
|
|
}
|
|
|
|
type notifierStateSlice []*notifierState
|
|
|
|
func (notifiers notifierStateSlice) ShouldUploadImage() bool {
|
|
for _, ns := range notifiers {
|
|
if ns.notifier.NeedsImage() {
|
|
return true
|
|
}
|
|
}
|
|
|
|
return false
|
|
}
|
|
|
|
// ConditionResult is the result of a condition evaluation.
|
|
type ConditionResult struct {
|
|
Firing bool
|
|
NoDataFound bool
|
|
Operator string
|
|
EvalMatches []*EvalMatch
|
|
AllMatches []*EvalMatch
|
|
}
|
|
|
|
// Condition is responsible for evaluating an alert condition.
|
|
type Condition interface {
|
|
Eval(result *EvalContext, requestHandler legacydata.RequestHandler) (*ConditionResult, error)
|
|
}
|