diff --git a/pkg/api/dtos/alerting.go b/pkg/api/dtos/alerting.go
index f8671978148..697d0a35a08 100644
--- a/pkg/api/dtos/alerting.go
+++ b/pkg/api/dtos/alerting.go
@@ -49,28 +49,28 @@ func formatShort(interval time.Duration) string {
func NewAlertNotification(notification *models.AlertNotification) *AlertNotification {
return &AlertNotification{
- Id: notification.Id,
- Name: notification.Name,
- Type: notification.Type,
- IsDefault: notification.IsDefault,
- Created: notification.Created,
- Updated: notification.Updated,
- Frequency: formatShort(notification.Frequency),
- NotifyOnce: notification.NotifyOnce,
- Settings: notification.Settings,
+ Id: notification.Id,
+ Name: notification.Name,
+ Type: notification.Type,
+ IsDefault: notification.IsDefault,
+ Created: notification.Created,
+ Updated: notification.Updated,
+ Frequency: formatShort(notification.Frequency),
+ SendReminder: notification.SendReminder,
+ Settings: notification.Settings,
}
}
type AlertNotification struct {
- Id int64 `json:"id"`
- Name string `json:"name"`
- Type string `json:"type"`
- IsDefault bool `json:"isDefault"`
- NotifyOnce bool `json:"notifyOnce"`
- Frequency string `json:"frequency"`
- Created time.Time `json:"created"`
- Updated time.Time `json:"updated"`
- Settings *simplejson.Json `json:"settings"`
+ Id int64 `json:"id"`
+ Name string `json:"name"`
+ Type string `json:"type"`
+ IsDefault bool `json:"isDefault"`
+ SendReminder bool `json:"sendReminder"`
+ Frequency string `json:"frequency"`
+ Created time.Time `json:"created"`
+ Updated time.Time `json:"updated"`
+ Settings *simplejson.Json `json:"settings"`
}
type AlertTestCommand struct {
@@ -100,11 +100,11 @@ type EvalMatch struct {
}
type NotificationTestCommand struct {
- Name string `json:"name"`
- Type string `json:"type"`
- NotifyOnce bool `json:"notifyOnce"`
- Frequency string `json:"frequency"`
- Settings *simplejson.Json `json:"settings"`
+ Name string `json:"name"`
+ Type string `json:"type"`
+ SendReminder bool `json:"sendReminder"`
+ Frequency string `json:"frequency"`
+ Settings *simplejson.Json `json:"settings"`
}
type PauseAlertCommand struct {
diff --git a/pkg/api/dtos/alerting_test.go b/pkg/api/dtos/alerting_test.go
index ea4c97fb4cc..bd0d9ff8feb 100644
--- a/pkg/api/dtos/alerting_test.go
+++ b/pkg/api/dtos/alerting_test.go
@@ -14,6 +14,7 @@ func TestFormatShort(t *testing.T) {
{interval: time.Duration(time.Hour + time.Minute), expected: "1h1m"},
{interval: time.Duration((time.Hour * 10) + time.Minute), expected: "10h1m"},
{interval: time.Duration((time.Hour * 10) + (time.Minute * 10) + time.Second), expected: "10h10m1s"},
+ {interval: time.Duration(time.Minute * 10), expected: "10m"},
}
for _, tc := range tcs {
diff --git a/pkg/models/alert_notifications.go b/pkg/models/alert_notifications.go
index ed6b8f372d1..c17124dd6ef 100644
--- a/pkg/models/alert_notifications.go
+++ b/pkg/models/alert_notifications.go
@@ -12,38 +12,38 @@ var (
)
type AlertNotification struct {
- Id int64 `json:"id"`
- OrgId int64 `json:"-"`
- Name string `json:"name"`
- Type string `json:"type"`
- NotifyOnce bool `json:"notifyOnce"`
- Frequency time.Duration `json:"frequency"`
- IsDefault bool `json:"isDefault"`
- Settings *simplejson.Json `json:"settings"`
- Created time.Time `json:"created"`
- Updated time.Time `json:"updated"`
+ Id int64 `json:"id"`
+ OrgId int64 `json:"-"`
+ Name string `json:"name"`
+ Type string `json:"type"`
+ SendReminder bool `json:"sendReminder"`
+ Frequency time.Duration `json:"frequency"`
+ IsDefault bool `json:"isDefault"`
+ Settings *simplejson.Json `json:"settings"`
+ Created time.Time `json:"created"`
+ Updated time.Time `json:"updated"`
}
type CreateAlertNotificationCommand struct {
- Name string `json:"name" binding:"Required"`
- Type string `json:"type" binding:"Required"`
- NotifyOnce bool `json:"notifyOnce"`
- Frequency string `json:"frequency"`
- IsDefault bool `json:"isDefault"`
- Settings *simplejson.Json `json:"settings"`
+ Name string `json:"name" binding:"Required"`
+ Type string `json:"type" binding:"Required"`
+ SendReminder bool `json:"sendReminder"`
+ Frequency string `json:"frequency"`
+ IsDefault bool `json:"isDefault"`
+ Settings *simplejson.Json `json:"settings"`
OrgId int64 `json:"-"`
Result *AlertNotification
}
type UpdateAlertNotificationCommand struct {
- Id int64 `json:"id" binding:"Required"`
- Name string `json:"name" binding:"Required"`
- Type string `json:"type" binding:"Required"`
- NotifyOnce bool `json:"notifyOnce"`
- Frequency string `json:"frequency"`
- IsDefault bool `json:"isDefault"`
- Settings *simplejson.Json `json:"settings" binding:"Required"`
+ Id int64 `json:"id" binding:"Required"`
+ Name string `json:"name" binding:"Required"`
+ Type string `json:"type" binding:"Required"`
+ SendReminder bool `json:"sendReminder"`
+ Frequency string `json:"frequency"`
+ IsDefault bool `json:"isDefault"`
+ Settings *simplejson.Json `json:"settings" binding:"Required"`
OrgId int64 `json:"-"`
Result *AlertNotification
diff --git a/pkg/services/alerting/interfaces.go b/pkg/services/alerting/interfaces.go
index 8842b35fba2..95fd4b5d04e 100644
--- a/pkg/services/alerting/interfaces.go
+++ b/pkg/services/alerting/interfaces.go
@@ -19,7 +19,7 @@ type Notifier interface {
GetNotifierId() int64
GetIsDefault() bool
- GetNotifyOnce() bool
+ GetSendReminder() bool
GetFrequency() time.Duration
}
diff --git a/pkg/services/alerting/notifiers/alertmanager.go b/pkg/services/alerting/notifiers/alertmanager.go
index 3eeb25986e0..42ffa9b2d6e 100644
--- a/pkg/services/alerting/notifiers/alertmanager.go
+++ b/pkg/services/alerting/notifiers/alertmanager.go
@@ -33,7 +33,7 @@ func NewAlertmanagerNotifier(model *m.AlertNotification) (alerting.Notifier, err
}
return &AlertmanagerNotifier{
- NotifierBase: NewNotifierBase(model.Id, model.IsDefault, model.Name, model.Type, model.NotifyOnce, model.Frequency, model.Settings),
+ NotifierBase: NewNotifierBase(model),
Url: url,
log: log.New("alerting.notifier.prometheus-alertmanager"),
}, nil
diff --git a/pkg/services/alerting/notifiers/base.go b/pkg/services/alerting/notifiers/base.go
index 7672d397491..1d0d904457f 100644
--- a/pkg/services/alerting/notifiers/base.go
+++ b/pkg/services/alerting/notifiers/base.go
@@ -3,54 +3,56 @@ package notifiers
import (
"time"
- "github.com/grafana/grafana/pkg/components/simplejson"
- m "github.com/grafana/grafana/pkg/models"
+ "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
- NotifyOnce bool
- Frequency time.Duration
+ Name string
+ Type string
+ Id int64
+ IsDeault bool
+ UploadImage bool
+ SendReminder bool
+ Frequency time.Duration
}
-func NewNotifierBase(id int64, isDefault bool, name, notifierType string, notifyOnce bool, frequency time.Duration, model *simplejson.Json) NotifierBase {
+func NewNotifierBase(model *models.AlertNotification) NotifierBase {
uploadImage := true
- value, exist := model.CheckGet("uploadImage")
+ value, exist := model.Settings.CheckGet("uploadImage")
if exist {
uploadImage = value.MustBool()
}
return NotifierBase{
- Id: id,
- Name: name,
- IsDeault: isDefault,
- Type: notifierType,
- UploadImage: uploadImage,
- NotifyOnce: notifyOnce,
- Frequency: frequency,
+ Id: model.Id,
+ Name: model.Name,
+ IsDeault: model.IsDefault,
+ Type: model.Type,
+ UploadImage: uploadImage,
+ SendReminder: model.SendReminder,
+ Frequency: model.Frequency,
}
}
-func defaultShouldNotify(context *alerting.EvalContext, notifyOnce bool, frequency time.Duration, lastNotify *time.Time) bool {
+func defaultShouldNotify(context *alerting.EvalContext, sendReminder bool, frequency time.Duration, lastNotify *time.Time) bool {
// Only notify on state change.
- if context.PrevAlertState == context.Rule.State && notifyOnce {
+ if context.PrevAlertState == context.Rule.State && !sendReminder {
return false
}
+
// Do not notify if interval has not elapsed
- if !notifyOnce && lastNotify != nil && lastNotify.Add(frequency).After(time.Now()) {
+ if sendReminder && lastNotify != nil && lastNotify.Add(frequency).After(time.Now()) {
return false
}
+
// Do not notify if alert state if OK or pending even on repeated notify
- if !notifyOnce && (context.Rule.State == m.AlertStateOK || context.Rule.State == m.AlertStatePending) {
+ if sendReminder && (context.Rule.State == models.AlertStateOK || context.Rule.State == models.AlertStatePending) {
return false
}
+
// Do not notify when we become OK for the first time.
- if (context.PrevAlertState == m.AlertStatePending) && (context.Rule.State == m.AlertStateOK) {
+ if (context.PrevAlertState == models.AlertStatePending) && (context.Rule.State == models.AlertStateOK) {
return false
}
return true
@@ -58,7 +60,7 @@ func defaultShouldNotify(context *alerting.EvalContext, notifyOnce bool, frequen
func (n *NotifierBase) ShouldNotify(context *alerting.EvalContext) bool {
lastNotify := context.LastNotify(n.Id)
- return defaultShouldNotify(context, n.NotifyOnce, n.Frequency, lastNotify)
+ return defaultShouldNotify(context, n.SendReminder, n.Frequency, lastNotify)
}
func (n *NotifierBase) GetType() string {
@@ -77,8 +79,8 @@ func (n *NotifierBase) GetIsDefault() bool {
return n.IsDeault
}
-func (n *NotifierBase) GetNotifyOnce() bool {
- return n.NotifyOnce
+func (n *NotifierBase) GetSendReminder() bool {
+ return n.SendReminder
}
func (n *NotifierBase) GetFrequency() time.Duration {
diff --git a/pkg/services/alerting/notifiers/base_test.go b/pkg/services/alerting/notifiers/base_test.go
index 5f2d4989063..28e2ff9f024 100644
--- a/pkg/services/alerting/notifiers/base_test.go
+++ b/pkg/services/alerting/notifiers/base_test.go
@@ -16,22 +16,29 @@ func TestBaseNotifier(t *testing.T) {
Convey("default constructor for notifiers", func() {
bJson := simplejson.New()
+ model := &m.AlertNotification{
+ Id: 1,
+ Name: "name",
+ Type: "email",
+ Settings: bJson,
+ }
+
Convey("can parse false value", func() {
bJson.Set("uploadImage", false)
- base := NewNotifierBase(1, false, "name", "email", true, 0, bJson)
+ base := NewNotifierBase(model)
So(base.UploadImage, ShouldBeFalse)
})
Convey("can parse true value", func() {
bJson.Set("uploadImage", true)
- base := NewNotifierBase(1, false, "name", "email", true, 0, bJson)
+ base := NewNotifierBase(model)
So(base.UploadImage, ShouldBeTrue)
})
Convey("default value should be true for backwards compatibility", func() {
- base := NewNotifierBase(1, false, "name", "email", true, 0, bJson)
+ base := NewNotifierBase(model)
So(base.UploadImage, ShouldBeTrue)
})
})
diff --git a/pkg/services/alerting/notifiers/dingding.go b/pkg/services/alerting/notifiers/dingding.go
index 78446c56f88..738e43af2d2 100644
--- a/pkg/services/alerting/notifiers/dingding.go
+++ b/pkg/services/alerting/notifiers/dingding.go
@@ -32,7 +32,7 @@ func NewDingDingNotifier(model *m.AlertNotification) (alerting.Notifier, error)
}
return &DingDingNotifier{
- NotifierBase: NewNotifierBase(model.Id, model.IsDefault, model.Name, model.Type, model.NotifyOnce, model.Frequency, model.Settings),
+ NotifierBase: NewNotifierBase(model),
Url: url,
log: log.New("alerting.notifier.dingding"),
}, nil
diff --git a/pkg/services/alerting/notifiers/discord.go b/pkg/services/alerting/notifiers/discord.go
index 693ed31e206..57d9d438fa2 100644
--- a/pkg/services/alerting/notifiers/discord.go
+++ b/pkg/services/alerting/notifiers/discord.go
@@ -39,7 +39,7 @@ func NewDiscordNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
}
return &DiscordNotifier{
- NotifierBase: NewNotifierBase(model.Id, model.IsDefault, model.Name, model.Type, model.NotifyOnce, model.Frequency, model.Settings),
+ NotifierBase: NewNotifierBase(model),
WebhookURL: url,
log: log.New("alerting.notifier.discord"),
}, nil
diff --git a/pkg/services/alerting/notifiers/email.go b/pkg/services/alerting/notifiers/email.go
index 234a4f8e756..17b88f7d97f 100644
--- a/pkg/services/alerting/notifiers/email.go
+++ b/pkg/services/alerting/notifiers/email.go
@@ -52,7 +52,7 @@ func NewEmailNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
})
return &EmailNotifier{
- NotifierBase: NewNotifierBase(model.Id, model.IsDefault, model.Name, model.Type, model.NotifyOnce, model.Frequency, model.Settings),
+ NotifierBase: NewNotifierBase(model),
Addresses: addresses,
log: log.New("alerting.notifier.email"),
}, nil
diff --git a/pkg/services/alerting/notifiers/hipchat.go b/pkg/services/alerting/notifiers/hipchat.go
index 4eb5b78811e..1c284ec3d2b 100644
--- a/pkg/services/alerting/notifiers/hipchat.go
+++ b/pkg/services/alerting/notifiers/hipchat.go
@@ -59,7 +59,7 @@ func NewHipChatNotifier(model *models.AlertNotification) (alerting.Notifier, err
roomId := model.Settings.Get("roomid").MustString()
return &HipChatNotifier{
- NotifierBase: NewNotifierBase(model.Id, model.IsDefault, model.Name, model.Type, model.NotifyOnce, model.Frequency, model.Settings),
+ NotifierBase: NewNotifierBase(model),
Url: url,
ApiKey: apikey,
RoomId: roomId,
diff --git a/pkg/services/alerting/notifiers/kafka.go b/pkg/services/alerting/notifiers/kafka.go
index 0dab556d5e1..d8d19fc5dae 100644
--- a/pkg/services/alerting/notifiers/kafka.go
+++ b/pkg/services/alerting/notifiers/kafka.go
@@ -43,7 +43,7 @@ func NewKafkaNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
}
return &KafkaNotifier{
- NotifierBase: NewNotifierBase(model.Id, model.IsDefault, model.Name, model.Type, model.NotifyOnce, model.Frequency, model.Settings),
+ NotifierBase: NewNotifierBase(model),
Endpoint: endpoint,
Topic: topic,
log: log.New("alerting.notifier.kafka"),
diff --git a/pkg/services/alerting/notifiers/line.go b/pkg/services/alerting/notifiers/line.go
index 0ee252e6447..9e3888b8f95 100644
--- a/pkg/services/alerting/notifiers/line.go
+++ b/pkg/services/alerting/notifiers/line.go
@@ -39,7 +39,7 @@ func NewLINENotifier(model *m.AlertNotification) (alerting.Notifier, error) {
}
return &LineNotifier{
- NotifierBase: NewNotifierBase(model.Id, model.IsDefault, model.Name, model.Type, model.NotifyOnce, model.Frequency, model.Settings),
+ NotifierBase: NewNotifierBase(model),
Token: token,
log: log.New("alerting.notifier.line"),
}, nil
diff --git a/pkg/services/alerting/notifiers/opsgenie.go b/pkg/services/alerting/notifiers/opsgenie.go
index 991afd5ce9b..84148a0d99c 100644
--- a/pkg/services/alerting/notifiers/opsgenie.go
+++ b/pkg/services/alerting/notifiers/opsgenie.go
@@ -56,7 +56,7 @@ func NewOpsGenieNotifier(model *m.AlertNotification) (alerting.Notifier, error)
}
return &OpsGenieNotifier{
- NotifierBase: NewNotifierBase(model.Id, model.IsDefault, model.Name, model.Type, model.NotifyOnce, model.Frequency, model.Settings),
+ NotifierBase: NewNotifierBase(model),
ApiKey: apiKey,
ApiUrl: apiUrl,
AutoClose: autoClose,
diff --git a/pkg/services/alerting/notifiers/pagerduty.go b/pkg/services/alerting/notifiers/pagerduty.go
index afa0ba63eca..bf85466388f 100644
--- a/pkg/services/alerting/notifiers/pagerduty.go
+++ b/pkg/services/alerting/notifiers/pagerduty.go
@@ -51,7 +51,7 @@ func NewPagerdutyNotifier(model *m.AlertNotification) (alerting.Notifier, error)
}
return &PagerdutyNotifier{
- NotifierBase: NewNotifierBase(model.Id, model.IsDefault, model.Name, model.Type, model.NotifyOnce, model.Frequency, model.Settings),
+ NotifierBase: NewNotifierBase(model),
Key: key,
AutoResolve: autoResolve,
log: log.New("alerting.notifier.pagerduty"),
diff --git a/pkg/services/alerting/notifiers/pushover.go b/pkg/services/alerting/notifiers/pushover.go
index 09dfd6f0f9b..55dc02c5f4a 100644
--- a/pkg/services/alerting/notifiers/pushover.go
+++ b/pkg/services/alerting/notifiers/pushover.go
@@ -99,7 +99,7 @@ func NewPushoverNotifier(model *m.AlertNotification) (alerting.Notifier, error)
return nil, alerting.ValidationError{Reason: "API token not given"}
}
return &PushoverNotifier{
- NotifierBase: NewNotifierBase(model.Id, model.IsDefault, model.Name, model.Type, model.NotifyOnce, model.Frequency, model.Settings),
+ NotifierBase: NewNotifierBase(model),
UserKey: userKey,
ApiToken: apiToken,
Priority: priority,
diff --git a/pkg/services/alerting/notifiers/sensu.go b/pkg/services/alerting/notifiers/sensu.go
index e6b94d3223e..21d5d3d9d9e 100644
--- a/pkg/services/alerting/notifiers/sensu.go
+++ b/pkg/services/alerting/notifiers/sensu.go
@@ -51,7 +51,7 @@ func NewSensuNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
}
return &SensuNotifier{
- NotifierBase: NewNotifierBase(model.Id, model.IsDefault, model.Name, model.Type, model.NotifyOnce, model.Frequency, model.Settings),
+ NotifierBase: NewNotifierBase(model),
Url: url,
User: model.Settings.Get("username").MustString(),
Source: model.Settings.Get("source").MustString(),
diff --git a/pkg/services/alerting/notifiers/slack.go b/pkg/services/alerting/notifiers/slack.go
index fbbe4b3e59d..93c9a0accc0 100644
--- a/pkg/services/alerting/notifiers/slack.go
+++ b/pkg/services/alerting/notifiers/slack.go
@@ -78,7 +78,7 @@ func NewSlackNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
uploadImage := model.Settings.Get("uploadImage").MustBool(true)
return &SlackNotifier{
- NotifierBase: NewNotifierBase(model.Id, model.IsDefault, model.Name, model.Type, model.NotifyOnce, model.Frequency, model.Settings),
+ NotifierBase: NewNotifierBase(model),
Url: url,
Recipient: recipient,
Mention: mention,
diff --git a/pkg/services/alerting/notifiers/teams.go b/pkg/services/alerting/notifiers/teams.go
index 362a367e1f2..58dd4b22bb7 100644
--- a/pkg/services/alerting/notifiers/teams.go
+++ b/pkg/services/alerting/notifiers/teams.go
@@ -33,7 +33,7 @@ func NewTeamsNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
}
return &TeamsNotifier{
- NotifierBase: NewNotifierBase(model.Id, model.IsDefault, model.Name, model.Type, model.NotifyOnce, model.Frequency, model.Settings),
+ NotifierBase: NewNotifierBase(model),
Url: url,
log: log.New("alerting.notifier.teams"),
}, nil
diff --git a/pkg/services/alerting/notifiers/telegram.go b/pkg/services/alerting/notifiers/telegram.go
index 97696b2290c..b03f7ca38c5 100644
--- a/pkg/services/alerting/notifiers/telegram.go
+++ b/pkg/services/alerting/notifiers/telegram.go
@@ -78,7 +78,7 @@ func NewTelegramNotifier(model *m.AlertNotification) (alerting.Notifier, error)
}
return &TelegramNotifier{
- NotifierBase: NewNotifierBase(model.Id, model.IsDefault, model.Name, model.Type, model.NotifyOnce, model.Frequency, model.Settings),
+ NotifierBase: NewNotifierBase(model),
BotToken: botToken,
ChatID: chatId,
UploadImage: uploadImage,
diff --git a/pkg/services/alerting/notifiers/threema.go b/pkg/services/alerting/notifiers/threema.go
index e7fb39f27db..28a62fade17 100644
--- a/pkg/services/alerting/notifiers/threema.go
+++ b/pkg/services/alerting/notifiers/threema.go
@@ -106,7 +106,7 @@ func NewThreemaNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
}
return &ThreemaNotifier{
- NotifierBase: NewNotifierBase(model.Id, model.IsDefault, model.Name, model.Type, model.NotifyOnce, model.Frequency, model.Settings),
+ NotifierBase: NewNotifierBase(model),
GatewayID: gatewayID,
RecipientID: recipientID,
APISecret: apiSecret,
diff --git a/pkg/services/alerting/notifiers/victorops.go b/pkg/services/alerting/notifiers/victorops.go
index c6c1cf76047..3093aec9957 100644
--- a/pkg/services/alerting/notifiers/victorops.go
+++ b/pkg/services/alerting/notifiers/victorops.go
@@ -51,7 +51,7 @@ func NewVictoropsNotifier(model *models.AlertNotification) (alerting.Notifier, e
}
return &VictoropsNotifier{
- NotifierBase: NewNotifierBase(model.Id, model.IsDefault, model.Name, model.Type, model.NotifyOnce, model.Frequency, model.Settings),
+ NotifierBase: NewNotifierBase(model),
URL: url,
AutoResolve: autoResolve,
log: log.New("alerting.notifier.victorops"),
diff --git a/pkg/services/alerting/notifiers/webhook.go b/pkg/services/alerting/notifiers/webhook.go
index 26989873e9e..4045e496af9 100644
--- a/pkg/services/alerting/notifiers/webhook.go
+++ b/pkg/services/alerting/notifiers/webhook.go
@@ -47,7 +47,7 @@ func NewWebHookNotifier(model *m.AlertNotification) (alerting.Notifier, error) {
}
return &WebhookNotifier{
- NotifierBase: NewNotifierBase(model.Id, model.IsDefault, model.Name, model.Type, model.NotifyOnce, model.Frequency, model.Settings),
+ NotifierBase: NewNotifierBase(model),
Url: url,
User: model.Settings.Get("username").MustString(),
Password: model.Settings.Get("password").MustString(),
diff --git a/pkg/services/sqlstore/alert_notification.go b/pkg/services/sqlstore/alert_notification.go
index ff36c38b1a5..8c136bd3887 100644
--- a/pkg/services/sqlstore/alert_notification.go
+++ b/pkg/services/sqlstore/alert_notification.go
@@ -57,7 +57,7 @@ func GetAlertNotificationsToSend(query *m.GetAlertNotificationsToSendQuery) erro
alert_notification.updated,
alert_notification.settings,
alert_notification.is_default,
- alert_notification.notify_once,
+ alert_notification.send_reminder,
alert_notification.frequency
FROM alert_notification
`)
@@ -97,7 +97,7 @@ func getAlertNotificationInternal(query *m.GetAlertNotificationsQuery, sess *DBS
alert_notification.updated,
alert_notification.settings,
alert_notification.is_default,
- alert_notification.notify_once,
+ alert_notification.send_reminder,
alert_notification.frequency
FROM alert_notification
`)
@@ -145,7 +145,7 @@ func CreateAlertNotificationCommand(cmd *m.CreateAlertNotificationCommand) error
}
var frequency time.Duration
- if !cmd.NotifyOnce {
+ if cmd.SendReminder {
if cmd.Frequency == "" {
return m.ErrNotificationFrequencyNotFound
}
@@ -157,18 +157,18 @@ func CreateAlertNotificationCommand(cmd *m.CreateAlertNotificationCommand) error
}
alertNotification := &m.AlertNotification{
- OrgId: cmd.OrgId,
- Name: cmd.Name,
- Type: cmd.Type,
- Settings: cmd.Settings,
- NotifyOnce: cmd.NotifyOnce,
- Frequency: frequency,
- Created: time.Now(),
- Updated: time.Now(),
- IsDefault: cmd.IsDefault,
+ OrgId: cmd.OrgId,
+ Name: cmd.Name,
+ Type: cmd.Type,
+ Settings: cmd.Settings,
+ SendReminder: cmd.SendReminder,
+ Frequency: frequency,
+ Created: time.Now(),
+ Updated: time.Now(),
+ IsDefault: cmd.IsDefault,
}
- if _, err = sess.MustCols("notify_once").Insert(alertNotification); err != nil {
+ if _, err = sess.MustCols("send_reminder").Insert(alertNotification); err != nil {
return err
}
@@ -200,9 +200,9 @@ func UpdateAlertNotification(cmd *m.UpdateAlertNotificationCommand) error {
current.Name = cmd.Name
current.Type = cmd.Type
current.IsDefault = cmd.IsDefault
- current.NotifyOnce = cmd.NotifyOnce
+ current.SendReminder = cmd.SendReminder
- if !current.NotifyOnce {
+ if current.SendReminder {
if cmd.Frequency == "" {
return m.ErrNotificationFrequencyNotFound
}
@@ -215,7 +215,7 @@ func UpdateAlertNotification(cmd *m.UpdateAlertNotificationCommand) error {
current.Frequency = frequency
}
- sess.UseBool("is_default", "notify_once")
+ sess.UseBool("is_default", "send_reminder")
if affected, err := sess.ID(cmd.Id).Update(current); err != nil {
return err
diff --git a/pkg/services/sqlstore/alert_notification_test.go b/pkg/services/sqlstore/alert_notification_test.go
index 578a53f34ad..fe7f02b22b0 100644
--- a/pkg/services/sqlstore/alert_notification_test.go
+++ b/pkg/services/sqlstore/alert_notification_test.go
@@ -23,13 +23,13 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
So(cmd.Result, ShouldBeNil)
})
- Convey("Cannot save alert notifier with notitfyonce = false", func() {
+ Convey("Cannot save alert notifier with send reminder = true", func() {
cmd := &m.CreateAlertNotificationCommand{
- Name: "ops",
- Type: "email",
- OrgId: 1,
- NotifyOnce: false,
- Settings: simplejson.New(),
+ Name: "ops",
+ Type: "email",
+ OrgId: 1,
+ SendReminder: true,
+ Settings: simplejson.New(),
}
Convey("and missing frequency", func() {
@@ -47,19 +47,19 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
Convey("Cannot update alert notifier with notitfyonce = false", func() {
cmd := &m.CreateAlertNotificationCommand{
- Name: "ops update",
- Type: "email",
- OrgId: 1,
- NotifyOnce: true,
- Settings: simplejson.New(),
+ Name: "ops update",
+ Type: "email",
+ OrgId: 1,
+ SendReminder: false,
+ Settings: simplejson.New(),
}
err := CreateAlertNotificationCommand(cmd)
So(err, ShouldBeNil)
updateCmd := &m.UpdateAlertNotificationCommand{
- Id: cmd.Result.Id,
- NotifyOnce: false,
+ Id: cmd.Result.Id,
+ SendReminder: true,
}
Convey("and missing frequency", func() {
@@ -71,18 +71,19 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
updateCmd.Frequency = "invalid duration"
err := UpdateAlertNotification(updateCmd)
+ So(err, ShouldNotBeNil)
So(err.Error(), ShouldEqual, "time: invalid duration invalid duration")
})
})
Convey("Can save Alert Notification", func() {
cmd := &m.CreateAlertNotificationCommand{
- Name: "ops",
- Type: "email",
- OrgId: 1,
- NotifyOnce: true,
- Frequency: "10s",
- Settings: simplejson.New(),
+ Name: "ops",
+ Type: "email",
+ OrgId: 1,
+ SendReminder: true,
+ Frequency: "10s",
+ Settings: simplejson.New(),
}
err := CreateAlertNotificationCommand(cmd)
@@ -98,13 +99,13 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
Convey("Can update alert notification", func() {
newCmd := &m.UpdateAlertNotificationCommand{
- Name: "NewName",
- Type: "webhook",
- OrgId: cmd.Result.OrgId,
- NotifyOnce: true,
- Frequency: "10s",
- Settings: simplejson.New(),
- Id: cmd.Result.Id,
+ Name: "NewName",
+ Type: "webhook",
+ OrgId: cmd.Result.OrgId,
+ SendReminder: true,
+ Frequency: "10s",
+ Settings: simplejson.New(),
+ Id: cmd.Result.Id,
}
err := UpdateAlertNotification(newCmd)
So(err, ShouldBeNil)
@@ -113,12 +114,12 @@ func TestAlertNotificationSQLAccess(t *testing.T) {
})
Convey("Can search using an array of ids", func() {
- cmd1 := m.CreateAlertNotificationCommand{Name: "nagios", Type: "webhook", OrgId: 1, NotifyOnce: true, Frequency: "10s", Settings: simplejson.New()}
- cmd2 := m.CreateAlertNotificationCommand{Name: "slack", Type: "webhook", OrgId: 1, NotifyOnce: true, Frequency: "10s", Settings: simplejson.New()}
- cmd3 := m.CreateAlertNotificationCommand{Name: "ops2", Type: "email", OrgId: 1, NotifyOnce: true, Frequency: "10s", Settings: simplejson.New()}
- cmd4 := m.CreateAlertNotificationCommand{IsDefault: true, Name: "default", Type: "email", OrgId: 1, NotifyOnce: true, Frequency: "10s", Settings: simplejson.New()}
+ cmd1 := m.CreateAlertNotificationCommand{Name: "nagios", Type: "webhook", OrgId: 1, SendReminder: true, Frequency: "10s", Settings: simplejson.New()}
+ cmd2 := m.CreateAlertNotificationCommand{Name: "slack", Type: "webhook", OrgId: 1, SendReminder: true, Frequency: "10s", Settings: simplejson.New()}
+ cmd3 := m.CreateAlertNotificationCommand{Name: "ops2", Type: "email", OrgId: 1, SendReminder: true, Frequency: "10s", Settings: simplejson.New()}
+ cmd4 := m.CreateAlertNotificationCommand{IsDefault: true, Name: "default", Type: "email", OrgId: 1, SendReminder: true, Frequency: "10s", Settings: simplejson.New()}
- otherOrg := m.CreateAlertNotificationCommand{Name: "default", Type: "email", OrgId: 2, NotifyOnce: true, Frequency: "10s", Settings: simplejson.New()}
+ otherOrg := m.CreateAlertNotificationCommand{Name: "default", Type: "email", OrgId: 2, SendReminder: true, Frequency: "10s", Settings: simplejson.New()}
So(CreateAlertNotificationCommand(&cmd1), ShouldBeNil)
So(CreateAlertNotificationCommand(&cmd2), ShouldBeNil)
diff --git a/pkg/services/sqlstore/migrations/alert_mig.go b/pkg/services/sqlstore/migrations/alert_mig.go
index d045f611fb2..51509099c7d 100644
--- a/pkg/services/sqlstore/migrations/alert_mig.go
+++ b/pkg/services/sqlstore/migrations/alert_mig.go
@@ -68,9 +68,10 @@ func addAlertMigrations(mg *Migrator) {
mg.AddMigration("Add column frequency", NewAddColumnMigration(alert_notification, &Column{
Name: "frequency", Type: DB_BigInt, Nullable: true,
}))
- mg.AddMigration("Add column notify_once", NewAddColumnMigration(alert_notification, &Column{
- Name: "notify_once", Type: DB_Bool, Nullable: false, Default: "1",
+ mg.AddMigration("Add column send_reminder", NewAddColumnMigration(alert_notification, &Column{
+ Name: "send_reminder", Type: DB_Bool, Nullable: true, Default: "0",
}))
+
mg.AddMigration("add index alert_notification org_id & name", NewAddIndexMigration(alert_notification, alert_notification.Indices[0]))
notification_journal := Table{
diff --git a/public/app/features/alerting/notification_edit_ctrl.ts b/public/app/features/alerting/notification_edit_ctrl.ts
index 9d20e871c7c..e066406bc43 100644
--- a/public/app/features/alerting/notification_edit_ctrl.ts
+++ b/public/app/features/alerting/notification_edit_ctrl.ts
@@ -11,7 +11,7 @@ export class AlertNotificationEditCtrl {
model: any;
defaults: any = {
type: 'email',
- notifyOnce: true,
+ sendReminder: false,
frequency: '15m',
settings: {
httpMethod: 'POST',
diff --git a/public/app/features/alerting/partials/notification_edit.html b/public/app/features/alerting/partials/notification_edit.html
index 48d44b74581..2a2fbb131b8 100644
--- a/public/app/features/alerting/partials/notification_edit.html
+++ b/public/app/features/alerting/partials/notification_edit.html
@@ -34,14 +34,27 @@