2016-04-27 06:02:28 -05:00
|
|
|
///<reference path="../../headers/common.d.ts" />
|
|
|
|
|
|
|
|
import angular from 'angular';
|
|
|
|
import _ from 'lodash';
|
|
|
|
import coreModule from '../../core/core_module';
|
2016-08-17 08:48:58 -05:00
|
|
|
import appEvents from '../../core/app_events';
|
2016-08-16 02:52:45 -05:00
|
|
|
import moment from 'moment';
|
2016-05-02 08:31:40 -05:00
|
|
|
import alertDef from './alert_def';
|
2016-04-27 06:02:28 -05:00
|
|
|
|
2016-06-06 02:17:29 -05:00
|
|
|
export class AlertListCtrl {
|
2016-04-27 06:02:28 -05:00
|
|
|
|
|
|
|
alerts: any;
|
2016-08-17 04:00:00 -05:00
|
|
|
stateFilters = [
|
|
|
|
{text: 'All', value: null},
|
|
|
|
{text: 'OK', value: 'ok'},
|
2016-09-13 08:09:55 -05:00
|
|
|
{text: 'Alerting', value: 'alerting'},
|
|
|
|
{text: 'No Data', value: 'no_data'},
|
2017-02-16 09:01:57 -06:00
|
|
|
{text: 'Paused', value: 'paused'},
|
2016-08-17 04:00:00 -05:00
|
|
|
];
|
|
|
|
|
2016-08-16 02:52:45 -05:00
|
|
|
filters = {
|
2016-08-17 04:00:00 -05:00
|
|
|
state: 'ALL'
|
2016-05-09 09:32:35 -05:00
|
|
|
};
|
2016-04-28 04:42:03 -05:00
|
|
|
|
2016-04-27 06:02:28 -05:00
|
|
|
/** @ngInject */
|
2016-10-10 08:17:14 -05:00
|
|
|
constructor(private backendSrv, private $location, private $scope) {
|
2016-08-17 04:00:00 -05:00
|
|
|
var params = $location.search();
|
|
|
|
this.filters.state = params.state || null;
|
2016-04-27 06:02:28 -05:00
|
|
|
this.loadAlerts();
|
|
|
|
}
|
|
|
|
|
2016-08-17 04:00:00 -05:00
|
|
|
filtersChanged() {
|
|
|
|
this.$location.search(this.filters);
|
2016-05-09 09:32:35 -05:00
|
|
|
}
|
|
|
|
|
2016-04-27 06:02:28 -05:00
|
|
|
loadAlerts() {
|
2016-08-17 04:00:00 -05:00
|
|
|
this.backendSrv.get('/api/alerts', this.filters).then(result => {
|
2016-05-02 08:31:40 -05:00
|
|
|
this.alerts = _.map(result, alert => {
|
2016-08-17 04:00:00 -05:00
|
|
|
alert.stateModel = alertDef.getStateDisplayModel(alert.state);
|
2016-08-16 02:52:45 -05:00
|
|
|
alert.newStateDateAgo = moment(alert.newStateDate).fromNow().replace(" ago", "");
|
2017-01-16 11:01:08 -06:00
|
|
|
if (alert.evalData && alert.evalData.no_data) {
|
|
|
|
alert.no_data = true;
|
|
|
|
}
|
2016-05-02 08:31:40 -05:00
|
|
|
return alert;
|
|
|
|
});
|
2016-04-27 06:02:28 -05:00
|
|
|
});
|
|
|
|
}
|
2016-08-17 08:48:58 -05:00
|
|
|
|
2016-10-10 08:17:14 -05:00
|
|
|
pauseAlertRule(alertId: any) {
|
|
|
|
var alert = _.find(this.alerts, {id: alertId});
|
|
|
|
|
|
|
|
var payload = {
|
2016-10-11 03:53:24 -05:00
|
|
|
paused: alert.state !== "paused"
|
2016-10-10 08:17:14 -05:00
|
|
|
};
|
|
|
|
|
2016-10-11 03:53:24 -05:00
|
|
|
this.backendSrv.post(`/api/alerts/${alert.id}/pause`, payload).then(result => {
|
2016-10-10 08:17:14 -05:00
|
|
|
alert.state = result.state;
|
|
|
|
alert.stateModel = alertDef.getStateDisplayModel(result.state);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-08-17 08:48:58 -05:00
|
|
|
openHowTo() {
|
|
|
|
appEvents.emit('show-modal', {
|
|
|
|
src: 'public/app/features/alerting/partials/alert_howto.html',
|
2016-08-18 03:07:31 -05:00
|
|
|
modalClass: 'confirm-modal',
|
2016-08-17 08:48:58 -05:00
|
|
|
model: {}
|
|
|
|
});
|
|
|
|
}
|
2016-04-27 06:02:28 -05:00
|
|
|
}
|
|
|
|
|
2016-06-06 02:17:29 -05:00
|
|
|
coreModule.controller('AlertListCtrl', AlertListCtrl);
|
2016-04-27 06:02:28 -05:00
|
|
|
|