Refactoring - new handleZabbixAPIResponse method.
This commit is contained in:
@@ -36,11 +36,8 @@ function (angular, _, kbn) {
|
||||
var from = kbn.parseDate(options.range.from).getTime();
|
||||
var to = kbn.parseDate(options.range.to).getTime();
|
||||
|
||||
// Need for find target alias
|
||||
var targets = options.targets;
|
||||
|
||||
// Remove undefined and hidden targets
|
||||
var displayedTargets = _.filter(targets, function (target) {
|
||||
var displayedTargets = _.filter(options.targets, function (target) {
|
||||
return (!target.hide && target.item);
|
||||
});
|
||||
|
||||
@@ -57,7 +54,15 @@ function (angular, _, kbn) {
|
||||
from = Math.ceil(from/1000);
|
||||
to = Math.ceil(to/1000);
|
||||
|
||||
var self = this;
|
||||
return this.performTimeSeriesQuery(target_items, from, to).then(function (response) {
|
||||
return self.handleZabbixAPIResponse(response, displayedTargets)
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
// Request data from Zabbix API
|
||||
ZabbixAPIDatasource.prototype.handleZabbixAPIResponse = function(response, targets) {
|
||||
/**
|
||||
* Response should be in the format:
|
||||
* data: [
|
||||
@@ -75,20 +80,12 @@ function (angular, _, kbn) {
|
||||
// Index returned datapoints by item/metric id
|
||||
var indexed_result = _.groupBy(response, 'itemid');
|
||||
|
||||
// TODO: realize correct timeseries reduce
|
||||
/*
|
||||
// Reduce timeseries to the same size for stacking and tooltip work properly
|
||||
var min_length = _.min(_.map(indexed_result, function (history) {
|
||||
return history.length;
|
||||
}));
|
||||
_.each(indexed_result, function (item) {
|
||||
item.splice(0, item.length - min_length);
|
||||
});*/
|
||||
|
||||
// Sort result as the same as targets for display
|
||||
// stacked timeseries in proper order
|
||||
// Sort result as the same as targets
|
||||
// for display stacked timeseries in proper order
|
||||
var sorted_history = _.sortBy(indexed_result, function (value, key, list) {
|
||||
return _.indexOf(_.map(target_items, 'itemid'), key);
|
||||
return _.indexOf(_.map(targets, function (target) {
|
||||
return target.item.itemid;
|
||||
}), key);
|
||||
});
|
||||
|
||||
var series = _.map(sorted_history,
|
||||
@@ -97,7 +94,6 @@ function (angular, _, kbn) {
|
||||
function (history, index) {
|
||||
return {
|
||||
// Lookup itemid:alias map
|
||||
//target: targets[itemid].alias,
|
||||
target: targets[index].alias,
|
||||
|
||||
datapoints: _.map(history, function (p) {
|
||||
@@ -112,15 +108,9 @@ function (angular, _, kbn) {
|
||||
};
|
||||
})
|
||||
return $q.when({data: series});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
/// Query methods
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
// Request data from Zabbix API
|
||||
ZabbixAPIDatasource.prototype.performZabbixAPIRequest = function(request_data) {
|
||||
var options = {
|
||||
|
||||
Reference in New Issue
Block a user