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.metric.groupList = [{name: '*', visible_name: 'All'}];
addTemplatedVariables($scope.metric.groupList);
$scope.datasource.zabbixAPI.performHostGroupSuggestQuery().then(function (groups) { $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); $scope.metric.groupList = $scope.metric.groupList.concat(groups);
}); });
}; };
@@ -132,51 +131,54 @@ function (angular, _) {
* Update list of hosts * Update list of hosts
*/ */
$scope.updateHostList = function() { $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; var groups = $scope.target.group ? zabbixHelperSrv.splitMetrics(templateSrv.replace($scope.target.group.name)) : undefined;
$scope.datasource.zabbixAPI.hostFindQuery(groups).then(function (hosts) { if (groups) {
$scope.metric.hostList = $scope.metric.hostList.concat(hosts); $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 * 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;
$scope.datasource.zabbixAPI.appFindQuery(hosts, groups).then(function (apps) { if (groups && hosts) {
apps = _.map(_.uniq(_.map(apps, 'name')), function (appname) { $scope.datasource.zabbixAPI.appFindQuery(hosts, groups).then(function (apps) {
return {name: appname}; 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 * 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;
$scope.datasource.zabbixAPI.itemFindQuery(groups, hosts, apps).then(function (items) { if (groups && hosts && apps) {
// Show only unique item names $scope.datasource.zabbixAPI.itemFindQuery(groups, hosts, apps).then(function (items) {
var uniq_items = _.map(_.uniq(items, function (item) { // Show only unique item names
return zabbixHelperSrv.expandItemName(item); var uniq_items = _.map(_.uniq(items, function (item) {
}), function (item) { return zabbixHelperSrv.expandItemName(item);
return {name: 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); }
});
}; };
/** /**