Improve metrics filtering in query editor.

This commit is contained in:
Alexander Zobnin
2015-06-09 11:58:55 +03:00
parent ffd4573efa
commit d9c08ca439
3 changed files with 27 additions and 27 deletions

View File

@@ -48,11 +48,11 @@ function (angular, _, kbn) {
var promises = _.map(options.targets, function(target) { var promises = _.map(options.targets, function(target) {
// Remove undefined and hidden targets // Remove undefined and hidden targets
if (target.hide) { if (target.hide || !target.group || !target.host || !target.application || !target.item) {
return []; return [];
} }
var groupname = target.hostGroup ? templateSrv.replace(target.hostGroup.name) : undefined; var groupname = target.group ? templateSrv.replace(target.group.name) : undefined;
var hostname = target.host ? templateSrv.replace(target.host.name) : undefined; var hostname = target.host ? templateSrv.replace(target.host.name) : undefined;
var appname = target.application ? templateSrv.replace(target.application.name) : undefined; var appname = target.application ? templateSrv.replace(target.application.name) : undefined;
var itemname = target.item ? templateSrv.replace(target.item.name) : undefined; var itemname = target.item ? templateSrv.replace(target.item.name) : undefined;
@@ -79,7 +79,7 @@ function (angular, _, kbn) {
var self = this; var self = this;
return this.itemFindQuery(groups, hosts, apps) return this.itemFindQuery(groups, hosts, apps)
.then(function (items) { .then(function (items) {
if (itemnames.length) { if (itemnames != 'All') {
return _.filter(items, function (item) { return _.filter(items, function (item) {
return _.contains(itemnames, expandItemName(item)); return _.contains(itemnames, expandItemName(item));
}); });
@@ -499,11 +499,11 @@ function (angular, _, kbn) {
promises.push(this.findZabbixHost(hosts)); promises.push(this.findZabbixHost(hosts));
} }
// Get groupids from names // Get groupids from names
else if (groups && groups != '*') { else if (groups) {
promises.push(this.findZabbixGroup(groups)); promises.push(this.findZabbixGroup(groups));
} }
// Get applicationids from names // Get applicationids from names
if (apps && apps != '*') { if (apps) {
promises.push(this.findZabbixApp(apps)); promises.push(this.findZabbixApp(apps));
} }
@@ -515,7 +515,7 @@ function (angular, _, kbn) {
return object.groupid; return object.groupid;
}), 'groupid'); }), 'groupid');
} }
if (hosts) { if (hosts && hosts != '*') {
var hostids = _.map(_.filter(results, function (object) { var hostids = _.map(_.filter(results, function (object) {
return object.hostid; return object.hostid;
}), 'hostid'); }), 'hostid');
@@ -539,7 +539,7 @@ function (angular, _, kbn) {
promises.push(this.findZabbixHost(hosts)); promises.push(this.findZabbixHost(hosts));
} }
// Get groupids from names // Get groupids from names
else if (groups && groups != '*') { else if (groups) {
promises.push(this.findZabbixGroup(groups)); promises.push(this.findZabbixGroup(groups));
} }
@@ -551,7 +551,7 @@ function (angular, _, kbn) {
return object.groupid; return object.groupid;
}), 'groupid'); }), 'groupid');
} }
if (hosts) { if (hosts && hosts != '*') {
var hostids = _.map(_.filter(results, function (object) { var hostids = _.map(_.filter(results, function (object) {
return object.hostid; return object.hostid;
}), 'hostid'); }), 'hostid');

View File

@@ -57,10 +57,10 @@
<select style="width: 10em" <select style="width: 10em"
class="tight-form-input input-small" class="tight-form-input input-small"
ng-change="selectHostGroup()" ng-change="selectHostGroup()"
ng-model="target.hostGroup" ng-model="target.group"
bs-tooltip="target.hostGroup.name.length > 25 ? target.hostGroup.name : ''" bs-tooltip="target.group.name.length > 25 ? target.group.name : ''"
ng-options="hostgroup.name for hostgroup in metric.groupList" > ng-options="group.visible_name ? group.visible_name : group.name for group in metric.groupList" >
<option value="">All</option> <option value="">-- Select host group --</option>
</select> </select>
<a bs-tooltip="target.errors.metric" <a bs-tooltip="target.errors.metric"
style="color: rgb(229, 189, 28)" style="color: rgb(229, 189, 28)"
@@ -75,8 +75,8 @@
ng-change="selectHost()" ng-change="selectHost()"
ng-model="target.host" ng-model="target.host"
bs-tooltip="target.host.name.length > 25 ? target.host.name : ''" bs-tooltip="target.host.name.length > 25 ? target.host.name : ''"
ng-options="host.name for host in metric.hostList" > ng-options="host.visible_name ? host.visible_name : host.name for host in metric.hostList" >
<option value="">-- select host --</option> <option value="">-- Select host --</option>
</select> </select>
<a bs-tooltip="target.errors.metric" <a bs-tooltip="target.errors.metric"
style="color: rgb(229, 189, 28)" style="color: rgb(229, 189, 28)"
@@ -91,8 +91,8 @@
ng-change="selectApplication()" ng-change="selectApplication()"
ng-model="target.application" ng-model="target.application"
bs-tooltip="target.application.name.length > 15 ? target.application.name : ''" bs-tooltip="target.application.name.length > 15 ? target.application.name : ''"
ng-options="app.name for app in metric.applicationList" > ng-options="app.visible_name ? app.visible_name : app.name for app in metric.applicationList" >
<option value="">All</option> <option value="">-- Select application --</option>
</select> </select>
<a bs-tooltip="target.errors.metric" <a bs-tooltip="target.errors.metric"
style="color: rgb(229, 189, 28)" style="color: rgb(229, 189, 28)"
@@ -108,7 +108,7 @@
ng-model="target.item" ng-model="target.item"
bs-tooltip="target.name.length > 30 ? target.name : ''" bs-tooltip="target.name.length > 30 ? target.name : ''"
ng-options="item.name for item in metric.itemList" > ng-options="item.name for item in metric.itemList" >
<option value="">--select item--</option> <option value="">-- Select item --</option>
</select> </select>
<a bs-tooltip="target.errors.metric" <a bs-tooltip="target.errors.metric"
style="color: rgb(229, 189, 28)" style="color: rgb(229, 189, 28)"

View File

@@ -128,16 +128,16 @@ function (angular, _) {
* Update list of host groups * Update list of host groups
*/ */
$scope.updateGroupList = function() { $scope.updateGroupList = function() {
$scope.metric.groupList = []; $scope.metric.groupList = [{name: '*', visible_name: 'All'}];
addTemplatedVariables($scope.metric.groupList); addTemplatedVariables($scope.metric.groupList);
$scope.datasource.performHostGroupSuggestQuery().then(function (series) { $scope.datasource.performHostGroupSuggestQuery().then(function (series) {
$scope.metric.groupList = $scope.metric.groupList.concat(series); $scope.metric.groupList = $scope.metric.groupList.concat(series);
if ($scope.target.hostGroup) { if ($scope.target.group) {
$scope.target.hostGroup = $scope.metric.groupList.filter(function (item, index, array) { $scope.target.group = $scope.metric.groupList.filter(function (item, index, array) {
// Find selected host in metric.hostList // Find selected host in metric.hostList
return item.name == $scope.target.hostGroup.name; return item.name == $scope.target.group.name;
}).pop(); }).pop();
} }
}); });
@@ -148,10 +148,10 @@ function (angular, _) {
* Update list of hosts * Update list of hosts
*/ */
$scope.updateHostList = function() { $scope.updateHostList = function() {
$scope.metric.hostList = []; $scope.metric.hostList = [{name: '*', visible_name: 'All'}];
addTemplatedVariables($scope.metric.hostList); addTemplatedVariables($scope.metric.hostList);
var groups = $scope.target.hostGroup ? splitMetrics(templateSrv.replace($scope.target.hostGroup.name)) : undefined; var groups = $scope.target.group ? splitMetrics(templateSrv.replace($scope.target.group.name)) : undefined;
$scope.datasource.hostFindQuery(groups).then(function (hosts) { $scope.datasource.hostFindQuery(groups).then(function (hosts) {
$scope.metric.hostList = $scope.metric.hostList.concat(hosts); $scope.metric.hostList = $scope.metric.hostList.concat(hosts);
@@ -169,10 +169,10 @@ function (angular, _) {
* Update list of host applications * Update list of host applications
*/ */
$scope.updateAppList = function() { $scope.updateAppList = function() {
$scope.metric.applicationList = []; $scope.metric.applicationList = [{name: '*', visible_name: 'All'}];
addTemplatedVariables($scope.metric.applicationList); addTemplatedVariables($scope.metric.applicationList);
var groups = $scope.target.hostGroup ? splitMetrics(templateSrv.replace($scope.target.hostGroup.name)) : undefined; var groups = $scope.target.group ? splitMetrics(templateSrv.replace($scope.target.group.name)) : undefined;
var hosts = $scope.target.host ? splitMetrics(templateSrv.replace($scope.target.host.name)) : undefined; var hosts = $scope.target.host ? splitMetrics(templateSrv.replace($scope.target.host.name)) : undefined;
$scope.datasource.appFindQuery(hosts, groups).then(function (apps) { $scope.datasource.appFindQuery(hosts, groups).then(function (apps) {
// TODO: work with app names, not objects // TODO: work with app names, not objects
@@ -195,10 +195,10 @@ function (angular, _) {
* Update list of items * Update list of items
*/ */
$scope.updateItemList = function() { $scope.updateItemList = function() {
$scope.metric.itemList = []; $scope.metric.itemList = [{name: 'All'}];;
addTemplatedVariables($scope.metric.itemList); addTemplatedVariables($scope.metric.itemList);
var groups = $scope.target.hostGroup ? splitMetrics(templateSrv.replace($scope.target.hostGroup.name)) : undefined; var groups = $scope.target.group ? splitMetrics(templateSrv.replace($scope.target.group.name)) : undefined;
var hosts = $scope.target.host ? splitMetrics(templateSrv.replace($scope.target.host.name)) : undefined; var hosts = $scope.target.host ? splitMetrics(templateSrv.replace($scope.target.host.name)) : undefined;
var apps = $scope.target.application ? splitMetrics(templateSrv.replace($scope.target.application.name)) : undefined; var apps = $scope.target.application ? splitMetrics(templateSrv.replace($scope.target.application.name)) : undefined;
$scope.datasource.itemFindQuery(groups, hosts, apps).then(function (items) { $scope.datasource.itemFindQuery(groups, hosts, apps).then(function (items) {