diff --git a/plugins/datasource-zabbix/queryProcessor.js b/plugins/datasource-zabbix/queryProcessor.js
index d28e2f4..97f128a 100644
--- a/plugins/datasource-zabbix/queryProcessor.js
+++ b/plugins/datasource-zabbix/queryProcessor.js
@@ -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) {
return self.cache.getGroups().then(function(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
*
diff --git a/plugins/datasource-zabbix/zabbixAPI.js b/plugins/datasource-zabbix/zabbixAPI.js
index f8e10e4..bdda740 100644
--- a/plugins/datasource-zabbix/zabbixAPI.js
+++ b/plugins/datasource-zabbix/zabbixAPI.js
@@ -296,49 +296,44 @@ function (angular, _) {
return this.request('service.getsla', params);
};
- p.getTriggers = function(limit, sortfield, groupids, hostids, applicationids, name) {
+ p.getTriggers = function(groupids, hostids, applicationids, showEvents) {
var params = {
output: 'extend',
- expandDescription: true,
- expandData: true,
- monitored: true,
- //only_true: true,
- filter: {
- value: 1
- },
- search : {
- description: name
- },
- searchWildcardsEnabled: false,
groupids: groupids,
hostids: hostids,
applicationids: applicationids,
- limit: limit,
- sortfield: 'lastchange',
- sortorder: 'DESC'
+ expandDescription: true,
+ expandData: true,
+ monitored: true,
+ skipDependent: true,
+ //only_true: true,
+ filter: {
+ value: showEvents
+ },
+ selectGroups: ['name'],
+ selectHosts: ['name'],
+ selectItems: ['name', 'key_', 'lastvalue'],
+ selectLastEvent: 'extend'
};
- if (sortfield) {
- params.sortfield = sortfield;
- }
-
return this.request('trigger.get', params);
};
- p.getAcknowledges = function(triggerids, from) {
+ p.getAcknowledges = function(eventids) {
var params = {
output: 'extend',
- objectids: triggerids,
- acknowledged: true,
+ eventids: eventids,
+ preservekeys: true,
select_acknowledges: 'extend',
sortfield: 'clock',
- sortorder: 'DESC',
- time_from: from
+ sortorder: 'DESC'
};
return this.request('event.get', params)
.then(function (events) {
- return _.flatten(_.map(events, 'acknowledges'));
+ return _.filter(events, function(event) {
+ return event.acknowledges.length;
+ });
});
};
diff --git a/plugins/panel-triggers/editor.html b/plugins/panel-triggers/editor.html
index c7695fe..bed41eb 100644
--- a/plugins/panel-triggers/editor.html
+++ b/plugins/panel-triggers/editor.html
@@ -7,21 +7,29 @@
Group
-
+
Host
-
+
@@ -32,22 +40,28 @@
Application
-
+
Trigger
+ class="input-large tight-form-input last"
+ ng-style="panel.triggers.trigger.style"
+ empty-to-null">
@@ -91,7 +105,7 @@
Limit triggers number to
- Show events
-