mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Using func InitNotifier for verifying notification settings
This commit is contained in:
parent
f132e929ce
commit
d0370ea7ad
@ -10,7 +10,6 @@ import (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
ErrInvalidConfigTooManyDefault = errors.New("Alert notification provisioning config is invalid. Only one alert notification can be marked as default")
|
ErrInvalidConfigTooManyDefault = errors.New("Alert notification provisioning config is invalid. Only one alert notification can be marked as default")
|
||||||
ErrInvalidNotifierType = errors.New("Unknown notifier type")
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func Provision(configDirectory string) error {
|
func Provision(configDirectory string) error {
|
||||||
|
@ -136,7 +136,6 @@ func validateRequiredField(notifications []*notificationsAsConfig) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func validateNotifications(notifications []*notificationsAsConfig) error {
|
func validateNotifications(notifications []*notificationsAsConfig) error {
|
||||||
notifierTypes := alerting.GetNotifiers()
|
|
||||||
|
|
||||||
for i := range notifications {
|
for i := range notifications {
|
||||||
if notifications[i].Notifications == nil {
|
if notifications[i].Notifications == nil {
|
||||||
@ -144,24 +143,13 @@ func validateNotifications(notifications []*notificationsAsConfig) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for _, notification := range notifications[i].Notifications {
|
for _, notification := range notifications[i].Notifications {
|
||||||
foundNotifier := false
|
_, err := alerting.InitNotifier(&m.AlertNotification{
|
||||||
|
Name: notification.Name,
|
||||||
for _, notifier := range notifierTypes {
|
Settings: notification.SettingsToJson(),
|
||||||
if notifier.Type == notification.Type {
|
Type: notification.Type,
|
||||||
foundNotifier = true
|
})
|
||||||
_, notifierError := notifier.Factory(&m.AlertNotification{
|
if err != nil {
|
||||||
Name: notification.Name,
|
return err
|
||||||
Settings: notification.SettingsToJson(),
|
|
||||||
Type: notification.Type,
|
|
||||||
})
|
|
||||||
if notifierError != nil {
|
|
||||||
return notifierError
|
|
||||||
}
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !foundNotifier {
|
|
||||||
return ErrInvalidNotifierType
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -293,7 +293,8 @@ func TestNotificationAsConfig(t *testing.T) {
|
|||||||
Convey("Unknown notifier should return error", func() {
|
Convey("Unknown notifier should return error", func() {
|
||||||
cfgProvifer := &configReader{log: log.New("test logger")}
|
cfgProvifer := &configReader{log: log.New("test logger")}
|
||||||
_, err := cfgProvifer.readConfig(unknownNotifier)
|
_, err := cfgProvifer.readConfig(unknownNotifier)
|
||||||
So(err, ShouldEqual, ErrInvalidNotifierType)
|
So(err, ShouldNotBeNil)
|
||||||
|
So(err.Error(), ShouldEqual, "Unsupported notification type")
|
||||||
})
|
})
|
||||||
|
|
||||||
Convey("Read incorrect properties", func() {
|
Convey("Read incorrect properties", func() {
|
||||||
|
Loading…
Reference in New Issue
Block a user