Fixed issues with query editor after grafana update.

This commit is contained in:
Alexander Zobnin
2015-07-13 19:25:23 +03:00
parent 920e0df729
commit 9d84a3e0e8

View File

@@ -14,10 +14,10 @@ function (angular, _) {
$scope.init = function() { $scope.init = function() {
$scope.targetLetters = targetLetters; $scope.targetLetters = targetLetters;
$scope.metric = { $scope.metric = {
hostGroupList: ["Loading..."], hostGroupList: [],
hostList: ["Loading..."], hostList: [{name: '*', visible_name: 'All'}],
applicationList: ["Loading..."], applicationList: [{name: '*', visible_name: 'All'}],
itemList: ["Loading..."] itemList: [{name: 'All'}]
}; };
// Update host group, host, application and item lists // Update host group, host, application and item lists
@@ -120,10 +120,9 @@ function (angular, _) {
* Update list of host groups * Update list of host groups
*/ */
$scope.updateGroupList = function() { $scope.updateGroupList = function() {
$scope.datasource.zabbixAPI.performHostGroupSuggestQuery().then(function (groups) {
$scope.metric.groupList = [{name: '*', visible_name: 'All'}]; $scope.metric.groupList = [{name: '*', visible_name: 'All'}];
addTemplatedVariables($scope.metric.groupList); addTemplatedVariables($scope.metric.groupList);
$scope.datasource.zabbixAPI.performHostGroupSuggestQuery().then(function (groups) {
$scope.metric.groupList = $scope.metric.groupList.concat(groups); $scope.metric.groupList = $scope.metric.groupList.concat(groups);
}); });
}; };
@@ -132,42 +131,42 @@ function (angular, _) {
* Update list of hosts * Update list of hosts
*/ */
$scope.updateHostList = function() { $scope.updateHostList = function() {
var groups = $scope.target.group ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.group.name)) : undefined;
if (groups) {
$scope.datasource.zabbixAPI.hostFindQuery(groups).then(function (hosts) {
$scope.metric.hostList = [{name: '*', visible_name: 'All'}]; $scope.metric.hostList = [{name: '*', visible_name: 'All'}];
addTemplatedVariables($scope.metric.hostList); 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); $scope.metric.hostList = $scope.metric.hostList.concat(hosts);
}); });
}
}; };
/** /**
* Update list of host applications * Update list of host applications
*/ */
$scope.updateAppList = function() { $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 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 hosts = $scope.target.host ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.host.name)) : undefined;
if (groups && hosts) {
$scope.datasource.zabbixAPI.appFindQuery(hosts, groups).then(function (apps) { $scope.datasource.zabbixAPI.appFindQuery(hosts, groups).then(function (apps) {
apps = _.map(_.uniq(_.map(apps, 'name')), function (appname) { apps = _.map(_.uniq(_.map(apps, 'name')), function (appname) {
return {name: 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 * Update list of items
*/ */
$scope.updateItemList = function() { $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 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 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; var apps = $scope.target.application ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.application.name)) : undefined;
if (groups && hosts && apps) {
$scope.datasource.zabbixAPI.itemFindQuery(groups, hosts, apps).then(function (items) { $scope.datasource.zabbixAPI.itemFindQuery(groups, hosts, apps).then(function (items) {
// Show only unique item names // Show only unique item names
var uniq_items = _.map(_.uniq(items, function (item) { var uniq_items = _.map(_.uniq(items, function (item) {
@@ -175,8 +174,11 @@ function (angular, _) {
}), function (item) { }), function (item) {
return {name: zabbixHelperSrv.expandItemName(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);
}); });
}
}; };
/** /**