Added methods for getting trend from different api types. Added some

hacks for getting applications from different apis.
This commit is contained in:
Alexander Zobnin
2016-02-02 14:45:03 +03:00
parent 5f0f79da0f
commit fa10d76e2b
3 changed files with 34 additions and 3 deletions

View File

@@ -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 {

View File

@@ -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',

View File

@@ -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'))
};
});
}