filter triggers by acknowledged status, #141

This commit is contained in:
Alexander Zobnin
2017-10-24 12:44:01 +03:00
parent 2b5af923d6
commit 611bd8b8ad
16 changed files with 178 additions and 44 deletions

View File

@@ -171,7 +171,6 @@
"application": {
"filter": ""
},
"countTriggers": false,
"functions": [],
"group": {
"filter": "/.*/"
@@ -182,11 +181,11 @@
"item": {
"filter": ""
},
"minSeverity": 0,
"mode": 4,
"options": {
"countTriggers": false,
"showDisabledItems": false
"triggers": {
"count": false,
"minSeverity": 0,
"acknowledged": 2
},
"refId": "A",
"target": ""
@@ -269,7 +268,6 @@
"application": {
"filter": ""
},
"countTriggers": true,
"functions": [],
"group": {
"filter": "$group"
@@ -280,10 +278,11 @@
"item": {
"filter": ""
},
"minSeverity": 3,
"mode": 4,
"options": {
"showDisabledItems": false
"triggers": {
"count": true,
"minSeverity": 3,
"acknowledged": 2
},
"refId": "A",
"target": ""

View File

@@ -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);
});

View File

@@ -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">

View File

@@ -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
}

View File

@@ -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." ||