Trigger panel: fixed trigger filtering by group, host and app.
This commit is contained in:
@@ -28,6 +28,19 @@ function (angular, _, utils) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build trigger query in asynchronous manner
|
||||||
|
*/
|
||||||
|
this.buildTriggerQuery = function (groupFilter, hostFilter, appFilter) {
|
||||||
|
if (this.cache._initialized) {
|
||||||
|
return $q.when(self.buildTriggerQueryFromCache(groupFilter, hostFilter, appFilter));
|
||||||
|
} else {
|
||||||
|
return this.cache.refresh().then(function() {
|
||||||
|
return self.buildTriggerQueryFromCache(groupFilter, hostFilter, appFilter);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
this.filterGroups = function(groupFilter) {
|
this.filterGroups = function(groupFilter) {
|
||||||
return self.cache.getGroups().then(function(groupList) {
|
return self.cache.getGroups().then(function(groupList) {
|
||||||
return groupList;
|
return groupList;
|
||||||
@@ -309,6 +322,60 @@ function (angular, _, utils) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Build query - convert target filters to array of Zabbix items
|
||||||
|
*/
|
||||||
|
this.buildTriggerQueryFromCache = function (groupFilter, hostFilter, appFilter) {
|
||||||
|
var promises = [
|
||||||
|
this.filterGroups(groupFilter).then(function(groups) {
|
||||||
|
return _.filter(groups, function(group) {
|
||||||
|
if (utils.isRegex(groupFilter)) {
|
||||||
|
return utils.buildRegex(groupFilter).test(group.name);
|
||||||
|
} else {
|
||||||
|
return group.name === groupFilter;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
this.filterHosts(groupFilter).then(function(hosts) {
|
||||||
|
return _.filter(hosts, function(host) {
|
||||||
|
if (utils.isRegex(hostFilter)) {
|
||||||
|
return utils.buildRegex(hostFilter).test(host.name);
|
||||||
|
} else {
|
||||||
|
return host.name === hostFilter;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}),
|
||||||
|
this.filterApplications(groupFilter, hostFilter).then(function(apps) {
|
||||||
|
return _.filter(apps, function(app) {
|
||||||
|
if (utils.isRegex(appFilter)) {
|
||||||
|
return utils.buildRegex(appFilter).test(app.name);
|
||||||
|
} else {
|
||||||
|
return app.name === appFilter;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})
|
||||||
|
];
|
||||||
|
|
||||||
|
return $q.all(promises).then(function(results) {
|
||||||
|
var filteredGroups = results[0];
|
||||||
|
var filteredHosts = results[1];
|
||||||
|
var filteredApps = results[2];
|
||||||
|
var query = {};
|
||||||
|
|
||||||
|
if (appFilter) {
|
||||||
|
query.applicationids = _.flatten(_.map(filteredApps, 'applicationids'));
|
||||||
|
}
|
||||||
|
if (hostFilter) {
|
||||||
|
query.hostids = _.map(filteredHosts, 'hostid');
|
||||||
|
}
|
||||||
|
if (groupFilter) {
|
||||||
|
query.groupids = _.map(filteredGroups, 'groupid');
|
||||||
|
}
|
||||||
|
|
||||||
|
return query;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert Zabbix API history.get response to Grafana format
|
* Convert Zabbix API history.get response to Grafana format
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -296,9 +296,12 @@ function (angular, _) {
|
|||||||
return this.request('service.getsla', params);
|
return this.request('service.getsla', params);
|
||||||
};
|
};
|
||||||
|
|
||||||
p.getTriggers = function() {
|
p.getTriggers = function(groupids, hostids, applicationids) {
|
||||||
var params = {
|
var params = {
|
||||||
output: 'extend',
|
output: 'extend',
|
||||||
|
groupids: groupids,
|
||||||
|
hostids: hostids,
|
||||||
|
applicationids: applicationids,
|
||||||
expandDescription: true,
|
expandDescription: true,
|
||||||
expandData: true,
|
expandData: true,
|
||||||
monitored: true,
|
monitored: true,
|
||||||
|
|||||||
@@ -121,9 +121,16 @@ function (angular, app, _, $, config, PanelMeta) {
|
|||||||
// Load datasource
|
// Load datasource
|
||||||
return datasourceSrv.get($scope.panel.datasource).then(function (datasource) {
|
return datasourceSrv.get($scope.panel.datasource).then(function (datasource) {
|
||||||
var zabbix = datasource.zabbixAPI;
|
var zabbix = datasource.zabbixAPI;
|
||||||
|
var queryProcessor = datasource.queryProcessor;
|
||||||
// Get triggers
|
var triggerFilter = $scope.panel.triggers;
|
||||||
return zabbix.getTriggers($scope.panel.showEvents.value)
|
var buildQuery = queryProcessor.buildTriggerQuery(triggerFilter.group.filter,
|
||||||
|
triggerFilter.host.filter,
|
||||||
|
triggerFilter.application.filter);
|
||||||
|
return buildQuery.then(function(query) {
|
||||||
|
return zabbix.getTriggers(query.groupids,
|
||||||
|
query.hostids,
|
||||||
|
query.applicationids,
|
||||||
|
$scope.panel.showEvents.value)
|
||||||
.then(function(triggers) {
|
.then(function(triggers) {
|
||||||
return _.map(triggers, function (trigger) {
|
return _.map(triggers, function (trigger) {
|
||||||
var lastchange = new Date(trigger.lastchange * 1000);
|
var lastchange = new Date(trigger.lastchange * 1000);
|
||||||
@@ -190,6 +197,7 @@ function (angular, app, _, $, config, PanelMeta) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
$scope.initFilters = function () {
|
$scope.initFilters = function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user