alerting: only check frequency when not send once

This commit is contained in:
bergquist
2018-06-04 22:19:27 +02:00
parent 0e647db485
commit 93124f38fa
5 changed files with 135 additions and 81 deletions
+20 -15
View File
@@ -144,14 +144,16 @@ func CreateAlertNotificationCommand(cmd *m.CreateAlertNotificationCommand) error
return fmt.Errorf("Alert notification name %s already exists", cmd.Name)
}
if cmd.Frequency == "" {
return fmt.Errorf("Alert notification frequency required")
}
var frequency time.Duration
frequency, err = time.ParseDuration(cmd.Frequency)
if err != nil {
return err
if !cmd.NotifyOnce {
if cmd.Frequency == "" {
return m.ErrNotificationFrequencyNotFound
}
frequency, err = time.ParseDuration(cmd.Frequency)
if err != nil {
return err
}
}
alertNotification := &m.AlertNotification{
@@ -200,22 +202,25 @@ func UpdateAlertNotification(cmd *m.UpdateAlertNotificationCommand) error {
current.IsDefault = cmd.IsDefault
current.NotifyOnce = cmd.NotifyOnce
if cmd.Frequency == "" {
return m.ErrNotificationFrequencyNotFound
}
if !current.NotifyOnce {
if cmd.Frequency == "" {
return m.ErrNotificationFrequencyNotFound
}
frequency, err := time.ParseDuration(cmd.Frequency)
if err != nil {
return err
frequency, err := time.ParseDuration(cmd.Frequency)
if err != nil {
return err
}
current.Frequency = frequency
}
current.Frequency = frequency
sess.UseBool("is_default", "notify_once")
if affected, err := sess.ID(cmd.Id).Update(current); err != nil {
return err
} else if affected == 0 {
return fmt.Errorf("Could not find alert notification")
return fmt.Errorf("Could not update alert notification")
}
cmd.Result = &current