datasource.js refactoring.

This commit is contained in:
Alexander Zobnin
2015-06-09 17:25:34 +03:00
parent 2390172c7a
commit fba21c45c9

View File

@@ -415,7 +415,8 @@ function (angular, _, kbn) {
/** /**
* For templated query * For templated query.
* Find metrics from templated request.
* *
* @param {string} query Query from Templating * @param {string} query Query from Templating
* @return {string} Metric name - group, host, app or item or list * @return {string} Metric name - group, host, app or item or list
@@ -443,7 +444,6 @@ function (angular, _, kbn) {
return _.map(result, function (item) { return _.map(result, function (item) {
var itemname = expandItemName(item) var itemname = expandItemName(item)
return { return {
// TODO: select only unique names
text: itemname, text: itemname,
expandable: false expandable: false
}; };
@@ -483,7 +483,7 @@ function (angular, _, kbn) {
}); });
}); });
} }
// Return empty object // Return empty object for invalid request
else { else {
var d = $q.defer(); var d = $q.defer();
d.resolve([]); d.resolve([]);
@@ -493,17 +493,14 @@ function (angular, _, kbn) {
/** /**
* Find items from templated request * Find items belongs to passed groups, hosts and
* applications
* *
* @param {object} template Template object in format: * @param {string or array} groups
* { * @param {string or array} hosts
* group: [groupnames], * @param {string or array} apps
* host: [hostnames],
* app: [appnames],
* item: [itemnames]
* }
* *
* @return {Array} Array of Zabbix API item objects * @return {array} array of Zabbix API item objects
*/ */
ZabbixAPIDatasource.prototype.itemFindQuery = function(groups, hosts, apps) { ZabbixAPIDatasource.prototype.itemFindQuery = function(groups, hosts, apps) {
var promises = []; var promises = [];
@@ -545,6 +542,14 @@ function (angular, _, kbn) {
}; };
/**
* Find applications belongs to passed groups and hosts
*
* @param {string or array} hosts
* @param {string or array} groups
*
* @return {array} array of Zabbix API application objects
*/
ZabbixAPIDatasource.prototype.appFindQuery = function(hosts, groups) { ZabbixAPIDatasource.prototype.appFindQuery = function(hosts, groups) {
var promises = []; var promises = [];
@@ -576,6 +581,12 @@ function (angular, _, kbn) {
}; };
/**
* Find hosts belongs to passed groups
*
* @param {string or array} groups
* @return {array} array of Zabbix API host objects
*/
ZabbixAPIDatasource.prototype.hostFindQuery = function(groups) { ZabbixAPIDatasource.prototype.hostFindQuery = function(groups) {
var self = this; var self = this;
return this.findZabbixGroup(groups).then(function (results) { return this.findZabbixGroup(groups).then(function (results) {