2016-04-27 13:02:28 +02:00
|
|
|
///<reference path="../../headers/common.d.ts" />
|
|
|
|
|
|
|
|
|
|
import angular from 'angular';
|
|
|
|
|
import _ from 'lodash';
|
|
|
|
|
import coreModule from '../../core/core_module';
|
2016-08-17 15:48:58 +02:00
|
|
|
import appEvents from '../../core/app_events';
|
2016-08-16 09:52:45 +02:00
|
|
|
import moment from 'moment';
|
2016-05-02 15:31:40 +02:00
|
|
|
import alertDef from './alert_def';
|
2016-04-27 13:02:28 +02:00
|
|
|
|
2016-06-06 09:17:29 +02:00
|
|
|
export class AlertListCtrl {
|
2016-04-27 13:02:28 +02:00
|
|
|
|
|
|
|
|
alerts: any;
|
2016-08-17 11:00:00 +02:00
|
|
|
stateFilters = [
|
|
|
|
|
{text: 'All', value: null},
|
|
|
|
|
{text: 'OK', value: 'ok'},
|
2016-09-06 20:40:12 +02:00
|
|
|
{text: 'Unknown', value: 'unknown'},
|
2016-08-17 11:00:00 +02:00
|
|
|
{text: 'Warning', value: 'warning'},
|
|
|
|
|
{text: 'Critical', value: 'critical'},
|
|
|
|
|
{text: 'Execution Error', value: 'execution_error'},
|
|
|
|
|
];
|
|
|
|
|
|
2016-08-16 09:52:45 +02:00
|
|
|
filters = {
|
2016-08-17 11:00:00 +02:00
|
|
|
state: 'ALL'
|
2016-05-09 16:32:35 +02:00
|
|
|
};
|
2016-04-28 11:42:03 +02:00
|
|
|
|
2016-04-27 13:02:28 +02:00
|
|
|
/** @ngInject */
|
2016-08-17 11:00:00 +02:00
|
|
|
constructor(private backendSrv, private $location) {
|
|
|
|
|
var params = $location.search();
|
|
|
|
|
this.filters.state = params.state || null;
|
2016-04-27 13:02:28 +02:00
|
|
|
this.loadAlerts();
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-17 11:00:00 +02:00
|
|
|
filtersChanged() {
|
|
|
|
|
this.$location.search(this.filters);
|
2016-05-09 16:32:35 +02:00
|
|
|
}
|
|
|
|
|
|
2016-04-27 13:02:28 +02:00
|
|
|
loadAlerts() {
|
2016-08-17 11:00:00 +02:00
|
|
|
this.backendSrv.get('/api/alerts', this.filters).then(result => {
|
2016-05-02 15:31:40 +02:00
|
|
|
this.alerts = _.map(result, alert => {
|
2016-08-17 11:00:00 +02:00
|
|
|
alert.stateModel = alertDef.getStateDisplayModel(alert.state);
|
2016-08-16 09:52:45 +02:00
|
|
|
alert.newStateDateAgo = moment(alert.newStateDate).fromNow().replace(" ago", "");
|
2016-05-02 15:31:40 +02:00
|
|
|
return alert;
|
|
|
|
|
});
|
2016-04-27 13:02:28 +02:00
|
|
|
});
|
|
|
|
|
}
|
2016-08-17 15:48:58 +02:00
|
|
|
|
|
|
|
|
openHowTo() {
|
|
|
|
|
appEvents.emit('show-modal', {
|
|
|
|
|
src: 'public/app/features/alerting/partials/alert_howto.html',
|
2016-08-18 10:07:31 +02:00
|
|
|
modalClass: 'confirm-modal',
|
2016-08-17 15:48:58 +02:00
|
|
|
model: {}
|
|
|
|
|
});
|
|
|
|
|
}
|
2016-04-27 13:02:28 +02:00
|
|
|
}
|
|
|
|
|
|
2016-06-06 09:17:29 +02:00
|
|
|
coreModule.controller('AlertListCtrl', AlertListCtrl);
|
2016-04-27 13:02:28 +02:00
|
|
|
|