expandItemName function moved to helperFunctions.js.
This commit is contained in:
@@ -105,7 +105,7 @@ function (angular, _, kbn) {
|
||||
if (target.itemFilter) {
|
||||
var item_pattern = new RegExp(target.itemFilter);
|
||||
return _.filter(items, function (item) {
|
||||
return item_pattern.test(self.zabbixAPI.expandItemName(item));
|
||||
return item_pattern.test(zabbixHelperSrv.expandItemName(item));
|
||||
});
|
||||
} else {
|
||||
return items;
|
||||
@@ -114,7 +114,7 @@ function (angular, _, kbn) {
|
||||
|
||||
// Filtering items
|
||||
return _.filter(items, function (item) {
|
||||
return _.contains(itemnames, self.zabbixAPI.expandItemName(item));
|
||||
return _.contains(itemnames, zabbixHelperSrv.expandItemName(item));
|
||||
});
|
||||
}
|
||||
}).then(function (items) {
|
||||
@@ -131,10 +131,10 @@ function (angular, _, kbn) {
|
||||
|
||||
if ((from < useTrendsFrom) && self.trends) {
|
||||
return self.zabbixAPI.getTrends(items, from, to)
|
||||
.then(_.bind(zabbixHelperSrv.handleTrendResponse, self, items, alias, target.scale));
|
||||
.then(_.bind(zabbixHelperSrv.handleTrendResponse, zabbixHelperSrv, items, alias, target.scale));
|
||||
} else {
|
||||
return self.zabbixAPI.getHistory(items, from, to)
|
||||
.then(_.bind(zabbixHelperSrv.handleHistoryResponse, self, items, alias, target.scale));
|
||||
.then(_.bind(zabbixHelperSrv.handleHistoryResponse, zabbixHelperSrv, items, alias, target.scale));
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -183,12 +183,11 @@ function (angular, _, kbn) {
|
||||
var template = _.object(['group', 'host', 'app', 'item'], parts);
|
||||
|
||||
// Get items
|
||||
var self = this;
|
||||
if (parts.length === 4) {
|
||||
return this.zabbixAPI.itemFindQuery(template.group, template.host, template.app)
|
||||
.then(function (result) {
|
||||
return _.map(result, function (item) {
|
||||
var itemname = self.zabbixAPI.expandItemName(item);
|
||||
var itemname = zabbixHelperSrv.expandItemName(item);
|
||||
return {
|
||||
text: itemname,
|
||||
expandable: false
|
||||
|
||||
@@ -46,7 +46,7 @@ function (angular, _) {
|
||||
var item = indexed_items[itemid];
|
||||
var series = {
|
||||
target: (item.hosts ? item.hosts[0].name+': ' : '')
|
||||
+ (alias ? alias : self.zabbixAPI.expandItemName(item)),
|
||||
+ (alias ? alias : self.expandItemName(item)),
|
||||
datapoints: _.map(history, function (p) {
|
||||
|
||||
// Value must be a number for properly work
|
||||
@@ -88,7 +88,7 @@ function (angular, _) {
|
||||
var item = indexed_items[itemid];
|
||||
var series = {
|
||||
target: (item.hosts ? item.hosts[0].name+': ' : '')
|
||||
+ (alias ? alias : self.zabbixAPI.expandItemName(item)),
|
||||
+ (alias ? alias : self.expandItemName(item)),
|
||||
datapoints: _.map(trends, function (p) {
|
||||
|
||||
// Value must be a number for properly work
|
||||
@@ -107,6 +107,28 @@ function (angular, _) {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Expand item parameters, for example:
|
||||
* CPU $2 time ($3) --> CPU system time (avg1)
|
||||
*
|
||||
* @param item: zabbix api item object
|
||||
* @return: expanded item name (string)
|
||||
*/
|
||||
this.expandItemName = function(item) {
|
||||
var name = item.name;
|
||||
var key = item.key_;
|
||||
|
||||
// extract params from key:
|
||||
// "system.cpu.util[,system,avg1]" --> ["", "system", "avg1"]
|
||||
var key_params = key.substring(key.indexOf('[') + 1, key.lastIndexOf(']')).split(',');
|
||||
|
||||
// replace item parameters
|
||||
for (var i = key_params.length; i >= 1; i--) {
|
||||
name = name.replace('$' + i, key_params[i - 1]);
|
||||
}
|
||||
return name;
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert multiple mettrics to array
|
||||
* "{metric1,metcic2,...,metricN}" --> [metric1, metcic2,..., metricN]
|
||||
|
||||
@@ -171,9 +171,9 @@ function (angular, _) {
|
||||
$scope.datasource.zabbixAPI.itemFindQuery(groups, hosts, apps).then(function (items) {
|
||||
// Show only unique item names
|
||||
var uniq_items = _.map(_.uniq(items, function (item) {
|
||||
return $scope.datasource.zabbixAPI.expandItemName(item);
|
||||
return zabbixHelperSrv.expandItemName(item);
|
||||
}), function (item) {
|
||||
return {name: $scope.datasource.zabbixAPI.expandItemName(item)};
|
||||
return {name: zabbixHelperSrv.expandItemName(item)};
|
||||
});
|
||||
$scope.metric.itemList = $scope.metric.itemList.concat(uniq_items);
|
||||
});
|
||||
|
||||
@@ -455,28 +455,6 @@ function (angular, _) {
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Expand item parameters, for example:
|
||||
* CPU $2 time ($3) --> CPU system time (avg1)
|
||||
*
|
||||
* @param item: zabbix api item object
|
||||
* @return: expanded item name (string)
|
||||
*/
|
||||
p.expandItemName = function(item) {
|
||||
var name = item.name;
|
||||
var key = item.key_;
|
||||
|
||||
// extract params from key:
|
||||
// "system.cpu.util[,system,avg1]" --> ["", "system", "avg1"]
|
||||
var key_params = key.substring(key.indexOf('[') + 1, key.lastIndexOf(']')).split(',');
|
||||
|
||||
// replace item parameters
|
||||
for (var i = key_params.length; i >= 1; i--) {
|
||||
name = name.replace('$' + i, key_params[i - 1]);
|
||||
}
|
||||
return name;
|
||||
};
|
||||
|
||||
return ZabbixAPI;
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user