Browse Source

feat(alerting): update paths for alert state

bergquist 9 years ago
parent
commit
27274f37e8

+ 5 - 4
pkg/api/api.go

@@ -239,14 +239,15 @@ func Register(r *macaron.Macaron) {
 		r.Get("/metrics/test", GetTestMetrics)
 
 		r.Group("/alerts", func() {
-			r.Get("/events/:alertId", wrap(GetAlertState))
-			r.Put("/events/:alertId", bind(m.UpdateAlertStateCommand{}), wrap(PutAlertState))
-			r.Get("/changes", wrap(GetAlertChanges))
-			r.Get("/", wrap(GetAlerts))
+			r.Get("/:alertId/states", wrap(GetAlertState))
+			r.Put("/:alertId/state", bind(m.UpdateAlertStateCommand{}), wrap(PutAlertState))
 			r.Get("/:alertId", ValidateOrgAlert, wrap(GetAlert))
+			r.Get("/", wrap(GetAlerts))
 			r.Delete("/:alertId", ValidateOrgAlert, wrap(DelAlert))
 		})
 
+		r.Get("/alert-changes", wrap(GetAlertChanges))
+
 		r.Get("/alerts-dashboard/:dashboardId", wrap(GetAlertsForDashboard))
 		r.Get("/alerts-dashboard/:dashboardId/:panelId", wrap(GetAlertsForPanel))
 

+ 1 - 0
pkg/services/sqlstore/alert_rule_changes_test.go

@@ -82,6 +82,7 @@ func TestAlertRuleChangesDataAccess(t *testing.T) {
 				SaveAlertChange("UPDATED", items[0], sess)
 				SaveAlertChange("UPDATED", items[0], sess)
 				SaveAlertChange("UPDATED", items[0], sess)
+				sess.Commit()
 
 				Convey("query for max one change", func() {
 					query := &m.GetAlertChangesQuery{OrgId: FakeOrgId, Limit: 1}

+ 2 - 2
public/app/features/alerts/alert_log_ctrl.ts

@@ -22,7 +22,7 @@ export class AlertLogCtrl {
   }
 
   loadAlertLogs() {
-    this.backendSrv.get('/api/alerts/events/' + this.alertId).then(result => {
+    this.backendSrv.get(`/api/alerts/${this.alertId}/states/`).then(result => {
       this.alertLogs = _.map(result, log => {
         log.iconCss = alertDef.getCssForState(log.newState);
         log.humanTime = moment(log.created).format("YYYY-MM-DD HH:mm:ss");
@@ -30,7 +30,7 @@ export class AlertLogCtrl {
       });
     });
 
-    this.backendSrv.get('/api/alerts/' + this.alertId).then(result => {
+    this.backendSrv.get(`api/alerts/${this.alertId}`).then(result => {
       this.alert = result;
     });
   }

+ 2 - 0
public/app/plugins/panel/graph/alert_tab_ctrl.ts

@@ -9,6 +9,8 @@ export class AlertTabCtrl {
   panelCtrl: any;
   alerting: any;
   metricTargets = [{ refId: '- select query -' } ];
+  operators = ['>', '<', '<=', '>='];
+  aggregators = ['avg', 'sum', 'min', 'max', 'median'];
 
   /** @ngInject */
   constructor($scope, private $timeout) {

+ 3 - 3
public/app/plugins/panel/graph/partials/tab_alerting.html

@@ -17,7 +17,7 @@
         Warn level
       </span>
       <div class="gf-form-select-wrapper max-width-10">
-        <select class="gf-form-input" ng-model="ctrl.panel.alerting.warnOperator" ng-options="oper as oper for oper in ['>', '<', '<=', '>=']"></select>
+				<select class="gf-form-input" ng-model="ctrl.panel.alerting.warnOperator" ng-options="oper as oper for oper in alertTab.operators"></select>
       </div>
       <input class="gf-form-input max-width-7" type="number" ng-model="ctrl.panel.alerting.warnLevel" ng-change="alertTab.thresholdsUpdated()"></input>
     </div>
@@ -27,7 +27,7 @@
         Critical level
       </span>
       <div class="gf-form-select-wrapper max-width-10">
-        <select class="gf-form-input" ng-model="ctrl.panel.alerting.critOperator" ng-options="oper as oper for oper in ['>', '<', '<=', '>=']"></select>
+        <select class="gf-form-input" ng-model="ctrl.panel.alerting.critOperator" ng-options="oper as oper for oper in alertTab.operators"></select>
       </div>
       <input class="gf-form-input max-width-7" type="number" ng-model="ctrl.panel.alerting.critLevel" ng-change="alertTab.thresholdsUpdated()"></input>
     </div>
@@ -40,7 +40,7 @@
       <div class="gf-form-select-wrapper max-width-10">
         <select class="gf-form-input"
           ng-model="ctrl.panel.alerting.aggregator"
-          ng-options="oper as oper for oper in ['avg', 'sum', 'min', 'max', 'median']"></select>
+          ng-options="oper as oper for oper in alertTab.aggregators"></select>
       </div>
     </div>