Return only numeric or text items depend of editor mode.

This commit is contained in:
Alexander Zobnin
2016-04-12 12:21:43 +03:00
parent 49ea07451f
commit a6c2774334
2 changed files with 21 additions and 5 deletions

View File

@@ -93,10 +93,11 @@ export class ZabbixQueryController extends QueryCtrl {
initFilters() { initFilters() {
var self = this; var self = this;
var itemtype = self.editorModes[self.target.mode];
return this.$q.when(this.suggestGroups()) return this.$q.when(this.suggestGroups())
.then(() => {return self.suggestHosts();}) .then(() => {return self.suggestHosts();})
.then(() => {return self.suggestApps();}) .then(() => {return self.suggestApps();})
.then(() => {return self.suggestItems();}); .then(() => {return self.suggestItems(itemtype);});
} }
suggestGroups() { suggestGroups() {
@@ -138,7 +139,7 @@ export class ZabbixQueryController extends QueryCtrl {
}); });
} }
suggestItems() { suggestItems(itemtype='num') {
var self = this; var self = this;
var appFilter = this.templateSrv.replace(this.target.application.filter); var appFilter = this.templateSrv.replace(this.target.application.filter);
if (appFilter) { if (appFilter) {
@@ -148,7 +149,7 @@ export class ZabbixQueryController extends QueryCtrl {
.then(apps => { .then(apps => {
var appids = _.map(apps, 'applicationid'); var appids = _.map(apps, 'applicationid');
return self.zabbix return self.zabbix
.getItems(undefined, appids) .getItems(undefined, appids, itemtype)
.then(items => { .then(items => {
if (!self.target.showDisabledItems) { if (!self.target.showDisabledItems) {
items = _.filter(items, {'status': '0'}); items = _.filter(items, {'status': '0'});
@@ -161,7 +162,7 @@ export class ZabbixQueryController extends QueryCtrl {
// Return all items belonged to selected hosts // Return all items belonged to selected hosts
var hostids = _.map(self.metric.hostList, 'hostid'); var hostids = _.map(self.metric.hostList, 'hostid');
return self.zabbix return self.zabbix
.getItems(hostids) .getItems(hostids, undefined, itemtype)
.then(items => { .then(items => {
if (!self.target.showDisabledItems) { if (!self.target.showDisabledItems) {
items = _.filter(items, {'status': '0'}); items = _.filter(items, {'status': '0'});

View File

@@ -145,7 +145,14 @@ function ZabbixAPIService($q, alertSrv, zabbixAPICoreService) {
return this.request('application.get', params); return this.request('application.get', params);
} }
getItems(hostids, appids) { /**
* Get Zabbix items
* @param {[type]} hostids host ids
* @param {[type]} appids application ids
* @param {String} itemtype 'num' or 'text'
* @return {[type]} array of items
*/
getItems(hostids, appids, itemtype='num') {
var params = { var params = {
output: [ output: [
'name', 'key_', 'name', 'key_',
@@ -156,6 +163,10 @@ function ZabbixAPIService($q, alertSrv, zabbixAPICoreService) {
], ],
sortfield: 'name', sortfield: 'name',
webitems: true, webitems: true,
filter: {
// Return only numeric items by default
value_type: [0, 3]
},
selectHosts: [ selectHosts: [
'hostid', 'hostid',
'name' 'name'
@@ -167,6 +178,10 @@ function ZabbixAPIService($q, alertSrv, zabbixAPICoreService) {
if (appids) { if (appids) {
params.applicationids = appids; params.applicationids = appids;
} }
if (itemtype === 'text') {
// Return only text metrics
params.filter.value_type = [1, 2, 4];
}
return this.request('item.get', params) return this.request('item.get', params)
.then(items => { .then(items => {