iss #35 - rename findZabbix<Obj> functions to get<Obj>ByName.

This commit is contained in:
Alexander Zobnin
2015-06-28 20:48:44 +03:00
parent 58693954cf
commit 7f76984bcb

View File

@@ -289,42 +289,33 @@ 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 * 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 +327,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 +346,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 +359,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 +406,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 +440,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;