From 9d84a3e0e821822834af7d75c354dccc682e0f07 Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Mon, 13 Jul 2015 19:25:23 +0300 Subject: [PATCH] Fixed issues with query editor after grafana update. --- zabbix/queryCtrl.js | 66 +++++++++++++++++++++++---------------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/zabbix/queryCtrl.js b/zabbix/queryCtrl.js index 053d4f4..0a02a58 100644 --- a/zabbix/queryCtrl.js +++ b/zabbix/queryCtrl.js @@ -14,10 +14,10 @@ function (angular, _) { $scope.init = function() { $scope.targetLetters = targetLetters; $scope.metric = { - hostGroupList: ["Loading..."], - hostList: ["Loading..."], - applicationList: ["Loading..."], - itemList: ["Loading..."] + hostGroupList: [], + hostList: [{name: '*', visible_name: 'All'}], + applicationList: [{name: '*', visible_name: 'All'}], + itemList: [{name: 'All'}] }; // Update host group, host, application and item lists @@ -120,10 +120,9 @@ function (angular, _) { * Update list of host groups */ $scope.updateGroupList = function() { - $scope.metric.groupList = [{name: '*', visible_name: 'All'}]; - addTemplatedVariables($scope.metric.groupList); - $scope.datasource.zabbixAPI.performHostGroupSuggestQuery().then(function (groups) { + $scope.metric.groupList = [{name: '*', visible_name: 'All'}]; + addTemplatedVariables($scope.metric.groupList); $scope.metric.groupList = $scope.metric.groupList.concat(groups); }); }; @@ -132,51 +131,54 @@ function (angular, _) { * Update list of hosts */ $scope.updateHostList = function() { - $scope.metric.hostList = [{name: '*', visible_name: 'All'}]; - addTemplatedVariables($scope.metric.hostList); - var groups = $scope.target.group ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.group.name)) : undefined; - $scope.datasource.zabbixAPI.hostFindQuery(groups).then(function (hosts) { - $scope.metric.hostList = $scope.metric.hostList.concat(hosts); - }); + if (groups) { + $scope.datasource.zabbixAPI.hostFindQuery(groups).then(function (hosts) { + $scope.metric.hostList = [{name: '*', visible_name: 'All'}]; + addTemplatedVariables($scope.metric.hostList); + $scope.metric.hostList = $scope.metric.hostList.concat(hosts); + }); + } }; /** * Update list of host applications */ $scope.updateAppList = function() { - $scope.metric.applicationList = [{name: '*', visible_name: 'All'}]; - addTemplatedVariables($scope.metric.applicationList); - var groups = $scope.target.group ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.group.name)) : undefined; var hosts = $scope.target.host ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.host.name)) : undefined; - $scope.datasource.zabbixAPI.appFindQuery(hosts, groups).then(function (apps) { - apps = _.map(_.uniq(_.map(apps, 'name')), function (appname) { - return {name: appname}; + if (groups && hosts) { + $scope.datasource.zabbixAPI.appFindQuery(hosts, groups).then(function (apps) { + apps = _.map(_.uniq(_.map(apps, 'name')), function (appname) { + return {name: appname}; + }); + $scope.metric.applicationList = [{name: '*', visible_name: 'All'}]; + addTemplatedVariables($scope.metric.applicationList); + $scope.metric.applicationList = $scope.metric.applicationList.concat(apps); }); - $scope.metric.applicationList = $scope.metric.applicationList.concat(apps); - }); + } }; /** * Update list of items */ $scope.updateItemList = function() { - $scope.metric.itemList = [{name: 'All'}]; - addTemplatedVariables($scope.metric.itemList); - var groups = $scope.target.group ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.group.name)) : undefined; var hosts = $scope.target.host ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.host.name)) : undefined; var apps = $scope.target.application ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.application.name)) : undefined; - $scope.datasource.zabbixAPI.itemFindQuery(groups, hosts, apps).then(function (items) { - // Show only unique item names - var uniq_items = _.map(_.uniq(items, function (item) { - return zabbixHelperSrv.expandItemName(item); - }), function (item) { - return {name: zabbixHelperSrv.expandItemName(item)}; + if (groups && hosts && apps) { + $scope.datasource.zabbixAPI.itemFindQuery(groups, hosts, apps).then(function (items) { + // Show only unique item names + var uniq_items = _.map(_.uniq(items, function (item) { + return zabbixHelperSrv.expandItemName(item); + }), function (item) { + return {name: zabbixHelperSrv.expandItemName(item)}; + }); + $scope.metric.itemList = [{name: 'All'}]; + addTemplatedVariables($scope.metric.itemList); + $scope.metric.itemList = $scope.metric.itemList.concat(uniq_items); }); - $scope.metric.itemList = $scope.metric.itemList.concat(uniq_items); - }); + } }; /**