Commit 69489993 by bergquist

export init notifier func

makes it possible to validate that an notifier can be
initialzed from the provisioning package
parent a6d90151
...@@ -166,7 +166,7 @@ func (n *notificationService) getNeededNotifiers(orgId int64, notificationIds [] ...@@ -166,7 +166,7 @@ func (n *notificationService) getNeededNotifiers(orgId int64, notificationIds []
var result notifierStateSlice var result notifierStateSlice
for _, notification := range query.Result { for _, notification := range query.Result {
not, err := n.createNotifierFor(notification) not, err := InitNotifier(notification)
if err != nil { if err != nil {
n.log.Error("Could not create notifier", "notifier", notification.Id, "error", err) n.log.Error("Could not create notifier", "notifier", notification.Id, "error", err)
continue continue
...@@ -195,7 +195,8 @@ func (n *notificationService) getNeededNotifiers(orgId int64, notificationIds [] ...@@ -195,7 +195,8 @@ func (n *notificationService) getNeededNotifiers(orgId int64, notificationIds []
return result, nil return result, nil
} }
func (n *notificationService) createNotifierFor(model *m.AlertNotification) (Notifier, error) { // InitNotifier instantiate a new notifier based on the model
func InitNotifier(model *m.AlertNotification) (Notifier, error) {
notifierPlugin, found := notifierFactories[model.Type] notifierPlugin, found := notifierFactories[model.Type]
if !found { if !found {
return nil, errors.New("Unsupported notification type") return nil, errors.New("Unsupported notification type")
...@@ -208,6 +209,7 @@ type NotifierFactory func(notification *m.AlertNotification) (Notifier, error) ...@@ -208,6 +209,7 @@ type NotifierFactory func(notification *m.AlertNotification) (Notifier, error)
var notifierFactories = make(map[string]*NotifierPlugin) var notifierFactories = make(map[string]*NotifierPlugin)
// RegisterNotifier register an notifier
func RegisterNotifier(plugin *NotifierPlugin) { func RegisterNotifier(plugin *NotifierPlugin) {
notifierFactories[plugin.Type] = plugin notifierFactories[plugin.Type] = plugin
} }
......
...@@ -32,7 +32,7 @@ func handleNotificationTestCommand(cmd *NotificationTestCommand) error { ...@@ -32,7 +32,7 @@ func handleNotificationTestCommand(cmd *NotificationTestCommand) error {
Settings: cmd.Settings, Settings: cmd.Settings,
} }
notifiers, err := notifier.createNotifierFor(model) notifiers, err := InitNotifier(model)
if err != nil { if err != nil {
log.Error2("Failed to create notifier", "error", err.Error()) log.Error2("Failed to create notifier", "error", err.Error())
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment