iss 35 - move expandItemName() function to zabbixAPIWrapper.js
This commit is contained in:
@@ -104,7 +104,7 @@ function (angular, _, kbn) {
|
||||
if (target.itemFilter) {
|
||||
var item_pattern = new RegExp(target.itemFilter);
|
||||
return _.filter(items, function (item) {
|
||||
return item_pattern.test(expandItemName(item));
|
||||
return item_pattern.test(zabbix.expandItemName(item));
|
||||
});
|
||||
} else {
|
||||
return items;
|
||||
@@ -113,7 +113,7 @@ function (angular, _, kbn) {
|
||||
|
||||
// Filtering items
|
||||
return _.filter(items, function (item) {
|
||||
return _.contains(itemnames, expandItemName(item));
|
||||
return _.contains(itemnames, zabbix.expandItemName(item));
|
||||
});
|
||||
}
|
||||
}).then(function (items) {
|
||||
@@ -152,7 +152,7 @@ function (angular, _, kbn) {
|
||||
return $q.when(_.map(grouped_history, function (trends, itemid) {
|
||||
var item = indexed_items[itemid];
|
||||
var series = {
|
||||
target: (item.hosts ? item.hosts[0].name+': ' : '') + (alias ? alias : expandItemName(item)),
|
||||
target: (item.hosts ? item.hosts[0].name+': ' : '') + (alias ? alias : zabbix.expandItemName(item)),
|
||||
datapoints: _.map(trends, function (p) {
|
||||
|
||||
// Value must be a number for properly work
|
||||
@@ -206,7 +206,7 @@ function (angular, _, kbn) {
|
||||
return $q.when(_.map(grouped_history, function (history, itemid) {
|
||||
var item = indexed_items[itemid];
|
||||
var series = {
|
||||
target: (item.hosts ? item.hosts[0].name+': ' : '') + (alias ? alias : expandItemName(item)),
|
||||
target: (item.hosts ? item.hosts[0].name+': ' : '') + (alias ? alias : zabbix.expandItemName(item)),
|
||||
datapoints: _.map(history, function (p) {
|
||||
|
||||
// Value must be a number for properly work
|
||||
@@ -252,9 +252,9 @@ function (angular, _, kbn) {
|
||||
|
||||
// Get items
|
||||
if (parts.length === 4) {
|
||||
return this.itemFindQuery(template.group, template.host, template.app).then(function (result) {
|
||||
return zabbix.itemFindQuery(template.group, template.host, template.app).then(function (result) {
|
||||
return _.map(result, function (item) {
|
||||
var itemname = expandItemName(item)
|
||||
var itemname = zabbix.expandItemName(item)
|
||||
return {
|
||||
text: itemname,
|
||||
expandable: false
|
||||
@@ -264,7 +264,7 @@ function (angular, _, kbn) {
|
||||
}
|
||||
// Get applications
|
||||
else if (parts.length === 3) {
|
||||
return this.appFindQuery(template.host, template.group).then(function (result) {
|
||||
return zabbix.appFindQuery(template.host, template.group).then(function (result) {
|
||||
return _.map(result, function (app) {
|
||||
return {
|
||||
text: app.name,
|
||||
@@ -275,7 +275,7 @@ function (angular, _, kbn) {
|
||||
}
|
||||
// Get hosts
|
||||
else if (parts.length === 2) {
|
||||
return this.hostFindQuery(template.group).then(function (result) {
|
||||
return zabbix.hostFindQuery(template.group).then(function (result) {
|
||||
return _.map(result, function (host) {
|
||||
return {
|
||||
text: host.name,
|
||||
@@ -286,7 +286,7 @@ function (angular, _, kbn) {
|
||||
}
|
||||
// Get groups
|
||||
else if (parts.length === 1) {
|
||||
return this.findZabbixGroup(template.group).then(function (result) {
|
||||
return zabbix.findZabbixGroup(template.group).then(function (result) {
|
||||
return _.map(result, function (hostgroup) {
|
||||
return {
|
||||
text: hostgroup.name,
|
||||
@@ -379,29 +379,6 @@ function splitMetrics(metrics) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Expand item parameters, for example:
|
||||
* CPU $2 time ($3) --> CPU system time (avg1)
|
||||
*
|
||||
* @param item: zabbix api item object
|
||||
* @return: expanded item name (string)
|
||||
*/
|
||||
function expandItemName(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 Date object to local time in format
|
||||
* YYYY-MM-DD HH:mm:ss
|
||||
|
||||
@@ -37,7 +37,7 @@ function (angular, _) {
|
||||
*/
|
||||
function setItemAlias() {
|
||||
if (!$scope.target.alias && $scope.target.item) {
|
||||
$scope.target.alias = expandItemName($scope.target.item);
|
||||
$scope.target.alias = zabbix.expandItemName($scope.target.item);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -184,9 +184,9 @@ function (angular, _) {
|
||||
zabbix.itemFindQuery(groups, hosts, apps).then(function (items) {
|
||||
// Show only unique item names
|
||||
var uniq_items = _.map(_.uniq(items, function (item) {
|
||||
return expandItemName(item);
|
||||
return zabbix.expandItemName(item);
|
||||
}), function (item) {
|
||||
return {name: expandItemName(item)}
|
||||
return {name: zabbix.expandItemName(item)}
|
||||
});
|
||||
$scope.metric.itemList = $scope.metric.itemList.concat(uniq_items);
|
||||
});
|
||||
@@ -208,31 +208,6 @@ function (angular, _) {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Expand item parameters, for example:
|
||||
* CPU $2 time ($3) --> CPU system time (avg1)
|
||||
*
|
||||
* @param {Object} item Zabbix item object
|
||||
* @return {string} expanded item name
|
||||
*/
|
||||
function expandItemName(item) {
|
||||
var name = item.name;
|
||||
var key = item.key_;
|
||||
|
||||
if (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;
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////
|
||||
// VALIDATION
|
||||
//////////////////////////////
|
||||
|
||||
@@ -434,5 +434,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;
|
||||
}
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user