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 // Get groups
else if (parts.length === 1) { 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 _.map(result, function (hostgroup) {
return { return {
text: hostgroup.name, text: hostgroup.name,

View File

@@ -37,7 +37,7 @@ function (angular, _) {
*/ */
function setItemAlias() { function setItemAlias() {
if (!$scope.target.alias && $scope.target.item) { 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 * @param {string or array} group group names
* @return {array} array of Zabbix API hostgroup objects * @return {array} array of Zabbix API hostgroup objects
*/ */
this.findZabbixGroup = function (group) { this.getGroupByName = function (group) {
var params = { var params = {
output: ['name'], output: ['name']
searchByAny: true
}; };
if (group != '*') { if (group != '*') {
if (_.isArray(group)) {
params.filter = { params.filter = {
name: group name: group
}; };
} else {
params.search = {
name: group
};
params.searchWildcardsEnabled = true;
}
} }
return this.performZabbixAPIRequest('hostgroup.get', params); 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 * @param {string or array} hostnames hosts names
* @return {array} array of Zabbix API host objects * @return {array} array of Zabbix API host objects
*/ */
this.findZabbixHost = function (hostnames) { this.getHostByName = function (hostnames) {
var params = { var params = {
output: ['host', 'name'], output: ['host', 'name']
searchByAny: true
}; };
if (hostnames != '*') { if (hostnames != '*') {
params.filter = { params.filter = {
@@ -336,15 +345,14 @@ function (angular, _) {
/** /**
* Find applications by names * Get applications by names
* *
* @param {string or array} application applications names * @param {string or array} application applications names
* @return {array} array of Zabbix API application objects * @return {array} array of Zabbix API application objects
*/ */
this.findZabbixApp = function (application) { this.getAppByName = function (application) {
var params = { var params = {
output: ['name'], output: ['name']
searchByAny: true
} }
if (application != '*') { if (application != '*') {
params.filter = { 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 * applications
* *
* @param {string or array} groups * @param {string or array} groups
@@ -369,15 +377,15 @@ function (angular, _) {
// Get hostids from names // Get hostids from names
if (hosts && hosts != '*') { if (hosts && hosts != '*') {
promises.push(this.findZabbixHost(hosts)); promises.push(this.getHostByName(hosts));
} }
// Get groupids from names // Get groupids from names
else if (groups) { else if (groups) {
promises.push(this.findZabbixGroup(groups)); promises.push(this.getGroupByName(groups));
} }
// Get applicationids from names // Get applicationids from names
if (apps) { if (apps) {
promises.push(this.findZabbixApp(apps)); promises.push(this.getAppByName(apps));
} }
var self = this; var self = this;
@@ -416,11 +424,11 @@ function (angular, _) {
// Get hostids from names // Get hostids from names
if (hosts && hosts != '*') { if (hosts && hosts != '*') {
promises.push(this.findZabbixHost(hosts)); promises.push(this.getHostByName(hosts));
} }
// Get groupids from names // Get groupids from names
else if (groups) { else if (groups) {
promises.push(this.findZabbixGroup(groups)); promises.push(this.getGroupByName(groups));
} }
var self = this; var self = this;
@@ -450,7 +458,7 @@ function (angular, _) {
*/ */
this.hostFindQuery = function(groups) { this.hostFindQuery = function(groups) {
var self = this; var self = this;
return this.findZabbixGroup(groups).then(function (results) { return this.getGroupByName(groups).then(function (results) {
results = _.flatten(results); results = _.flatten(results);
var groupids = _.map(_.filter(results, function (object) { var groupids = _.map(_.filter(results, function (object) {
return object.groupid; return object.groupid;