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

View File

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

View File

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