forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.go
63 lines (53 loc) · 1.38 KB
/
base.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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 := true
value, exist := model.CheckGet("uploadImage")
if exist {
uploadImage = value.MustBool()
}
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
}