mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
60 lines
1.3 KiB
Go
60 lines
1.3 KiB
Go
package notifiers
|
|
|
|
import (
|
|
"github.com/grafana/grafana/pkg/components/simplejson"
|
|
m "github.com/grafana/grafana/pkg/models"
|
|
"github.com/grafana/grafana/pkg/services/alerting"
|
|
)
|
|
|
|
type NotifierBase struct {
|
|
Name string
|
|
Type string
|
|
Id int64
|
|
IsDeault bool
|
|
UploadImage bool
|
|
}
|
|
|
|
func NewNotifierBase(id int64, isDefault bool, name, notifierType string, model *simplejson.Json) NotifierBase {
|
|
uploadImage := model.Get("uploadImage").MustBool(false)
|
|
|
|
return NotifierBase{
|
|
Id: id,
|
|
Name: name,
|
|
IsDeault: isDefault,
|
|
Type: notifierType,
|
|
UploadImage: uploadImage,
|
|
}
|
|
}
|
|
|
|
func defaultShouldNotify(context *alerting.EvalContext) bool {
|
|
// Only notify on state change.
|
|
if context.PrevAlertState == context.Rule.State {
|
|
return false
|
|
}
|
|
// Do not notify when we become OK for the first time.
|
|
if (context.PrevAlertState == m.AlertStatePending) && (context.Rule.State == m.AlertStateOK) {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
func (n *NotifierBase) ShouldNotify(context *alerting.EvalContext) bool {
|
|
return defaultShouldNotify(context)
|
|
}
|
|
|
|
func (n *NotifierBase) GetType() string {
|
|
return n.Type
|
|
}
|
|
|
|
func (n *NotifierBase) NeedsImage() bool {
|
|
return n.UploadImage
|
|
}
|
|
|
|
func (n *NotifierBase) GetNotifierId() int64 {
|
|
return n.Id
|
|
}
|
|
|
|
func (n *NotifierBase) GetIsDefault() bool {
|
|
return n.IsDeault
|
|
}
|