filter triggers by acknowledged status, #141
This commit is contained in:
@@ -362,7 +362,14 @@ class ZabbixAPIDatasource {
|
||||
if (hosts.length) {
|
||||
let hostids = _.map(hosts, 'hostid');
|
||||
let appids = _.map(apps, 'applicationid');
|
||||
return this.zabbix.getHostAlerts(hostids, appids, target.minSeverity, target.countTriggers, timeFrom, timeTo)
|
||||
let options = {
|
||||
minSeverity: target.triggers.minSeverity,
|
||||
acknowledged: target.triggers.acknowledged,
|
||||
count: target.triggers.count,
|
||||
timeFrom: timeFrom,
|
||||
timeTo: timeTo
|
||||
};
|
||||
return this.zabbix.getHostAlerts(hostids, appids, options)
|
||||
.then((triggers) => {
|
||||
return responseHandler.handleTriggersResponse(triggers, timeRange);
|
||||
});
|
||||
|
||||
@@ -123,14 +123,24 @@
|
||||
<div class="gf-form-select-wrapper width-16">
|
||||
<select class="gf-form-input"
|
||||
ng-change="ctrl.onTargetBlur()"
|
||||
ng-model="ctrl.target.minSeverity"
|
||||
ng-model="ctrl.target.triggers.minSeverity"
|
||||
ng-options="s.val as s.text for s in ctrl.triggerSeverity">
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="gf-form max-width-20" ng-show="ctrl.target.mode == editorMode.TRIGGERS">
|
||||
<label class="gf-form-label query-keyword width-8">Acknowledged</label>
|
||||
<div class="gf-form-select-wrapper width-12">
|
||||
<select class="gf-form-input"
|
||||
ng-change="ctrl.onTargetBlur()"
|
||||
ng-model="ctrl.target.triggers.acknowledged"
|
||||
ng-options="a.value as a.text for a in ctrl.ackFilters">
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<gf-form-switch class="gf-form" label="Count" ng-show="ctrl.target.mode == editorMode.TRIGGERS"
|
||||
checked="ctrl.target.countTriggers" on-change="ctrl.onTargetBlur()">
|
||||
checked="ctrl.target.triggers.count" on-change="ctrl.onTargetBlur()">
|
||||
</gf-form-switch>
|
||||
|
||||
<div class="gf-form gf-form--grow">
|
||||
|
||||
@@ -45,6 +45,12 @@ export class ZabbixQueryController extends QueryCtrl {
|
||||
{name: "Down time", property: "downtimeTime"}
|
||||
];
|
||||
|
||||
this.ackFilters = [
|
||||
{text: 'all triggers', value: 2},
|
||||
{text: 'unacknowledged', value: 0},
|
||||
{text: 'acknowledged', value: 1},
|
||||
];
|
||||
|
||||
this.triggerSeverity = c.TRIGGER_SEVERITY;
|
||||
|
||||
// Map functions for bs-typeahead
|
||||
@@ -84,8 +90,11 @@ export class ZabbixQueryController extends QueryCtrl {
|
||||
'application': { 'filter': "" },
|
||||
'item': { 'filter': "" },
|
||||
'functions': [],
|
||||
'minSeverity': 3,
|
||||
'countTriggers': true,
|
||||
'triggers': {
|
||||
'count': true,
|
||||
'minSeverity': 3,
|
||||
'acknowledged': 2
|
||||
},
|
||||
'options': {
|
||||
'showDisabledItems': false
|
||||
}
|
||||
|
||||
@@ -434,8 +434,9 @@ function ZabbixAPIServiceFactory(alertSrv, zabbixAPICoreService) {
|
||||
return this.request('trigger.get', params);
|
||||
}
|
||||
|
||||
getHostAlerts(hostids, applicationids, minSeverity, count, timeFrom, timeTo) {
|
||||
var params = {
|
||||
getHostAlerts(hostids, applicationids, options) {
|
||||
let {minSeverity, acknowledged, count, timeFrom, timeTo} = options;
|
||||
let params = {
|
||||
output: 'extend',
|
||||
hostids: hostids,
|
||||
min_severity: minSeverity,
|
||||
@@ -450,7 +451,7 @@ function ZabbixAPIServiceFactory(alertSrv, zabbixAPICoreService) {
|
||||
selectHosts: ['host', 'name']
|
||||
};
|
||||
|
||||
if (count) {
|
||||
if (count && acknowledged !== 0 && acknowledged !== 1) {
|
||||
params.countOutput = true;
|
||||
}
|
||||
|
||||
@@ -463,13 +464,32 @@ function ZabbixAPIServiceFactory(alertSrv, zabbixAPICoreService) {
|
||||
params.lastChangeTill = timeTo;
|
||||
}
|
||||
|
||||
return this.request('trigger.get', params);
|
||||
return this.request('trigger.get', params)
|
||||
.then((triggers) => {
|
||||
if (!count || acknowledged === 0 || acknowledged === 1) {
|
||||
triggers = filterTriggersByAcknowledge(triggers, acknowledged);
|
||||
if (count) {
|
||||
triggers = triggers.length;
|
||||
}
|
||||
}
|
||||
return triggers;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return ZabbixAPI;
|
||||
}
|
||||
|
||||
function filterTriggersByAcknowledge(triggers, acknowledged) {
|
||||
if (acknowledged === 0) {
|
||||
return _.filter(triggers, (trigger) => trigger.lastEvent.acknowledged === "0");
|
||||
} else if (acknowledged === 1) {
|
||||
return _.filter(triggers, (trigger) => trigger.lastEvent.acknowledged === "1");
|
||||
} else {
|
||||
return triggers;
|
||||
}
|
||||
}
|
||||
|
||||
function isNotAuthorized(message) {
|
||||
return (
|
||||
message === "Session terminated, re-login, please." ||
|
||||
|
||||
Reference in New Issue
Block a user