mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
parent
2264addd9d
commit
faa3b5f4e8
@ -20,6 +20,14 @@ var conditionTypes = [
|
|||||||
{text: 'Query', value: 'query'},
|
{text: 'Query', value: 'query'},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
var alertStateSortScore = {
|
||||||
|
alerting: 1,
|
||||||
|
no_data: 2,
|
||||||
|
pending: 3,
|
||||||
|
ok: 4,
|
||||||
|
paused: 5,
|
||||||
|
};
|
||||||
|
|
||||||
var evalFunctions = [
|
var evalFunctions = [
|
||||||
{text: 'IS ABOVE', value: 'gt'},
|
{text: 'IS ABOVE', value: 'gt'},
|
||||||
{text: 'IS BELOW', value: 'lt'},
|
{text: 'IS BELOW', value: 'lt'},
|
||||||
@ -129,4 +137,5 @@ export default {
|
|||||||
reducerTypes: reducerTypes,
|
reducerTypes: reducerTypes,
|
||||||
createReducerPart: createReducerPart,
|
createReducerPart: createReducerPart,
|
||||||
joinEvalMatches: joinEvalMatches,
|
joinEvalMatches: joinEvalMatches,
|
||||||
|
alertStateSortScore: alertStateSortScore,
|
||||||
};
|
};
|
||||||
|
@ -11,6 +11,12 @@
|
|||||||
<span class="gf-form-label width-8">Max items</span>
|
<span class="gf-form-label width-8">Max items</span>
|
||||||
<input type="text" class="gf-form-input max-width-15" ng-model="ctrl.panel.limit" ng-change="ctrl.onRender()" />
|
<input type="text" class="gf-form-input max-width-15" ng-model="ctrl.panel.limit" ng-change="ctrl.onRender()" />
|
||||||
</div>
|
</div>
|
||||||
|
<div class="gf-form" ng-show="ctrl.panel.show === 'current'">
|
||||||
|
<span class="gf-form-label width-8">Sort order</span>
|
||||||
|
<div class="gf-form-select-wrapper max-width-15">
|
||||||
|
<select class="gf-form-input" ng-model="ctrl.panel.sortOrder" ng-options="f.value as f.text for f in ctrl.sortOrderOptions" ng-change="ctrl.onRender()"></select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<gf-form-switch class="gf-form" label="Alerts from this dashboard" label-class="width-18" checked="ctrl.panel.onlyAlertsOnDashboard" on-change="ctrl.updateStateFilter()"></gf-form-switch>
|
<gf-form-switch class="gf-form" label="Alerts from this dashboard" label-class="width-18" checked="ctrl.panel.onlyAlertsOnDashboard" on-change="ctrl.updateStateFilter()"></gf-form-switch>
|
||||||
</div>
|
</div>
|
||||||
<div class="section gf-form-group">
|
<div class="section gf-form-group">
|
||||||
|
@ -17,6 +17,12 @@ class AlertListPanel extends PanelCtrl {
|
|||||||
{text: 'Recent state changes', value: 'changes'}
|
{text: 'Recent state changes', value: 'changes'}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
sortOrderOptions = [
|
||||||
|
{text: 'Alphabetical (asc)', value: 1},
|
||||||
|
{text: 'Alphabetical (desc)', value: 2},
|
||||||
|
{text: 'Importance', value: 3},
|
||||||
|
];
|
||||||
|
|
||||||
contentHeight: string;
|
contentHeight: string;
|
||||||
stateFilter: any = {};
|
stateFilter: any = {};
|
||||||
currentAlerts: any = [];
|
currentAlerts: any = [];
|
||||||
@ -26,10 +32,10 @@ class AlertListPanel extends PanelCtrl {
|
|||||||
show: 'current',
|
show: 'current',
|
||||||
limit: 10,
|
limit: 10,
|
||||||
stateFilter: [],
|
stateFilter: [],
|
||||||
onlyAlertsOnDashboard: false
|
onlyAlertsOnDashboard: false,
|
||||||
|
sortOrder: 1
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
constructor($scope, $injector, private $location, private backendSrv, private timeSrv, private templateSrv) {
|
constructor($scope, $injector, private $location, private backendSrv, private timeSrv, private templateSrv) {
|
||||||
super($scope, $injector);
|
super($scope, $injector);
|
||||||
@ -44,6 +50,19 @@ class AlertListPanel extends PanelCtrl {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sortResult(alerts) {
|
||||||
|
if (this.panel.sortOrder === 3) {
|
||||||
|
return _.sortBy(alerts, a => { return alertDef.alertStateSortScore[a.state]; });
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = _.sortBy(alerts, a => { return a.name.toLowerCase();});
|
||||||
|
if (this.panel.sortOrder === 2) {
|
||||||
|
result.reverse();
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
updateStateFilter() {
|
updateStateFilter() {
|
||||||
var result = [];
|
var result = [];
|
||||||
|
|
||||||
@ -104,11 +123,11 @@ class AlertListPanel extends PanelCtrl {
|
|||||||
|
|
||||||
this.backendSrv.get(`/api/alerts`, params)
|
this.backendSrv.get(`/api/alerts`, params)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
this.currentAlerts = _.map(res, al => {
|
this.currentAlerts = this.sortResult(_.map(res, al => {
|
||||||
al.stateModel = alertDef.getStateDisplayModel(al.state);
|
al.stateModel = alertDef.getStateDisplayModel(al.state);
|
||||||
al.newStateDateAgo = moment(al.newStateDate).fromNow().replace(" ago", "");
|
al.newStateDateAgo = moment(al.newStateDate).fromNow().replace(" ago", "");
|
||||||
return al;
|
return al;
|
||||||
});
|
}));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user