Resolved #54 - Implemented testDatasource() method for test connection to zabbix server.

This commit is contained in:
Alexander Zobnin
2015-07-12 19:12:21 +03:00
parent b97b96a164
commit b466cc4cbc
2 changed files with 51 additions and 0 deletions

View File

@@ -41,6 +41,21 @@ function (angular, _, kbn) {
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.
*

View File

@@ -117,6 +117,42 @@ function (angular, _) {
// 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
*