From fa10d76e2b5278b62843a0f1cb82ef197f384fc4 Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Tue, 2 Feb 2016 14:45:03 +0300 Subject: [PATCH] Added methods for getting trend from different api types. Added some hacks for getting applications from different apis. --- plugins/datasource-zabbix/datasource.js | 2 +- plugins/datasource-zabbix/zabbixAPI.js | 29 +++++++++++++++++++++++- plugins/datasource-zabbix/zabbixCache.js | 6 ++++- 3 files changed, 34 insertions(+), 3 deletions(-) diff --git a/plugins/datasource-zabbix/datasource.js b/plugins/datasource-zabbix/datasource.js index 8ca918a..6417b7e 100644 --- a/plugins/datasource-zabbix/datasource.js +++ b/plugins/datasource-zabbix/datasource.js @@ -138,7 +138,7 @@ function (angular, _, dateMath, utils, metricFunctions) { // Use trends var valueType = target.downsampleFunction ? target.downsampleFunction.value : "avg"; - getHistory = self.zabbixAPI.getTrends(items, from, to).then(function(history) { + getHistory = self.zabbixAPI.getTrend(items, from, to).then(function(history) { return self.queryProcessor.handleTrends(history, addHostName, valueType); }); } else { diff --git a/plugins/datasource-zabbix/zabbixAPI.js b/plugins/datasource-zabbix/zabbixAPI.js index 098e097..f8e10e4 100644 --- a/plugins/datasource-zabbix/zabbixAPI.js +++ b/plugins/datasource-zabbix/zabbixAPI.js @@ -143,6 +143,9 @@ function (angular, _) { var params = { output: ['name'], sortfield: 'name', + + // Hack for supporting different apis (2.2 vs 2.4 vs 3.0) + selectHost: [], selectHosts: [] }; @@ -223,7 +226,7 @@ function (angular, _) { * @param {Number} time_till Time in seconds * @return {Array} Array of Zabbix trend objects */ - p.getTrends = function(items, time_from, time_till) { + p.getTrend_ZBXNEXT1193 = function(items, time_from, time_till) { var self = this; // Group items by value type @@ -250,6 +253,30 @@ function (angular, _) { })).then(_.flatten); }; + p.getTrend_30 = function(items, time_from, time_till, value_type) { + var self = this; + var itemids = _.map(items, 'itemid'); + + var params = { + output: ["itemid", + "clock", + value_type + ], + itemids: itemids, + time_from: time_from + }; + + // Relative queries (e.g. last hour) don't include an end time + if (time_till) { + params.time_till = time_till; + } + + return self.request('trend.get', params); + }; + + p.getTrend = p.getTrend_ZBXNEXT1193; + //p.getTrend = p.getTrend_30; + p.getITService = function(/* optional */ serviceids) { var params = { output: 'extend', diff --git a/plugins/datasource-zabbix/zabbixCache.js b/plugins/datasource-zabbix/zabbixCache.js index 1806ec5..abe4fe3 100644 --- a/plugins/datasource-zabbix/zabbixCache.js +++ b/plugins/datasource-zabbix/zabbixCache.js @@ -187,10 +187,14 @@ function (angular, _, utils) { */ function convertApplications(applications) { return _.map(_.groupBy(applications, 'name'), function(value, key) { + + // Hack for supporting different apis (2.2 vs 2.4 vs 3.0) + var hostField = value['hosts'] ? 'hosts' : 'host'; + return { name: key, applicationids: _.map(value, 'applicationid'), - hosts: _.uniq(_.map(_.flatten(value, 'hosts'), 'hostid')) + hosts: _.uniq(_.map(_.flatten(value, hostField), 'hostid')) }; }); }