Refactor: queryProcessor.service.

This commit is contained in:
Alexander Zobnin
2016-11-12 18:04:29 +03:00
parent 4a73957c16
commit 2e57b9b166
4 changed files with 166 additions and 267 deletions

View File

@@ -20,6 +20,7 @@ export class ZabbixQueryController extends QueryCtrl {
this.zabbix = this.datasource.zabbixAPI;
this.cache = this.datasource.zabbixCache;
this.queryProcessor = this.datasource.queryProcessor;
this.$q = $q;
// Use custom format for template variables
@@ -115,76 +116,47 @@ export class ZabbixQueryController extends QueryCtrl {
}
suggestGroups() {
var self = this;
return this.cache.getGroups().then(groups => {
self.metric.groupList = groups;
return this.queryProcessor.getAllGroups()
.then(groups => {
this.metric.groupList = groups;
return groups;
});
}
suggestHosts() {
var self = this;
var groupFilter = this.replaceTemplateVars(this.target.group.filter);
return this.datasource.queryProcessor
.filterGroups(self.metric.groupList, groupFilter)
.then(groups => {
var groupids = _.map(groups, 'groupid');
return self.zabbix
.getHosts(groupids)
.then(hosts => {
self.metric.hostList = hosts;
return hosts;
});
});
let groupFilter = this.replaceTemplateVars(this.target.group.filter);
return this.queryProcessor.getAllHosts(groupFilter)
.then(hosts => {
this.metric.hostList = hosts;
return hosts;
});
}
suggestApps() {
var self = this;
var hostFilter = this.replaceTemplateVars(this.target.host.filter);
return this.datasource.queryProcessor
.filterHosts(self.metric.hostList, hostFilter)
.then(hosts => {
var hostids = _.map(hosts, 'hostid');
return self.zabbix
.getApps(hostids)
.then(apps => {
return self.metric.appList = apps;
});
});
let groupFilter = this.replaceTemplateVars(this.target.group.filter);
let hostFilter = this.replaceTemplateVars(this.target.host.filter);
return this.queryProcessor.getAllApps(groupFilter, hostFilter)
.then(apps => {
this.metric.appList = apps;
return apps;
});
}
suggestItems(itemtype='num') {
var self = this;
var appFilter = this.replaceTemplateVars(this.target.application.filter);
if (appFilter) {
// Filter by applications
return this.datasource.queryProcessor
.filterApps(self.metric.appList, appFilter)
.then(apps => {
var appids = _.map(apps, 'applicationid');
return self.zabbix
.getItems(undefined, appids, itemtype)
.then(items => {
if (!self.target.options.showDisabledItems) {
items = _.filter(items, {'status': '0'});
}
self.metric.itemList = items;
return items;
});
});
} else {
// Return all items belonged to selected hosts
var hostids = _.map(self.metric.hostList, 'hostid');
return self.zabbix
.getItems(hostids, undefined, itemtype)
.then(items => {
if (!self.target.options.showDisabledItems) {
items = _.filter(items, {'status': '0'});
}
self.metric.itemList = items;
return items;
});
}
suggestItems(itemtype = 'num') {
let groupFilter = this.replaceTemplateVars(this.target.group.filter);
let hostFilter = this.replaceTemplateVars(this.target.host.filter);
let appFilter = this.replaceTemplateVars(this.target.application.filter);
let options = {
itemtype: itemtype,
showDisabledItems: this.target.options.showDisabledItems
};
return this.queryProcessor
.getAllItems(groupFilter, hostFilter, appFilter, options)
.then(items => {
this.metric.itemList = items;
return items;
});
}
isRegex(str) {