Fix query editor for work with templated variables.

This commit is contained in:
Alexander Zobnin
2015-05-30 20:54:03 +03:00
parent 81f10ea6a9
commit 46c9fa90be
3 changed files with 41 additions and 74 deletions

View File

@@ -49,7 +49,7 @@ function (angular, _, kbn) {
name: target.alias
}];
return this.performTimeSeriesQuery(item, from, to).then(_.partial(
this.handleZabbixAPIResponse, alias));
this.handleHistoryResponse, alias));
} else {
// Handle templated target
@@ -73,13 +73,14 @@ function (angular, _, kbn) {
var self = this;
return $q.all(_.map(hosts, function (hostname) {
if (hosts.length > 1) {
// Select the host that the item belongs for multiple hosts request
var selectHosts = true;
}
return this.findZabbixItem(hostname, itemnames, selectHosts);
}, this)).then(function (items) {
items = _.flatten(items);
return self.performTimeSeriesQuery(items, from, to)
.then(_.partial(self.handleZabbixAPIResponse, items));
.then(_.partial(self.handleHistoryResponse, items));
});
} else {
return [];
@@ -127,7 +128,7 @@ function (angular, _, kbn) {
// Convert Zabbix API data to Grafana format
ZabbixAPIDatasource.prototype.handleZabbixAPIResponse = function(items, response) {
ZabbixAPIDatasource.prototype.handleHistoryResponse = function(items, response) {
/**
* Response should be in the format:
* data: [

View File

@@ -59,7 +59,7 @@
ng-change="selectHostGroup()"
ng-model="target.hostGroup"
bs-tooltip="target.hostGroup.name.length > 25 ? target.hostGroup.name : ''"
ng-options="hostgroup.name for hostgroup in metric.hostGroupList" >
ng-options="hostgroup.name for hostgroup in metric.groupList" >
<option value="">All</option>
</select>
<a bs-tooltip="target.errors.metric"

View File

@@ -20,20 +20,9 @@ function (angular, _) {
};
// Update host group, host, application and item lists
$scope.updateHostGroupList();
if ($scope.target.hostGroup) {
$scope.updateHostList($scope.target.hostGroup.groupid);
} else {
$scope.updateHostList();
}
if ($scope.target.host) {
$scope.updateAppList($scope.target.host.hostid);
if ($scope.target.application) {
$scope.updateItemList($scope.target.host.hostid, $scope.target.application.applicationid);
} else {
$scope.updateItemList($scope.target.host.hostid, null);
}
}
$scope.updateGroupList();
$scope.updateHostList()
$scope.updateItemList();
setItemAlias();
@@ -58,13 +47,8 @@ function (angular, _) {
// Call when host group selected
$scope.selectHostGroup = function() {
// Update host list
if ($scope.target.hostGroup) {
$scope.updateHostList($scope.target.hostGroup.groupid);
} else {
$scope.updateHostList('');
}
$scope.updateHostList()
$scope.updateAppList();
$scope.target.errors = validateTarget($scope.target);
if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) {
@@ -75,17 +59,8 @@ function (angular, _) {
// Call when host selected
$scope.selectHost = function() {
if ($scope.target.host) {
// Update item list
if ($scope.target.application) {
$scope.updateItemList($scope.target.host.hostid, $scope.target.application.applicationid);
} else {
$scope.updateItemList($scope.target.host.hostid, null);
}
// Update application list
$scope.updateAppList($scope.target.host.hostid);
}
$scope.updateItemList();
$scope.updateAppList();
$scope.target.errors = validateTarget($scope.target);
if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) {
@@ -97,13 +72,7 @@ function (angular, _) {
// Call when application selected
$scope.selectApplication = function() {
// Update item list
if ($scope.target.application) {
$scope.updateItemList($scope.target.host.hostid, $scope.target.application.applicationid);
} else {
$scope.updateItemList($scope.target.host.hostid, null);
}
$scope.updateItemList();
$scope.target.errors = validateTarget($scope.target);
if (!_.isEqual($scope.oldTarget, $scope.target) && _.isEmpty($scope.target.errors)) {
@@ -142,15 +111,15 @@ function (angular, _) {
/**
* Update list of host groups
*/
$scope.updateHostGroupList = function() {
$scope.metric.hostGroupList = [];
addTemplatedVariables($scope.metric.hostGroupList);
$scope.updateGroupList = function() {
$scope.metric.groupList = [];
addTemplatedVariables($scope.metric.groupList);
$scope.datasource.performHostGroupSuggestQuery().then(function (series) {
$scope.metric.hostGroupList = $scope.metric.hostGroupList.concat(series);
$scope.metric.groupList = $scope.metric.groupList.concat(series);
if ($scope.target.hostGroup) {
$scope.target.hostGroup = $scope.metric.hostGroupList.filter(function (item, index, array) {
$scope.target.hostGroup = $scope.metric.groupList.filter(function (item, index, array) {
// Find selected host in metric.hostList
return item.name == $scope.target.hostGroup.name;
}).pop();
@@ -162,10 +131,11 @@ function (angular, _) {
/**
* Update list of hosts
*/
$scope.updateHostList = function(groupid) {
$scope.updateHostList = function() {
$scope.metric.hostList = [];
addTemplatedVariables($scope.metric.hostList);
var groupid = $scope.target.hostGroup ? $scope.target.hostGroup.groupid: null;
$scope.datasource.performHostSuggestQuery(groupid).then(function (series) {
$scope.metric.hostList = $scope.metric.hostList.concat(series);
@@ -182,11 +152,13 @@ function (angular, _) {
/**
* Update list of host applications
*/
$scope.updateAppList = function(hostid) {
$scope.updateAppList = function() {
$scope.metric.applicationList = [];
addTemplatedVariables($scope.metric.applicationList);
$scope.datasource.performAppSuggestQuery(hostid).then(function (series) {
var hostid = $scope.target.host ? $scope.target.host.hostid : null;
var groupid = $scope.target.hostGroup ? $scope.target.hostGroup.groupid: null;
$scope.datasource.performAppSuggestQuery(hostid, groupid).then(function (series) {
$scope.metric.applicationList = $scope.metric.applicationList.concat(series);
if ($scope.target.application) {
@@ -202,13 +174,15 @@ function (angular, _) {
/**
* Update list of items
*/
$scope.updateItemList = function(hostid, applicationid) {
$scope.updateItemList = function() {
$scope.metric.itemList = [];
addTemplatedVariables($scope.metric.itemList);
// Update only if host selected
if (hostid) {
$scope.datasource.performItemSuggestQuery(hostid, applicationid).then(function (series) {
var groupids = $scope.target.hostGroup ? $scope.target.hostGroup.groupid: null;
var hostids = $scope.target.host ? $scope.target.host.hostid : null;
var applicationids = $scope.target.application ? $scope.target.application.applicationid : null;
$scope.datasource.performItemSuggestQuery(hostids, applicationids, groupids).then(function (series) {
$scope.metric.itemList = $scope.metric.itemList.concat(series);
// Expand item parameters
@@ -224,14 +198,6 @@ function (angular, _) {
}).pop();
}
});
} else {
if ($scope.target.item) {
$scope.target.item = $scope.metric.itemList.filter(function (item, index, array) {
// Find selected item in metric.hostList
return (item.name == $scope.target.item.name);
}).pop();
}
}
};