Improve templated variables search, reduced the number of requests to api.
This commit is contained in:
@@ -233,48 +233,60 @@ function (angular, _, kbn) {
|
|||||||
|
|
||||||
|
|
||||||
// Get the list of hosts
|
// Get the list of hosts
|
||||||
ZabbixAPIDatasource.prototype.performHostSuggestQuery = function(groupid) {
|
ZabbixAPIDatasource.prototype.performHostSuggestQuery = function(groupids) {
|
||||||
var params = {
|
var params = {
|
||||||
output: ['name', 'host'],
|
output: ['name', 'host'],
|
||||||
sortfield: 'name'
|
sortfield: 'name',
|
||||||
|
// Return only hosts that have items with numeric type of information.
|
||||||
|
with_simple_graph_items: true
|
||||||
};
|
};
|
||||||
// Return only hosts in given group
|
// Return only hosts in given group
|
||||||
if (groupid) {
|
if (groupids) {
|
||||||
params.groupids = groupid;
|
params.groupids = groupids;
|
||||||
}
|
}
|
||||||
return this.performZabbixAPIRequest('host.get', params);
|
return this.performZabbixAPIRequest('host.get', params);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Get the list of applications
|
// Get the list of applications
|
||||||
ZabbixAPIDatasource.prototype.performAppSuggestQuery = function(hostid) {
|
ZabbixAPIDatasource.prototype.performAppSuggestQuery = function(hostids, /* optional */ groupids) {
|
||||||
var params = {
|
var params = {
|
||||||
output: ['name'],
|
output: ['name'],
|
||||||
sortfield: 'name',
|
sortfield: 'name'
|
||||||
hostids: hostid
|
|
||||||
};
|
};
|
||||||
|
if (hostids) {
|
||||||
|
params.hostids = hostids;
|
||||||
|
}
|
||||||
|
else if (groupids) {
|
||||||
|
params.groupids = groupids;
|
||||||
|
}
|
||||||
|
|
||||||
return this.performZabbixAPIRequest('application.get', params);
|
return this.performZabbixAPIRequest('application.get', params);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Get the list of host items
|
// Get the list of host items
|
||||||
ZabbixAPIDatasource.prototype.performItemSuggestQuery = function(hostid, applicationid) {
|
ZabbixAPIDatasource.prototype.performItemSuggestQuery = function(hostids, applicationids, /* optional */ groupids) {
|
||||||
var params = {
|
var params = {
|
||||||
output: ['name', 'key_', 'value_type', 'delay'],
|
output: ['name', 'key_', 'value_type', 'delay'],
|
||||||
sortfield: 'name',
|
sortfield: 'name',
|
||||||
hostids: hostid,
|
|
||||||
|
|
||||||
//Include web items in the result
|
//Include web items in the result
|
||||||
webitems: true,
|
webitems: true,
|
||||||
// Return only numeric items
|
// Return only numeric items
|
||||||
filter: {
|
filter: {
|
||||||
value_type: [0,3]
|
value_type: [0,3]
|
||||||
}
|
},
|
||||||
|
searchByAny: true
|
||||||
};
|
};
|
||||||
|
if (hostids) {
|
||||||
|
params.hostids = hostids;
|
||||||
|
}
|
||||||
|
else if (groupids) {
|
||||||
|
params.groupids = groupids;
|
||||||
|
}
|
||||||
// If application selected return only relative items
|
// If application selected return only relative items
|
||||||
if (applicationid) {
|
if (applicationids) {
|
||||||
params.applicationids = applicationid;
|
params.applicationids = applicationids;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.performZabbixAPIRequest('item.get', params);
|
return this.performZabbixAPIRequest('item.get', params);
|
||||||
@@ -414,19 +426,7 @@ function (angular, _, kbn) {
|
|||||||
return object.applicationid;
|
return object.applicationid;
|
||||||
}), 'applicationid');
|
}), 'applicationid');
|
||||||
|
|
||||||
var params = {
|
return self.performItemSuggestQuery(hostids, applicationids, groupids)
|
||||||
output: ['name', 'key_'],
|
|
||||||
sortfield: 'name',
|
|
||||||
};
|
|
||||||
if (applicationids.length) {
|
|
||||||
params.applicationids = applicationids;
|
|
||||||
}
|
|
||||||
if (hostids.length) {
|
|
||||||
params.hostids = hostids;
|
|
||||||
} else if (groupids.length) {
|
|
||||||
params.groupids = groupids;
|
|
||||||
}
|
|
||||||
return self.performZabbixAPIRequest('item.get', params)
|
|
||||||
.then(function (result) {
|
.then(function (result) {
|
||||||
return _.map(result, function (item) {
|
return _.map(result, function (item) {
|
||||||
return {
|
return {
|
||||||
@@ -443,14 +443,14 @@ function (angular, _, kbn) {
|
|||||||
ZabbixAPIDatasource.prototype.appFindQuery = function(template) {
|
ZabbixAPIDatasource.prototype.appFindQuery = function(template) {
|
||||||
var promises = [];
|
var promises = [];
|
||||||
|
|
||||||
// Get groupids from names
|
|
||||||
if (template.group && template.group != '*') {
|
|
||||||
promises.push(this.findZabbixGroup(template.group));
|
|
||||||
}
|
|
||||||
// Get hostids from names
|
// Get hostids from names
|
||||||
if (template.host && template.host != '*') {
|
if (template.host && template.host != '*') {
|
||||||
promises.push(this.findZabbixHost(template.host));
|
promises.push(this.findZabbixHost(template.host));
|
||||||
}
|
}
|
||||||
|
// Get groupids from names
|
||||||
|
else if (template.group && template.group != '*') {
|
||||||
|
promises.push(this.findZabbixGroup(template.group));
|
||||||
|
}
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
return $q.all(promises).then(function (results) {
|
return $q.all(promises).then(function (results) {
|
||||||
@@ -462,17 +462,7 @@ function (angular, _, kbn) {
|
|||||||
return object.hostid;
|
return object.hostid;
|
||||||
}), 'hostid');
|
}), 'hostid');
|
||||||
|
|
||||||
var params = {
|
return self.performAppSuggestQuery(hostids, groupids)
|
||||||
output: ['name'],
|
|
||||||
sortfield: 'name'
|
|
||||||
}
|
|
||||||
if (hostids.length) {
|
|
||||||
params.hostids = hostids;
|
|
||||||
} else if (groupids.length) {
|
|
||||||
params.groupids = groupids;
|
|
||||||
}
|
|
||||||
|
|
||||||
return self.performZabbixAPIRequest('application.get', params)
|
|
||||||
.then(function (result) {
|
.then(function (result) {
|
||||||
return _.map(result, function (app) {
|
return _.map(result, function (app) {
|
||||||
return {
|
return {
|
||||||
@@ -486,13 +476,6 @@ function (angular, _, kbn) {
|
|||||||
|
|
||||||
|
|
||||||
ZabbixAPIDatasource.prototype.hostFindQuery = function(template) {
|
ZabbixAPIDatasource.prototype.hostFindQuery = function(template) {
|
||||||
var promises = [];
|
|
||||||
|
|
||||||
// Get groupids from names
|
|
||||||
if (template.group && template.group != '*') {
|
|
||||||
promises.push(this.findZabbixGroup(template.group));
|
|
||||||
}
|
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
return this.findZabbixGroup(template.group).then(function (results) {
|
return this.findZabbixGroup(template.group).then(function (results) {
|
||||||
results = _.flatten(results);
|
results = _.flatten(results);
|
||||||
@@ -500,23 +483,14 @@ function (angular, _, kbn) {
|
|||||||
return object.groupid;
|
return object.groupid;
|
||||||
}), 'groupid');
|
}), 'groupid');
|
||||||
|
|
||||||
var params = {
|
return self.performHostSuggestQuery(groupids).then(function (result) {
|
||||||
output: ['name', 'host'],
|
return _.map(result, function (host) {
|
||||||
sortfield: 'name'
|
return {
|
||||||
}
|
text: host.name,
|
||||||
if (groupids.length) {
|
expandable: false
|
||||||
params.groupids = groupids;
|
};
|
||||||
}
|
|
||||||
|
|
||||||
return self.performZabbixAPIRequest('host.get', params)
|
|
||||||
.then(function (result) {
|
|
||||||
return _.map(result, function (host) {
|
|
||||||
return {
|
|
||||||
text: host.name,
|
|
||||||
expandable: false
|
|
||||||
};
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user