diff --git a/pkg/services/alerting/interfaces.go b/pkg/services/alerting/interfaces.go index 88c006f9e47..583e12a120d 100644 --- a/pkg/services/alerting/interfaces.go +++ b/pkg/services/alerting/interfaces.go @@ -16,6 +16,9 @@ type Notifier interface { GetType() string NeedsImage() bool PassesFilter(rule *Rule) bool + + GetNotifierId() int64 + GetIsDefault() bool } type Condition interface { diff --git a/pkg/services/alerting/notifier.go b/pkg/services/alerting/notifier.go index db84b20e041..7fdbc86d69d 100644 --- a/pkg/services/alerting/notifier.go +++ b/pkg/services/alerting/notifier.go @@ -35,14 +35,22 @@ func (n *RootNotifier) PassesFilter(rule *Rule) bool { return false } -func (n *RootNotifier) Notify(context *EvalContext) error { - n.log.Info("Sending notifications for", "ruleId", context.Rule.Id) +func (n *RootNotifier) GetNotifierId() int64 { + return 0 +} +func (n *RootNotifier) GetIsDefault() bool { + return false +} + +func (n *RootNotifier) Notify(context *EvalContext) error { notifiers, err := n.getNotifiers(context.Rule.OrgId, context.Rule.Notifications, context) if err != nil { return err } + n.log.Info("Sending notifications for", "ruleId", context.Rule.Id, "Amount to send", len(notifiers)) + if len(notifiers) == 0 { return nil } @@ -60,7 +68,7 @@ func (n *RootNotifier) sendNotifications(context *EvalContext, notifiers []Notif g, _ := errgroup.WithContext(context.Ctx) for _, notifier := range notifiers { - n.log.Info("Sending notification", "firing", context.Firing, "type", notifier.GetType()) + n.log.Info("Sending notification", "type", notifier.GetType(), "id", notifier.GetNotifierId(), "isDefault", notifier.GetIsDefault()) g.Go(func() error { return notifier.Notify(context) }) } diff --git a/pkg/services/alerting/notifier_test.go b/pkg/services/alerting/notifier_test.go index 5c79187078f..5e378dec890 100644 --- a/pkg/services/alerting/notifier_test.go +++ b/pkg/services/alerting/notifier_test.go @@ -22,6 +22,14 @@ func (fn *FakeNotifier) NeedsImage() bool { return true } +func (n *FakeNotifier) GetNotifierId() int64 { + return 0 +} + +func (n *FakeNotifier) GetIsDefault() bool { + return false +} + func (fn *FakeNotifier) Notify(alertResult *EvalContext) error { return nil } func (fn *FakeNotifier) PassesFilter(rule *Rule) bool { diff --git a/pkg/services/alerting/notifiers/base.go b/pkg/services/alerting/notifiers/base.go index 27c2a625d17..f1e748207d8 100644 --- a/pkg/services/alerting/notifiers/base.go +++ b/pkg/services/alerting/notifiers/base.go @@ -6,13 +6,19 @@ import ( ) type NotifierBase struct { - Name string - Type string + Name string + Type string + Id int64 + IsDeault bool } -func NewNotifierBase(name, notifierType string, model *simplejson.Json) NotifierBase { - base := NotifierBase{Name: name, Type: notifierType} - return base +func NewNotifierBase(id int64, isDefault bool, name, notifierType string, model *simplejson.Json) NotifierBase { + return NotifierBase{ + Id: id, + Name: name, + IsDeault: isDefault, + Type: notifierType, + } } func (n *NotifierBase) PassesFilter(rule *alerting.Rule) bool { @@ -26,3 +32,11 @@ func (n *NotifierBase) GetType() string { func (n *NotifierBase) NeedsImage() bool { return true } + +func (n *NotifierBase) GetNotifierId() int64 { + return n.Id +} + +func (n *NotifierBase) GetIsDefault() bool { + return n.IsDeault +} diff --git a/pkg/services/alerting/notifiers/email.go b/pkg/services/alerting/notifiers/email.go index d51383a7ddc..2b9dd4fd1b2 100644 --- a/pkg/services/alerting/notifiers/email.go +++ b/pkg/services/alerting/notifiers/email.go @@ -29,7 +29,7 @@ func NewEmailNotifier(model *m.AlertNotification) (alerting.Notifier, error) { } return &EmailNotifier{ - NotifierBase: NewNotifierBase(model.Name, model.Type, model.Settings), + NotifierBase: NewNotifierBase(model.Id, model.IsDefault, model.Name, model.Type, model.Settings), Addresses: strings.Split(addressesString, "\n"), log: log.New("alerting.notifier.email"), }, nil diff --git a/pkg/services/alerting/notifiers/slack.go b/pkg/services/alerting/notifiers/slack.go index b0f36631626..7238af179d7 100644 --- a/pkg/services/alerting/notifiers/slack.go +++ b/pkg/services/alerting/notifiers/slack.go @@ -23,7 +23,7 @@ func NewSlackNotifier(model *m.AlertNotification) (alerting.Notifier, error) { } return &SlackNotifier{ - NotifierBase: NewNotifierBase(model.Name, model.Type, model.Settings), + NotifierBase: NewNotifierBase(model.Id, model.IsDefault, model.Name, model.Type, model.Settings), Url: url, log: log.New("alerting.notifier.slack"), }, nil diff --git a/pkg/services/alerting/notifiers/webhook.go b/pkg/services/alerting/notifiers/webhook.go index 09134702549..979ce2e8a98 100644 --- a/pkg/services/alerting/notifiers/webhook.go +++ b/pkg/services/alerting/notifiers/webhook.go @@ -20,7 +20,7 @@ func NewWebHookNotifier(model *m.AlertNotification) (alerting.Notifier, error) { } return &WebhookNotifier{ - NotifierBase: NewNotifierBase(model.Name, model.Type, model.Settings), + NotifierBase: NewNotifierBase(model.Id, model.IsDefault, model.Name, model.Type, model.Settings), Url: url, User: model.Settings.Get("user").MustString(), Password: model.Settings.Get("password").MustString(),