backend: proxy Zabbix API requests through the backend
This commit is contained in:
@@ -10,7 +10,7 @@ import { ZBX_ACK_ACTION_NONE, ZBX_ACK_ACTION_ACK, ZBX_ACK_ACTION_ADD_MESSAGE, MI
|
||||
* Wraps API calls and provides high-level methods.
|
||||
*/
|
||||
export class ZabbixAPIConnector {
|
||||
constructor(api_url, username, password, version, basicAuth, withCredentials, backendSrv) {
|
||||
constructor(api_url, username, password, version, basicAuth, withCredentials, backendSrv, datasourceId) {
|
||||
this.url = api_url;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
@@ -22,6 +22,9 @@ export class ZabbixAPIConnector {
|
||||
withCredentials: withCredentials
|
||||
};
|
||||
|
||||
this.datasourceId = datasourceId;
|
||||
this.backendSrv = backendSrv;
|
||||
|
||||
this.loginPromise = null;
|
||||
this.loginErrorCount = 0;
|
||||
this.maxLoginAttempts = 3;
|
||||
@@ -37,6 +40,8 @@ export class ZabbixAPIConnector {
|
||||
//////////////////////////
|
||||
|
||||
request(method, params) {
|
||||
this.tsdbRequest(method, params);
|
||||
|
||||
return this.zabbixAPICore.request(this.url, method, params, this.requestOptions, this.auth)
|
||||
.catch(error => {
|
||||
if (isNotAuthorized(error.data)) {
|
||||
@@ -55,6 +60,25 @@ export class ZabbixAPIConnector {
|
||||
});
|
||||
}
|
||||
|
||||
tsdbRequest(method, params) {
|
||||
const tsdbRequestData = {
|
||||
queries: [{
|
||||
datasourceId: this.datasourceId,
|
||||
queryType: 'zabbixAPI',
|
||||
target: {
|
||||
method,
|
||||
params,
|
||||
},
|
||||
}],
|
||||
};
|
||||
|
||||
return this.backendSrv.datasourceRequest({
|
||||
url: '/api/tsdb/query',
|
||||
method: 'POST',
|
||||
data: tsdbRequestData
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* When API unauthenticated or auth token expired each request produce login()
|
||||
* call. But auth token is common to all requests. This function wraps login() method
|
||||
|
||||
Reference in New Issue
Block a user