From c4df472f6c6b52e5f2a0daeb52764f3688492b2c Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Sat, 20 Jun 2015 17:35:46 +0300 Subject: [PATCH] Resolved #11 - add scale filter. --- zabbix/datasource.js | 18 ++++++++++++++---- zabbix/partials/query.editor.html | 9 +++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/zabbix/datasource.js b/zabbix/datasource.js index 436410e53..125c8cad1 100644 --- a/zabbix/datasource.js +++ b/zabbix/datasource.js @@ -110,10 +110,10 @@ function (angular, _, kbn) { if ((from < useTrendsFrom) && self.trends) { return self.getTrends(items, from, to) - .then(_.partial(self.handleTrendResponse, items)); + .then(_.partial(self.handleTrendResponse, items, target.scale)); } else { return self.performTimeSeriesQuery(items, from, to) - .then(_.partial(self.handleHistoryResponse, items)); + .then(_.partial(self.handleHistoryResponse, items, target.scale)); } } }); @@ -190,7 +190,7 @@ function (angular, _, kbn) { }; - ZabbixAPIDatasource.prototype.handleTrendResponse = function(items, trends) { + ZabbixAPIDatasource.prototype.handleTrendResponse = function(items, scale, trends) { // Group items and trends by itemid var indexed_items = _.indexBy(items, 'itemid'); @@ -204,6 +204,11 @@ function (angular, _, kbn) { // Value must be a number for properly work var value = Number(p.value_avg); + + // Apply scale + if (scale) { + value *= scale; + } return [value, p.clock * 1000]; }) }; @@ -226,7 +231,7 @@ function (angular, _, kbn) { * datapoints: [[, ], ...] * } */ - ZabbixAPIDatasource.prototype.handleHistoryResponse = function(items, history) { + ZabbixAPIDatasource.prototype.handleHistoryResponse = function(items, scale, history) { /** * Response should be in the format: * data: [ @@ -253,6 +258,11 @@ function (angular, _, kbn) { // Value must be a number for properly work var value = Number(p.value); + + // Apply scale + if (scale) { + value *= scale; + } return [value, p.clock * 1000]; }) }; diff --git a/zabbix/partials/query.editor.html b/zabbix/partials/query.editor.html index c00a77f7b..76da671bf 100644 --- a/zabbix/partials/query.editor.html +++ b/zabbix/partials/query.editor.html @@ -125,6 +125,15 @@ placeholder="Item filter (regex)" ng-blur="targetBlur()"> + +
  • + +