diff --git a/pkg/api/alerting.go b/pkg/api/alerting.go
index 3f2c38486a4..e54f8adf0c4 100644
--- a/pkg/api/alerting.go
+++ b/pkg/api/alerting.go
@@ -156,3 +156,35 @@ func PutAlertState(c *middleware.Context, cmd models.UpdateAlertStateCommand) Re
return Json(200, cmd.Result)
}
+
+func GetAlertNotifications(c *middleware.Context) Response {
+ query := &models.GetAlertNotificationQuery{
+ OrgID: c.OrgId,
+ }
+
+ if err := bus.Dispatch(query); err != nil {
+ return ApiError(500, "Failed to get alert notifications", err)
+ }
+
+ return Json(200, query.Result)
+}
+
+func CreateAlertNotification(c *middleware.Context, cmd *models.CreateAlertNotificationCommand) Response {
+ cmd.OrgID = c.OrgId
+
+ if err := bus.Dispatch(cmd); err != nil {
+ return ApiError(500, "Failed to create alert notification", err)
+ }
+
+ return Json(200, cmd.Result)
+}
+
+func UpdateAlertNotification(c *middleware.Context, cmd *models.UpdateAlertNotificationCommand) Response {
+ cmd.OrgID = c.OrgId
+
+ if err := bus.Dispatch(cmd); err != nil {
+ return ApiError(500, "Failed to update alert notification", err)
+ }
+
+ return Json(200, cmd.Result)
+}
diff --git a/pkg/api/api.go b/pkg/api/api.go
index 4483f64530f..5de22c7ba51 100644
--- a/pkg/api/api.go
+++ b/pkg/api/api.go
@@ -59,6 +59,7 @@ func Register(r *macaron.Macaron) {
r.Get("/playlists/", reqSignedIn, Index)
r.Get("/playlists/*", reqSignedIn, Index)
r.Get("/alerting/", reqSignedIn, Index)
+ r.Get("/alerting/*", reqSignedIn, Index)
// sign up
r.Get("/signup", Index)
@@ -250,6 +251,12 @@ func Register(r *macaron.Macaron) {
r.Get("/", wrap(GetAlerts))
})
+ r.Get("/notifications", wrap(GetAlertNotifications))
+ r.Group("/notification", func() {
+ r.Post("/", bind(m.CreateAlertNotificationCommand{}), wrap(CreateAlertNotification))
+ r.Put("/", bind(m.UpdateAlertNotificationCommand{}), wrap(UpdateAlertNotification))
+ })
+
r.Get("/changes", wrap(GetAlertChanges))
})
diff --git a/pkg/services/alerting/notifier.go b/pkg/services/alerting/notifier.go
index 6dbd4812190..48fa4767437 100644
--- a/pkg/services/alerting/notifier.go
+++ b/pkg/services/alerting/notifier.go
@@ -29,7 +29,7 @@ func (n *NotifierImpl) Notify(alertResult *AlertResult) {
n.log.Warn("looopie", "warn", warn, "crit", crit)
if warn || crit {
n.log.Info("Sending notification", "state", alertResult.State, "type", notifier.Type)
- go notifier.Notifierr.Notify(alertResult)
+ go notifier.Notifierr.Dispatch(alertResult)
}
}
@@ -41,7 +41,7 @@ type Notification struct {
SendWarning bool
SendCritical bool
- Notifierr Notifierr
+ Notifierr NotificationDispatcher
}
type EmailNotifier struct {
@@ -50,7 +50,7 @@ type EmailNotifier struct {
log log.Logger
}
-func (this *EmailNotifier) Notify(alertResult *AlertResult) {
+func (this *EmailNotifier) Dispatch(alertResult *AlertResult) {
//bus.dispath to notification package in grafana
this.log.Info("Sending email")
}
@@ -62,13 +62,13 @@ type WebhookNotifier struct {
log log.Logger
}
-func (this *WebhookNotifier) Notify(alertResult *AlertResult) {
+func (this *WebhookNotifier) Dispatch(alertResult *AlertResult) {
//bus.dispath to notification package in grafana
this.log.Info("Sending webhook")
}
-type Notifierr interface {
- Notify(alertResult *AlertResult)
+type NotificationDispatcher interface {
+ Dispatch(alertResult *AlertResult)
}
func (n *NotifierImpl) getNotifiers(orgId int64, notificationGroups []int64) []*Notification {
@@ -104,7 +104,7 @@ func NewNotificationFromDBModel(model *m.AlertNotification) (*Notification, erro
}, nil
}
-var createNotifier = func(notificationType string, settings *simplejson.Json) Notifierr {
+var createNotifier = func(notificationType string, settings *simplejson.Json) NotificationDispatcher {
if notificationType == "email" {
return &EmailNotifier{
To: settings.Get("to").MustString(),
diff --git a/public/app/core/routes/routes.ts b/public/app/core/routes/routes.ts
index a1655f23bd2..1dccb5a1ea0 100644
--- a/public/app/core/routes/routes.ts
+++ b/public/app/core/routes/routes.ts
@@ -201,6 +201,12 @@ function setupAngularRoutes($routeProvider, $locationProvider) {
controllerAs: 'ctrl',
resolve: loadAlertingBundle,
})
+ .when('/alerting/notifications', {
+ templateUrl: 'public/app/features/alerting/partials/alert_notifications.html',
+ controller: 'AlertNotificationsCtrl',
+ contrllerAs: 'ctrl',
+ resolve: loadAlertingBundle,
+ })
.when('/alerting/:alertId/states', {
templateUrl: 'public/app/features/alerting/partials/alert_log.html',
controller: 'AlertLogCtrl',
diff --git a/public/app/features/alerting/alert_notifications_ctrl.ts b/public/app/features/alerting/alert_notifications_ctrl.ts
new file mode 100644
index 00000000000..ac3ad532450
--- /dev/null
+++ b/public/app/features/alerting/alert_notifications_ctrl.ts
@@ -0,0 +1,20 @@
+///
| Name | + +
|---|
| + Name + | +