diff --git a/pkg/services/sqlstore/migrations/alert_mig.go b/pkg/services/sqlstore/migrations/alert_mig.go index a043451cf1b..a228f186da9 100644 --- a/pkg/services/sqlstore/migrations/alert_mig.go +++ b/pkg/services/sqlstore/migrations/alert_mig.go @@ -65,7 +65,6 @@ func addAlertMigrations(mg *Migrator) { {Name: "org_id", Type: DB_BigInt, Nullable: false}, {Name: "name", Type: DB_NVarchar, Length: 255, Nullable: false}, {Name: "type", Type: DB_NVarchar, Length: 255, Nullable: false}, - {Name: "always_execute", Type: DB_Bool, Nullable: false}, {Name: "settings", Type: DB_Text, Nullable: false}, {Name: "created", Type: DB_DateTime, Nullable: false}, {Name: "updated", Type: DB_DateTime, Nullable: false}, diff --git a/public/app/core/routes/routes.ts b/public/app/core/routes/routes.ts index ba79398cb72..85bf7334042 100644 --- a/public/app/core/routes/routes.ts +++ b/public/app/core/routes/routes.ts @@ -211,7 +211,7 @@ function setupAngularRoutes($routeProvider, $locationProvider) { controllerAs: 'ctrl', resolve: loadAlertingBundle, }) - .when('/alerting/notification/:notificationId/edit', { + .when('/alerting/notification/:id/edit', { templateUrl: 'public/app/features/alerting/partials/notification_edit.html', controller: 'AlertNotificationEditCtrl', controllerAs: 'ctrl', diff --git a/public/app/features/alerting/alerts_ctrl.ts b/public/app/features/alerting/alerts_ctrl.ts index 8adc0e105cc..17d048cee85 100644 --- a/public/app/features/alerting/alerts_ctrl.ts +++ b/public/app/features/alerting/alerts_ctrl.ts @@ -27,7 +27,6 @@ export class AlertListCtrl { updateFilter() { var stats = []; - this.filter.ok && stats.push('OK'); this.filter.warn && stats.push('Warn'); this.filter.critical && stats.push('critical'); diff --git a/public/app/features/alerting/notification_edit_ctrl.ts b/public/app/features/alerting/notification_edit_ctrl.ts index 69e2e276862..0b959945215 100644 --- a/public/app/features/alerting/notification_edit_ctrl.ts +++ b/public/app/features/alerting/notification_edit_ctrl.ts @@ -6,49 +6,39 @@ import coreModule from '../../core/core_module'; import config from 'app/core/config'; export class AlertNotificationEditCtrl { - - notification: any; + model: any; /** @ngInject */ - constructor(private $routeParams, private backendSrv, private $scope) { - if ($routeParams.notificationId) { - this.loadNotification($routeParams.notificationId); + constructor(private $routeParams, private backendSrv, private $scope, private $location) { + if ($routeParams.id) { + this.loadNotification($routeParams.id); } else { - this.notification = { + this.model = { type: 'email', + settings: {} }; } } - loadNotification(notificationId) { - this.backendSrv.get(`/api/alert-notifications/${notificationId}`).then(result => { - console.log(result); - this.notification = result; + loadNotification(id) { + this.backendSrv.get(`/api/alert-notifications/${id}`).then(result => { + this.model = result; }); } isNew() { - return this.notification === undefined || this.notification.id === undefined; + return this.model.id === undefined; } save() { - if (this.notification.id) { - console.log('this.notification: ', this.notification); - this.backendSrv.put(`/api/alert-notifications/${this.notification.id}`, this.notification) - .then(result => { - this.notification = result; - this.$scope.appEvent('alert-success', ['Notification created!', '']); - }, () => { - this.$scope.appEvent('alert-error', ['Unable to create notification.', '']); - }); + if (this.model.id) { + this.backendSrv.put(`/api/alert-notifications/${this.model.id}`, this.model).then(res => { + this.model = res; + }); } else { - this.backendSrv.post(`/api/alert-notifications`, this.notification) - .then(result => { - this.notification = result; - this.$scope.appEvent('alert-success', ['Notification updated!', '']); - }, () => { - this.$scope.appEvent('alert-error', ['Unable to update notification.', '']); - }); + this.backendSrv.post(`/api/alert-notifications`, this.model).then(res => { + this.$location.path('alerting/notification/' + res.id + '/edit'); + }); } } } diff --git a/public/app/features/alerting/notifications_list_ctrl.ts b/public/app/features/alerting/notifications_list_ctrl.ts index d5a05b3edca..184d829f69d 100644 --- a/public/app/features/alerting/notifications_list_ctrl.ts +++ b/public/app/features/alerting/notifications_list_ctrl.ts @@ -20,16 +20,12 @@ export class AlertNotificationsListCtrl { }); } - deleteNotification(notificationId) { - this.backendSrv.delete(`/api/alerts-notification/${notificationId}`) - .then(() => { - this.notifications = this.notifications.filter(notification => { - return notification.id !== notificationId; - }); - this.$scope.appEvent('alert-success', ['Notification deleted', '']); - }, () => { - this.$scope.appEvent('alert-error', ['Unable to delete notification', '']); + deleteNotification(id) { + this.backendSrv.delete(`/api/alert-notifications/${id}`).then(() => { + this.notifications = this.notifications.filter(notification => { + return notification.id !== notificationId; }); + }); } } diff --git a/public/app/features/alerting/partials/alert_list.html b/public/app/features/alerting/partials/alert_list.html index 420acd4b0bf..dbae224a0cc 100644 --- a/public/app/features/alerting/partials/alert_list.html +++ b/public/app/features/alerting/partials/alert_list.html @@ -1,4 +1,4 @@ - +
diff --git a/public/app/features/alerting/partials/notification_edit.html b/public/app/features/alerting/partials/notification_edit.html index 8ed471887d5..a963bd348a3 100644 --- a/public/app/features/alerting/partials/notification_edit.html +++ b/public/app/features/alerting/partials/notification_edit.html @@ -1,4 +1,8 @@ - + + + + Notifications +
@@ -9,13 +13,13 @@
Name - +
Type
@@ -23,27 +27,28 @@
-
+

Webhook settings

Url - +
Username - +
Password - +
-
+ +

Email addresses

- +
diff --git a/public/app/features/alerting/partials/notifications_list.html b/public/app/features/alerting/partials/notifications_list.html index 10f45571c31..b46f23fe2a8 100644 --- a/public/app/features/alerting/partials/notifications_list.html +++ b/public/app/features/alerting/partials/notifications_list.html @@ -1,4 +1,8 @@ - + + + + Notifications +
diff --git a/public/app/plugins/panel/graph/alert_tab_ctrl.ts b/public/app/plugins/panel/graph/alert_tab_ctrl.ts index 559e9c6b78e..fae5a4ca8ff 100644 --- a/public/app/plugins/panel/graph/alert_tab_ctrl.ts +++ b/public/app/plugins/panel/graph/alert_tab_ctrl.ts @@ -49,14 +49,17 @@ export class AlertTabCtrl { {text: 'Critical', value: 'critical'}, {text: 'Warning', value: 'warning'}, ]; + addNotificationSegment; /** @ngInject */ - constructor($scope, private $timeout, private backendSrv, private dashboardSrv) { + constructor($scope, private $timeout, private backendSrv, private dashboardSrv, private uiSegmentSrv) { this.panelCtrl = $scope.ctrl; this.panel = this.panelCtrl.panel; $scope.ctrl = this; this.metricTargets = this.panel.targets.map(val => val); + this.addNotificationSegment = uiSegmentSrv.newPlusButton(); + this.initModel(); // set panel alert edit mode @@ -66,6 +69,28 @@ export class AlertTabCtrl { }); } + getNotifications() { + return this.backendSrv.get('/api/alert-notifications').then(res => { + return res.map(item => { + return this.uiSegmentSrv.newSegment(item.name); + }); + }); + } + + notificationAdded() { + this.alert.notifications.push({ + name: this.addNotificationSegment.value + }); + + // reset plus button + this.addNotificationSegment.value = this.uiSegmentSrv.newPlusButton().value; + this.addNotificationSegment.html = this.uiSegmentSrv.newPlusButton().html; + } + + removeNotification(index) { + this.alert.notifications.splice(index, 1); + } + initModel() { var alert = this.alert = this.panel.alert = this.panel.alert || {}; diff --git a/public/app/plugins/panel/graph/partials/tab_alerting.html b/public/app/plugins/panel/graph/partials/tab_alerting.html index c5b85f5de59..41edfe6aaad 100644 --- a/public/app/plugins/panel/graph/partials/tab_alerting.html +++ b/public/app/plugins/panel/graph/partials/tab_alerting.html @@ -24,53 +24,33 @@
-
-
Alert Rule
-
-
- Name - -
- - - - - - - - - -
- Evaluate every - -
-
-
-
- Notifications - -
- -
- Severity -
- -
-
-
-
+
+
Alert Rule
+
+
+ Name + +
+
+ Evaluate every + +
+
+ Severity +
+ +
+
+
+
Conditions
- AND + AND + WHEN
- When Value + Value
@@ -98,48 +78,63 @@ -
+
-
-
-
- - -
+
+
Notifications
+
+
+ + {{nc.name}} + + + +
+
+
- +
+
+ + + +
+
- -
-
- Evaluating rule + Evaluating rule
- +
-
- -
+
+ +