Refactoring: change performZabbixAPIRequest()? deleted code duplication.
This commit is contained in:
@@ -85,14 +85,20 @@ function (angular, _, kbn) {
|
|||||||
|
|
||||||
|
|
||||||
// Request data from Zabbix API
|
// Request data from Zabbix API
|
||||||
ZabbixAPIDatasource.prototype.performZabbixAPIRequest = function(request_data) {
|
ZabbixAPIDatasource.prototype.performZabbixAPIRequest = function(method, params) {
|
||||||
var options = {
|
var options = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
url: this.url,
|
url: this.url,
|
||||||
data: request_data
|
data: {
|
||||||
|
jsonrpc: '2.0',
|
||||||
|
method: method,
|
||||||
|
params: params,
|
||||||
|
auth: this.auth,
|
||||||
|
id: 1
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var performedQuery;
|
var performedQuery;
|
||||||
@@ -125,10 +131,7 @@ function (angular, _, kbn) {
|
|||||||
* @param items: array of zabbix api item objects
|
* @param items: array of zabbix api item objects
|
||||||
*/
|
*/
|
||||||
ZabbixAPIDatasource.prototype.performTimeSeriesQuery = function(items, start, end) {
|
ZabbixAPIDatasource.prototype.performTimeSeriesQuery = function(items, start, end) {
|
||||||
var data = {
|
var params = {
|
||||||
jsonrpc: '2.0',
|
|
||||||
method: 'history.get',
|
|
||||||
params: {
|
|
||||||
output: 'extend',
|
output: 'extend',
|
||||||
history: items.value_type,
|
history: items.value_type,
|
||||||
itemids: items.itemid,
|
itemids: items.itemid,
|
||||||
@@ -136,17 +139,14 @@ function (angular, _, kbn) {
|
|||||||
sortorder: 'ASC',
|
sortorder: 'ASC',
|
||||||
limit: this.limitmetrics,
|
limit: this.limitmetrics,
|
||||||
time_from: start,
|
time_from: start,
|
||||||
},
|
|
||||||
auth: this.auth,
|
|
||||||
id: 1
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Relative queries (e.g. last hour) don't include an end time
|
// Relative queries (e.g. last hour) don't include an end time
|
||||||
if (end) {
|
if (end) {
|
||||||
data.params.time_till = end;
|
params.time_till = end;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.performZabbixAPIRequest(data);
|
return this.performZabbixAPIRequest('history.get', params);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -178,83 +178,62 @@ function (angular, _, kbn) {
|
|||||||
|
|
||||||
// Get the list of host groups
|
// Get the list of host groups
|
||||||
ZabbixAPIDatasource.prototype.performHostGroupSuggestQuery = function() {
|
ZabbixAPIDatasource.prototype.performHostGroupSuggestQuery = function() {
|
||||||
var data = {
|
var params = {
|
||||||
jsonrpc: '2.0',
|
|
||||||
method: 'hostgroup.get',
|
|
||||||
params: {
|
|
||||||
output: ['name'],
|
output: ['name'],
|
||||||
real_hosts: true, //Return only host groups that contain hosts
|
real_hosts: true, //Return only host groups that contain hosts
|
||||||
sortfield: 'name'
|
sortfield: 'name'
|
||||||
},
|
|
||||||
auth: this.auth,
|
|
||||||
id: 1
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return this.performZabbixAPIRequest(data);
|
return this.performZabbixAPIRequest('hostgroup.get', params);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Get the list of hosts
|
// Get the list of hosts
|
||||||
ZabbixAPIDatasource.prototype.performHostSuggestQuery = function(groupid) {
|
ZabbixAPIDatasource.prototype.performHostSuggestQuery = function(groupid) {
|
||||||
var data = {
|
var params = {
|
||||||
jsonrpc: '2.0',
|
|
||||||
method: 'host.get',
|
|
||||||
params: {
|
|
||||||
output: ['name'],
|
output: ['name'],
|
||||||
sortfield: 'name'
|
sortfield: 'name'
|
||||||
},
|
|
||||||
auth: this.auth,
|
|
||||||
id: 1
|
|
||||||
};
|
};
|
||||||
|
// Return only hosts in given group
|
||||||
if (groupid) {
|
if (groupid) {
|
||||||
data.params.groupids = groupid;
|
params.groupids = groupid;
|
||||||
}
|
}
|
||||||
|
return this.performZabbixAPIRequest('host.get', params);
|
||||||
return this.performZabbixAPIRequest(data);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// Get the list of applications
|
// Get the list of applications
|
||||||
ZabbixAPIDatasource.prototype.performAppSuggestQuery = function(hostid) {
|
ZabbixAPIDatasource.prototype.performAppSuggestQuery = function(hostid) {
|
||||||
var data = {
|
var params = {
|
||||||
jsonrpc: '2.0',
|
|
||||||
method: 'application.get',
|
|
||||||
params: {
|
|
||||||
output: ['name'],
|
output: ['name'],
|
||||||
sortfield: 'name',
|
sortfield: 'name',
|
||||||
hostids: hostid
|
hostids: hostid
|
||||||
},
|
|
||||||
auth: this.auth,
|
|
||||||
id: 1
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return this.performZabbixAPIRequest(data);
|
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(hostid, applicationid) {
|
||||||
var data = {
|
var params = {
|
||||||
jsonrpc: '2.0',
|
|
||||||
method: 'item.get',
|
|
||||||
params: {
|
|
||||||
output: ['name', 'key_', 'value_type', 'delay'],
|
output: ['name', 'key_', 'value_type', 'delay'],
|
||||||
sortfield: 'name',
|
sortfield: 'name',
|
||||||
hostids: hostid,
|
hostids: hostid,
|
||||||
webitems: true, //Include web items in the result
|
|
||||||
|
//Include web items in the result
|
||||||
|
webitems: true,
|
||||||
|
// Return only numeric items
|
||||||
filter: {
|
filter: {
|
||||||
value_type: [0,3]
|
value_type: [0,3]
|
||||||
}
|
}
|
||||||
},
|
|
||||||
auth: this.auth,
|
|
||||||
id: 1
|
|
||||||
};
|
};
|
||||||
// If application selected return only relative items
|
// If application selected return only relative items
|
||||||
if (applicationid) {
|
if (applicationid) {
|
||||||
data.params.applicationids = applicationid;
|
params.applicationids = applicationid;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.performZabbixAPIRequest(data);
|
return this.performZabbixAPIRequest('item.get', params);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user