This commit is contained in:
bergquist 2016-09-14 14:12:19 +02:00
parent d0f9623037
commit 9dd8b3b408
3 changed files with 62 additions and 35 deletions

View File

@ -29,12 +29,16 @@ func ValidateOrgAlert(c *middleware.Context) {
func GetAlerts(c *middleware.Context) Response { func GetAlerts(c *middleware.Context) Response {
query := models.GetAlertsQuery{ query := models.GetAlertsQuery{
OrgId: c.OrgId, OrgId: c.OrgId,
State: c.QueryStrings("state"),
DashboardId: c.QueryInt64("dashboardId"), DashboardId: c.QueryInt64("dashboardId"),
PanelId: c.QueryInt64("panelId"), PanelId: c.QueryInt64("panelId"),
Limit: c.QueryInt64("limit"), Limit: c.QueryInt64("limit"),
} }
states := c.QueryStrings("state")
if len(states) > 0 {
query.State = states
}
if err := bus.Dispatch(&query); err != nil { if err := bus.Dispatch(&query); err != nil {
return ApiError(500, "List alerts failed", err) return ApiError(500, "List alerts failed", err)
} }

View File

@ -11,26 +11,22 @@
<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" /> <input type="text" class="gf-form-input max-width-15" ng-model="ctrl.panel.limit" />
</div> </div>
<div class="gf-form">
<span class="gf-form-label width-8">With state</span>
<div class="gf-form-select-wrapper max-width-15">
<select class="gf-form-input" ng-model="ctrl.panel.stateFilter" ng-options="f as f for f in ctrl.alertStates" ng-change="ctrl.onRender()"></select>
</div>
</div>
</div> </div>
<div class="section gf-form-group">
<h5 class="section-heading">State filter</h5>
<gf-form-switch class="gf-form" label="Ok" label-class="width-10" checked="ctrl.stateFilter['ok']" on-change="ctrl.updateStateFilter()"></gf-form-switch>
<gf-form-switch class="gf-form" label="Paused" label-class="width-10" checked="ctrl.stateFilter['paused']" on-change="ctrl.updateStateFilter()"></gf-form-switch>
<gf-form-switch class="gf-form" label="No data" label-class="width-10" checked="ctrl.stateFilter['no_data']" on-change="ctrl.updateStateFilter()"></gf-form-switch>
<gf-form-switch class="gf-form" label="Execution error" label-class="width-10" checked="ctrl.stateFilter['execution_error']" on-change="ctrl.updateStateFilter()"></gf-form-switch>
<gf-form-switch class="gf-form" label="Alerting" label-class="width-10" checked="ctrl.stateFilter['alerting']" on-change="ctrl.updateStateFilter()"></gf-form-switch>
</div>
<div class="section gf-form-group" ng-if="ctrl.panel.show == 'changes'"> <div class="section gf-form-group" ng-if="ctrl.panel.show == 'changes'">
<h5 class="section-heading">Search options</h5> <!-- <h5 class="section-heading">Search options</h5> -->
<div class="gf-form">
<span class="gf-form-label width-8">Timerange from</span>
<input type="text" placeholder="6h" class="gf-form-input max-width-4" ng-model="ctrl.panel.since" />
</div>
<div class="gf-form">
<gf-form-switch class="gf-form" label="Setting" label-class="width-8" checked="ctrl.panel.setting" on-change="ctrl.render()"></gf-form-switch>
</div>
</div> </div>
<div class="section gf-form-group" ng-if="ctrl.panel.show == 'current'"> <div class="section gf-form-group" ng-if="ctrl.panel.show == 'current'">
<h5 class="section-heading">Current state</h5> <!-- <h5 class="section-heading">Current state</h5> -->
</div> </div>
</div> </div>

View File

@ -4,9 +4,11 @@ import _ from 'lodash';
import moment from 'moment'; import moment from 'moment';
import alertDef from '../../../features/alerting/alert_def'; import alertDef from '../../../features/alerting/alert_def';
import config from 'app/core/config'; import config from 'app/core/config';
//import * as dateMath from 'app/core/utils/datemath';
import {PanelCtrl} from 'app/plugins/sdk'; import {PanelCtrl} from 'app/plugins/sdk';
import * as rangeUtil from 'app/core/utils/rangeutil';
import * as dateMath from 'app/core/utils/datemath';
class AlertListPanel extends PanelCtrl { class AlertListPanel extends PanelCtrl {
static templateUrl = 'module.html'; static templateUrl = 'module.html';
@ -15,25 +17,41 @@ class AlertListPanel extends PanelCtrl {
{text: 'Recent statechanges', value: 'changes'} {text: 'Recent statechanges', value: 'changes'}
]; ];
alertStates = [ 'all', 'ok', 'alerting', 'paused', 'no_data', 'execution_error' ]; stateFilter: any = {};
currentAlerts: any = []; currentAlerts: any = [];
alertHistory: any = []; alertHistory: any = [];
// Set and populate defaults // Set and populate defaults
panelDefaults = { panelDefaults = {
show: 'current', show: 'current',
limit: 10, limit: 10,
stateFilter: 'all' stateFilter: []
}; };
/** @ngInject */ /** @ngInject */
constructor($scope, $injector, private $location, private backendSrv) { constructor($scope, $injector, private $location, private backendSrv, private timeSrv, private templateSrv) {
super($scope, $injector); super($scope, $injector);
_.defaults(this.panel, this.panelDefaults); _.defaults(this.panel, this.panelDefaults);
this.events.on('init-edit-mode', this.onInitEditMode.bind(this)); this.events.on('init-edit-mode', this.onInitEditMode.bind(this));
this.events.on('render', this.onRender.bind(this)); this.events.on('render', this.onRender.bind(this));
this.events.on('refresh', this.onRender.bind(this)); this.events.on('refresh', this.onRender.bind(this));
for (let key in this.panel.stateFilter) {
this.stateFilter[this.panel.stateFilter[key]] = true;
}
}
updateStateFilter() {
var result = [];
for (let key in this.stateFilter) {
if (this.stateFilter[key]) {
result.push(key);
}
}
this.panel.stateFilter = result;
this.onRender();
} }
onRender() { onRender() {
@ -50,22 +68,27 @@ class AlertListPanel extends PanelCtrl {
var params: any = { var params: any = {
limit: this.panel.limit, limit: this.panel.limit,
type: 'alert', type: 'alert',
newState: this.panel.stateFilter
}; };
if (this.panel.stateFilter !== "all") { //date.unix();i
params.newState = this.panel.stateFilter;
}
/*
var since = this.panel.since;
if (since !== undefined && since !== "" && since !== null) {
var t = this.dashboard.time;
var now = (new Date()).getTime();
params.to = t.to;
//this.range = this.timeSrv.timeRange(); this.panel.since = '12h';
params.from = dateMath.parseDateMath("1m", t.from, false); if (this.panel.since) {
var range = this.timeSrv.timeRange();
//var timeShiftInterpolated = this.panel.since;
var timeShiftInterpolated = this.templateSrv.replace(this.panel.since, this.panel.scopedVars);
var timeShiftInfo = rangeUtil.describeTextRange(timeShiftInterpolated);
var timeShift = '-' + timeShiftInterpolated;
//params.from = dateMath.parseDateMath(timeShift, range.from, false).unix() * 1000;
params.from = dateMath.parseDateMath(timeShift, moment((new Date()).getTime()), true).unix() * 1000;
//params.to = dateMath.parseDateMath(timeShift, range.to, true).unix() * 1000;
params.to = (new Date()).getTime();
} }
*/
console.log(params.from, params.to);
this.backendSrv.get(`/api/annotations`, params) this.backendSrv.get(`/api/annotations`, params)
.then(res => { .then(res => {
this.alertHistory = _.map(res, al => { this.alertHistory = _.map(res, al => {
@ -78,7 +101,11 @@ class AlertListPanel extends PanelCtrl {
} }
getCurrentAlertState() { getCurrentAlertState() {
this.backendSrv.get(`/api/alerts`) var params: any = {
state: this.panel.stateFilter
};
this.backendSrv.get(`/api/alerts`, params)
.then(res => { .then(res => {
this.currentAlerts = _.map(res, al => { this.currentAlerts = _.map(res, al => {
al.stateModel = alertDef.getStateDisplayModel(al.state); al.stateModel = alertDef.getStateDisplayModel(al.state);