diff --git a/zabbix/datasource.js b/zabbix/datasource.js index 8dbe4cd..51d7211 100644 --- a/zabbix/datasource.js +++ b/zabbix/datasource.js @@ -25,12 +25,8 @@ function (angular, _, kbn) { this.username = datasource.meta.username; this.password = datasource.meta.password; - // Limit metrics per panel - this.limitmetrics = datasource.meta.limitmetrics || 20; - - // For testing - this.ds = datasource; - this.auth = 'testauth' + // Limit metrics per panel for templated request + this.limitmetrics = datasource.meta.limitmetrics || 50; } @@ -81,12 +77,14 @@ function (angular, _, kbn) { var hosts = hostname.match(host_pattern); // Remove hostnames from item names and then - // Extract item names + // extract item names // "hostname: itemname" --> "itemname" var delete_hostname_pattern = /(?:\[[\w\.]+\]\:\s)/g; - var itemname_pattern = /([^{},]+)/g; + var remove_brackets_pattern = /^{|}$/g; + var itemname_split_pattern = /(,(?!\s))/g; var itemnames = itemname.replace(delete_hostname_pattern, '') - .match(itemname_pattern); + .replace(remove_brackets_pattern, '') + .split(itemname_split_pattern); //var aliases = itemname.match(itemname_pattern); // Don't perform query for high number of items diff --git a/zabbix/queryCtrl.js b/zabbix/queryCtrl.js index dba67b8..116f22e 100644 --- a/zabbix/queryCtrl.js +++ b/zabbix/queryCtrl.js @@ -30,13 +30,17 @@ function (angular, _) { $scope.target.errors = validateTarget($scope.target); }; - // Take alias from item name by default + + /** + * Take alias from item name by default + */ function setItemAlias() { if (!$scope.target.alias && $scope.target.item) { $scope.target.alias = expandItemName($scope.target.item); } }; + $scope.targetBlur = function() { setItemAlias(); $scope.target.errors = validateTarget($scope.target); @@ -46,7 +50,10 @@ function (angular, _) { } }; - // Call when host group selected + + /** + * Call when host group selected + */ $scope.selectHostGroup = function() { $scope.updateHostList() $scope.updateAppList(); @@ -58,7 +65,10 @@ function (angular, _) { } }; - // Call when host selected + + /** + * Call when host selected + */ $scope.selectHost = function() { $scope.updateItemList(); $scope.updateAppList(); @@ -71,7 +81,9 @@ function (angular, _) { }; - // Call when application selected + /** + * Call when application selected + */ $scope.selectApplication = function() { $scope.updateItemList(); @@ -83,7 +95,9 @@ function (angular, _) { }; - // Call when item selected + /** + * Call when item selected + */ $scope.selectItem = function() { setItemAlias(); $scope.target.errors = validateTarget($scope.target); @@ -209,6 +223,11 @@ function (angular, _) { }; + /** + * Add templated variables to list of available metrics + * + * @param {Array} metricList List of metrics which variables add to + */ function addTemplatedVariables(metricList) { _.each(templateSrv.variables, function(variable) { metricList.push({ @@ -223,8 +242,8 @@ 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) + * @param {Object} item Zabbix item object + * @return {string} expanded item name */ function expandItemName(item) { var name = item.name;