Fixed history request for multiple value type items.
This commit is contained in:
@@ -39,6 +39,7 @@ function (angular, _, kbn) {
|
||||
// Need for find target alias
|
||||
var targets = options.targets;
|
||||
|
||||
// TODO: remove undefined targets from request
|
||||
// Check that all targets defined
|
||||
var targetsDefined = options.targets.every(function (target, index, array) {
|
||||
return target.item;
|
||||
@@ -72,9 +73,7 @@ function (angular, _, kbn) {
|
||||
*/
|
||||
|
||||
// Index returned datapoints by item/metric id
|
||||
var indexed_result = _.groupBy(response, function (history_item) {
|
||||
return history_item.itemid;
|
||||
});
|
||||
var indexed_result = _.groupBy(response, 'itemid');
|
||||
|
||||
// Reduce timeseries to the same size for stacking and tooltip work properly
|
||||
var min_length = _.min(_.map(indexed_result, function (history) {
|
||||
@@ -124,6 +123,9 @@ function (angular, _, kbn) {
|
||||
ZabbixAPIDatasource.prototype.doZabbixAPIRequest = function(request_data) {
|
||||
var options = {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
},
|
||||
url: this.url,
|
||||
data: request_data
|
||||
};
|
||||
@@ -158,14 +160,17 @@ function (angular, _, kbn) {
|
||||
* @param items: array of zabbix api item objects
|
||||
*/
|
||||
ZabbixAPIDatasource.prototype.performTimeSeriesQuery = function(items, start, end) {
|
||||
var item_ids = items.map(function (item, index, array) {
|
||||
return item.itemid;
|
||||
});
|
||||
|
||||
// TODO: if different value types passed?
|
||||
// Perform multiple api request.
|
||||
var history_type = items[0].value_type;
|
||||
// Group items by value type for separate requests
|
||||
var items_by_value_type = _.groupBy(items, 'value_type');
|
||||
|
||||
var self = this;
|
||||
var apiRequests = [];
|
||||
|
||||
// Prepare requests for each value type
|
||||
_.each(items_by_value_type, function (value, key, list) {
|
||||
var item_ids = _.map(value, 'itemid');
|
||||
var history_type = key;
|
||||
var data = {
|
||||
jsonrpc: '2.0',
|
||||
method: 'history.get',
|
||||
@@ -175,10 +180,10 @@ function (angular, _, kbn) {
|
||||
itemids: item_ids,
|
||||
sortfield: 'clock',
|
||||
sortorder: 'ASC',
|
||||
limit: this.limitmetrics,
|
||||
limit: self.limitmetrics,
|
||||
time_from: start,
|
||||
},
|
||||
auth: this.auth,
|
||||
auth: self.auth,
|
||||
id: 1
|
||||
};
|
||||
|
||||
@@ -187,7 +192,36 @@ function (angular, _, kbn) {
|
||||
data.params.time_till = end;
|
||||
}
|
||||
|
||||
return this.doZabbixAPIRequest(data);
|
||||
apiRequests.push(self.doZabbixAPIRequest(data));
|
||||
});
|
||||
|
||||
return this.handleMultipleRequest(apiRequests);
|
||||
};
|
||||
|
||||
|
||||
// Handle multiple request
|
||||
ZabbixAPIDatasource.prototype.handleMultipleRequest = function(apiRequests) {
|
||||
var history = [];
|
||||
var performedQuery = null;
|
||||
|
||||
// Build chain of api requests and put all history data into single array
|
||||
_.each(apiRequests, function (apiRequest) {
|
||||
if(!performedQuery) {
|
||||
performedQuery = apiRequest.then(function (response) {
|
||||
history = history.concat(response);
|
||||
return history;
|
||||
});
|
||||
} else {
|
||||
performedQuery = performedQuery.then(function () {
|
||||
return apiRequest.then(function (response) {
|
||||
history = history.concat(response);
|
||||
return history;
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return performedQuery;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user