From 7f76984bcb48c74b17faa4ac89fa6f0608b3e5aa Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Sun, 28 Jun 2015 20:48:44 +0300 Subject: [PATCH 1/3] iss #35 - rename findZabbix functions to getByName. --- zabbix/zabbixAPIWrapper.js | 48 +++++++++++++++----------------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/zabbix/zabbixAPIWrapper.js b/zabbix/zabbixAPIWrapper.js index 8d09944..65e5242 100644 --- a/zabbix/zabbixAPIWrapper.js +++ b/zabbix/zabbixAPIWrapper.js @@ -289,42 +289,33 @@ 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; - } + params.filter = { + name: group + }; } return this.performZabbixAPIRequest('hostgroup.get', params); }; /** - * Find hosts by names + * 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 +327,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 +346,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 +359,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 +406,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 +440,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; From 73eb57ef5684680ca0f5754296ca4af72c78345c Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Mon, 29 Jun 2015 13:14:34 +0300 Subject: [PATCH 2/3] Fixed #38 - Alias don't set automatically from item name. --- zabbix/queryCtrl.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zabbix/queryCtrl.js b/zabbix/queryCtrl.js index 886255d..4f847c9 100644 --- a/zabbix/queryCtrl.js +++ b/zabbix/queryCtrl.js @@ -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; } }; From fca214ad443cbd5cff66a88f7e31c6efeeb2a6c1 Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Mon, 29 Jun 2015 13:46:01 +0300 Subject: [PATCH 3/3] iss #33 - Add searchGroup() method. --- zabbix/datasource.js | 2 +- zabbix/zabbixAPIWrapper.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/zabbix/datasource.js b/zabbix/datasource.js index 8305127..d62b75b 100644 --- a/zabbix/datasource.js +++ b/zabbix/datasource.js @@ -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, diff --git a/zabbix/zabbixAPIWrapper.js b/zabbix/zabbixAPIWrapper.js index 65e5242..eae7ea5 100644 --- a/zabbix/zabbixAPIWrapper.js +++ b/zabbix/zabbixAPIWrapper.js @@ -307,6 +307,24 @@ function (angular, _) { }; + /** + * 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 *