Fixed template variable query with new cache model.
This commit is contained in:
@@ -293,22 +293,25 @@ export class ZabbixAPIDatasource {
|
|||||||
|
|
||||||
// Get items
|
// Get items
|
||||||
if (parts.length === 4) {
|
if (parts.length === 4) {
|
||||||
return this.queryProcessor.filterItems(template.group, template.host,
|
// Search for all items, even it's not belong to any application
|
||||||
template.app, 'all', true)
|
if (template.app === '/.*/') {
|
||||||
.then(function(items) {
|
template.app = '';
|
||||||
return _.map(items, formatMetric);
|
}
|
||||||
});
|
return this.queryProcessor.getItems(template.group, template.host, template.app)
|
||||||
|
.then(function(items) {
|
||||||
|
return _.map(items, formatMetric);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
// Get applications
|
// Get applications
|
||||||
else if (parts.length === 3) {
|
else if (parts.length === 3) {
|
||||||
return this.queryProcessor.filterApplications(template.group, template.host)
|
return this.queryProcessor.getApps(template.group, template.host)
|
||||||
.then(function(apps) {
|
.then(function(apps) {
|
||||||
return _.map(apps, formatMetric);
|
return _.map(apps, formatMetric);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Get hosts
|
// Get hosts
|
||||||
else if (parts.length === 2) {
|
else if (parts.length === 2) {
|
||||||
return this.queryProcessor.filterHosts(template.group)
|
return this.queryProcessor.getHosts(template.group)
|
||||||
.then(function(hosts) {
|
.then(function(hosts) {
|
||||||
return _.map(hosts, formatMetric);
|
return _.map(hosts, formatMetric);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -201,6 +201,79 @@ angular.module('grafana.services').factory('QueryProcessor', function($q) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getHosts(groupFilter) {
|
||||||
|
var self = this;
|
||||||
|
return this.cache
|
||||||
|
.getGroups()
|
||||||
|
.then(groups => {
|
||||||
|
return findByFilter(groups, groupFilter);
|
||||||
|
})
|
||||||
|
.then(groups => {
|
||||||
|
var groupids = _.map(groups, 'groupid');
|
||||||
|
return self.cache.getHosts(groupids);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getApps(groupFilter, hostFilter) {
|
||||||
|
var self = this;
|
||||||
|
return this
|
||||||
|
.getHosts(groupFilter)
|
||||||
|
.then(hosts => {
|
||||||
|
return findByFilter(hosts, hostFilter);
|
||||||
|
})
|
||||||
|
.then(hosts => {
|
||||||
|
var hostids = _.map(hosts, 'hostid');
|
||||||
|
return self.cache.getApps(hostids);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
getItems(groupFilter, hostFilter, appFilter, showDisabledItems) {
|
||||||
|
var self = this;
|
||||||
|
return this
|
||||||
|
.getHosts(groupFilter)
|
||||||
|
.then(hosts => {
|
||||||
|
return findByFilter(hosts, hostFilter);
|
||||||
|
})
|
||||||
|
.then(hosts => {
|
||||||
|
var hostids = _.map(hosts, 'hostid');
|
||||||
|
if (appFilter) {
|
||||||
|
return self.cache
|
||||||
|
.getApps(hostids)
|
||||||
|
.then(apps => {
|
||||||
|
// Use getByFilter for proper item filtering
|
||||||
|
return getByFilter(apps, appFilter);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return {
|
||||||
|
appFilterEmpty: true,
|
||||||
|
hostids: hostids
|
||||||
|
};
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.then(apps => {
|
||||||
|
if (apps.appFilterEmpty) {
|
||||||
|
return self.cache
|
||||||
|
.getItems(apps.hostids, undefined)
|
||||||
|
.then(items => {
|
||||||
|
if (showDisabledItems) {
|
||||||
|
items = _.filter(items, {'status': '0'});
|
||||||
|
}
|
||||||
|
return items;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
var appids = _.map(apps, 'applicationid');
|
||||||
|
return self.cache
|
||||||
|
.getItems(undefined, appids)
|
||||||
|
.then(items => {
|
||||||
|
if (showDisabledItems) {
|
||||||
|
items = _.filter(items, {'status': '0'});
|
||||||
|
}
|
||||||
|
return items;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build query - convert target filters to array of Zabbix items
|
* Build query - convert target filters to array of Zabbix items
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user