瀏覽代碼

feat(alerting): skeleton for alert notification configuration page

bergquist 9 年之前
父節點
當前提交
a3b7ea7704

+ 32 - 0
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)
+}

+ 7 - 0
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))
 		})
 

+ 7 - 7
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(),

+ 6 - 0
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',

+ 20 - 0
public/app/features/alerting/alert_notifications_ctrl.ts

@@ -0,0 +1,20 @@
+///<reference path="../../headers/common.d.ts" />
+
+import angular from 'angular';
+import _ from 'lodash';
+import coreModule from '../../core/core_module';
+import config from 'app/core/config';
+
+export class AlertNotificationsCtrl {
+
+  /** @ngInject */
+  constructor(private backendSrv) {
+    this.loadNotifications();
+  }
+
+  loadNotifications() {
+  }
+}
+
+coreModule.controller('AlertNotificationsCtrl', AlertNotificationsCtrl);
+

+ 1 - 0
public/app/features/alerting/all.ts

@@ -1,3 +1,4 @@
 import './alerts_ctrl';
 import './alert_log_ctrl';
+import './alert_notifications_ctrl';
 

+ 20 - 0
public/app/features/alerting/partials/alert_notifications.html

@@ -0,0 +1,20 @@
+
+<navbar icon="fa fa-fw fa-list" title="Alerting" title-url="alerting">
+</navbar>
+
+<div class="page-container" >
+	<div class="page-header">
+		<h1>Alert notifications</h1>
+	</div>
+
+	<table class="grafana-options-table">
+		<thead>
+			<th style="min-width: 200px"><strong>Name</strong></th>
+		</thead>
+		<tr ng-repeat="notification in ctrl.notifications">
+			<td class="text-center">
+				Name
+			</td>
+		</tr>
+	</table>
+</div>