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

@@ -487,7 +487,13 @@ function ZabbixAPIServiceFactory(alertSrv, zabbixAPICoreService) {
}
}, {
key: 'getHostAlerts',
value: function getHostAlerts(hostids, applicationids, minSeverity, count, timeFrom, timeTo) {
value: function getHostAlerts(hostids, applicationids, options) {
var minSeverity = options.minSeverity,
acknowledged = options.acknowledged,
count = options.count,
timeFrom = options.timeFrom,
timeTo = options.timeTo;
var params = {
output: 'extend',
hostids: hostids,
@@ -503,7 +509,7 @@ function ZabbixAPIServiceFactory(alertSrv, zabbixAPICoreService) {
selectHosts: ['host', 'name']
};
if (count) {
if (count && acknowledged !== 0 && acknowledged !== 1) {
params.countOutput = true;
}
@@ -516,7 +522,15 @@ function ZabbixAPIServiceFactory(alertSrv, zabbixAPICoreService) {
params.lastChangeTill = timeTo;
}
return this.request('trigger.get', params);
return this.request('trigger.get', params).then(function (triggers) {
if (!count || acknowledged === 0 || acknowledged === 1) {
triggers = filterTriggersByAcknowledge(triggers, acknowledged);
if (count) {
triggers = triggers.length;
}
}
return triggers;
});
}
}]);
@@ -526,6 +540,20 @@ function ZabbixAPIServiceFactory(alertSrv, zabbixAPICoreService) {
return ZabbixAPI;
}
function filterTriggersByAcknowledge(triggers, acknowledged) {
if (acknowledged === 0) {
return _lodash2.default.filter(triggers, function (trigger) {
return trigger.lastEvent.acknowledged === "0";
});
} else if (acknowledged === 1) {
return _lodash2.default.filter(triggers, function (trigger) {
return trigger.lastEvent.acknowledged === "1";
});
} else {
return triggers;
}
}
function isNotAuthorized(message) {
return message === "Session terminated, re-login, please." || message === "Not authorised." || message === "Not authorized.";
}