Resolved #54 - Implemented testDatasource() method for test connection to zabbix server.
This commit is contained in:
@@ -41,6 +41,21 @@ function (angular, _, kbn) {
|
|||||||
this.zabbixAPI = new ZabbixAPI(this.url, this.username, this.password, this.basicAuth, this.withCredentials);
|
this.zabbixAPI = new ZabbixAPI(this.url, this.username, this.password, this.basicAuth, this.withCredentials);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test connection to Zabbix API
|
||||||
|
*
|
||||||
|
* @return {object} Connection status and Zabbix API version
|
||||||
|
*/
|
||||||
|
ZabbixAPIDatasource.prototype.testDatasource = function() {
|
||||||
|
return this.zabbixAPI.getZabbixAPIVersion().then(function (apiVersion) {
|
||||||
|
return {
|
||||||
|
status: "success",
|
||||||
|
title: "Success",
|
||||||
|
message: "Zabbix API version: " + apiVersion
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calls for each panel in dashboard.
|
* Calls for each panel in dashboard.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -117,6 +117,42 @@ function (angular, _) {
|
|||||||
// API method wrappers //
|
// API method wrappers //
|
||||||
/////////////////////////
|
/////////////////////////
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Request version of the Zabbix API.
|
||||||
|
*
|
||||||
|
* @return {string} Zabbix API version
|
||||||
|
*/
|
||||||
|
p.getZabbixAPIVersion = function() {
|
||||||
|
var options = {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
url: this.url,
|
||||||
|
data: {
|
||||||
|
jsonrpc: '2.0',
|
||||||
|
method: 'apiinfo.version',
|
||||||
|
params: [],
|
||||||
|
id: 1
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (this.basicAuth || this.withCredentials) {
|
||||||
|
options.withCredentials = true;
|
||||||
|
}
|
||||||
|
if (this.basicAuth) {
|
||||||
|
options.headers = options.headers || {};
|
||||||
|
options.headers.Authorization = this.basicAuth;
|
||||||
|
}
|
||||||
|
|
||||||
|
return backendSrv.datasourceRequest(options).then(function (result) {
|
||||||
|
if (!result.data) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return result.data.result;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform history query from Zabbix API
|
* Perform history query from Zabbix API
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user