Merge branch 'fix-33' into develop

This commit is contained in:
Alexander Zobnin
2015-06-29 13:46:35 +03:00
3 changed files with 39 additions and 31 deletions

View File

@@ -286,7 +286,7 @@ function (angular, _, kbn) {
}
// Get groups
else if (parts.length === 1) {
return zabbix.findZabbixGroup(template.group).then(function (result) {
return zabbix.getGroupByName(template.group).then(function (result) {
return _.map(result, function (hostgroup) {
return {
text: hostgroup.name,

View File

@@ -37,7 +37,7 @@ function (angular, _) {
*/
function setItemAlias() {
if (!$scope.target.alias && $scope.target.item) {
$scope.target.alias = zabbix.expandItemName($scope.target.item);
$scope.target.alias = $scope.target.item.name;
}
};

View File

@@ -289,42 +289,51 @@ function (angular, _) {
/**
* Find groups by names
* Get groups by names
*
* @param {string or array} group group names
* @return {array} array of Zabbix API hostgroup objects
*/
this.findZabbixGroup = function (group) {
this.getGroupByName = function (group) {
var params = {
output: ['name'],
searchByAny: true
output: ['name']
};
if (group != '*') {
if (_.isArray(group)) {
params.filter = {
name: group
};
} else {
params.search = {
name: group
};
params.searchWildcardsEnabled = true;
}
}
return this.performZabbixAPIRequest('hostgroup.get', params);
};
/**
* Find hosts by names
* Search group by name.
*
* @param {string} group group name
* @return {array} groups
*/
this.searchGroup = function (group) {
var params = {
output: ['name'],
search: {
name: group
},
searchWildcardsEnabled: true
};
return this.performZabbixAPIRequest('hostgroup.get', params);
};
/**
* Get hosts by names
*
* @param {string or array} hostnames hosts names
* @return {array} array of Zabbix API host objects
*/
this.findZabbixHost = function (hostnames) {
this.getHostByName = function (hostnames) {
var params = {
output: ['host', 'name'],
searchByAny: true
output: ['host', 'name']
};
if (hostnames != '*') {
params.filter = {
@@ -336,15 +345,14 @@ function (angular, _) {
/**
* Find applications by names
* Get applications by names
*
* @param {string or array} application applications names
* @return {array} array of Zabbix API application objects
*/
this.findZabbixApp = function (application) {
this.getAppByName = function (application) {
var params = {
output: ['name'],
searchByAny: true
output: ['name']
}
if (application != '*') {
params.filter = {
@@ -356,7 +364,7 @@ function (angular, _) {
/**
* Find items belongs to passed groups, hosts and
* Get items belongs to passed groups, hosts and
* applications
*
* @param {string or array} groups
@@ -369,15 +377,15 @@ function (angular, _) {
// Get hostids from names
if (hosts && hosts != '*') {
promises.push(this.findZabbixHost(hosts));
promises.push(this.getHostByName(hosts));
}
// Get groupids from names
else if (groups) {
promises.push(this.findZabbixGroup(groups));
promises.push(this.getGroupByName(groups));
}
// Get applicationids from names
if (apps) {
promises.push(this.findZabbixApp(apps));
promises.push(this.getAppByName(apps));
}
var self = this;
@@ -416,11 +424,11 @@ function (angular, _) {
// Get hostids from names
if (hosts && hosts != '*') {
promises.push(this.findZabbixHost(hosts));
promises.push(this.getHostByName(hosts));
}
// Get groupids from names
else if (groups) {
promises.push(this.findZabbixGroup(groups));
promises.push(this.getGroupByName(groups));
}
var self = this;
@@ -450,7 +458,7 @@ function (angular, _) {
*/
this.hostFindQuery = function(groups) {
var self = this;
return this.findZabbixGroup(groups).then(function (results) {
return this.getGroupByName(groups).then(function (results) {
results = _.flatten(results);
var groupids = _.map(_.filter(results, function (object) {
return object.groupid;