Migrate backendSrv to getBackendSrv, fix direct DB connection
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import React, { FC } from 'react';
|
||||
import { css, cx } from 'emotion';
|
||||
import { Themeable, withTheme, Input, GrafanaTheme, EventsWithValidation, ValidationEvents } from '@grafana/ui';
|
||||
import { Themeable, withTheme, Input, EventsWithValidation, ValidationEvents } from '@grafana/ui';
|
||||
import { isRegex, variableRegex } from '../utils';
|
||||
import { GrafanaTheme } from '@grafana/data';
|
||||
|
||||
const variablePattern = RegExp(`^${variableRegex.source}`);
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ const DEFAULT_ZABBIX_VERSION = 3;
|
||||
export class ZabbixDatasource {
|
||||
|
||||
/** @ngInject */
|
||||
constructor(instanceSettings, templateSrv, backendSrv, datasourceSrv, zabbixAlertingSrv) {
|
||||
constructor(instanceSettings, templateSrv, datasourceSrv, zabbixAlertingSrv) {
|
||||
this.templateSrv = templateSrv;
|
||||
this.zabbixAlertingSrv = zabbixAlertingSrv;
|
||||
|
||||
@@ -75,7 +75,7 @@ export class ZabbixDatasource {
|
||||
dbConnectionRetentionPolicy: this.dbConnectionRetentionPolicy,
|
||||
};
|
||||
|
||||
this.zabbix = new Zabbix(zabbixOptions, datasourceSrv, backendSrv);
|
||||
this.zabbix = new Zabbix(zabbixOptions, datasourceSrv);
|
||||
}
|
||||
|
||||
////////////////////////
|
||||
|
||||
@@ -21,11 +21,11 @@ describe('ZabbixDatasource', () => {
|
||||
};
|
||||
|
||||
ctx.templateSrv = mocks.templateSrvMock;
|
||||
ctx.backendSrv = mocks.backendSrvMock;
|
||||
// ctx.backendSrv = mocks.backendSrvMock;
|
||||
ctx.datasourceSrv = mocks.datasourceSrvMock;
|
||||
ctx.zabbixAlertingSrv = mocks.zabbixAlertingSrvMock;
|
||||
|
||||
ctx.ds = new Datasource(ctx.instanceSettings, ctx.templateSrv, ctx.backendSrv, ctx.datasourceSrv, ctx.zabbixAlertingSrv);
|
||||
ctx.ds = new Datasource(ctx.instanceSettings, ctx.templateSrv, ctx.datasourceSrv, ctx.zabbixAlertingSrv);
|
||||
});
|
||||
|
||||
describe('When querying data', () => {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import _ from 'lodash';
|
||||
import { getBackendSrv } from '@grafana/runtime';
|
||||
import { compactQuery } from '../../../utils';
|
||||
import mysql from './mysql';
|
||||
import postgres from './postgres';
|
||||
@@ -17,8 +18,7 @@ export class SQLConnector extends DBConnector {
|
||||
this.sqlDialect = null;
|
||||
|
||||
super.loadDBDataSource()
|
||||
.then(ds => {
|
||||
this.backendSrv = ds.backendSrv;
|
||||
.then(() => {
|
||||
this.loadSQLDialect();
|
||||
});
|
||||
}
|
||||
@@ -96,7 +96,7 @@ export class SQLConnector extends DBConnector {
|
||||
maxDataPoints: this.limit
|
||||
};
|
||||
|
||||
return this.backendSrv.datasourceRequest({
|
||||
return getBackendSrv().datasourceRequest({
|
||||
url: '/api/tsdb/query',
|
||||
method: 'POST',
|
||||
data: {
|
||||
|
||||
@@ -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) {
|
||||
this.url = api_url;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
@@ -26,7 +26,7 @@ export class ZabbixAPIConnector {
|
||||
this.loginErrorCount = 0;
|
||||
this.maxLoginAttempts = 3;
|
||||
|
||||
this.zabbixAPICore = new ZabbixAPICore(backendSrv);
|
||||
this.zabbixAPICore = new ZabbixAPICore();
|
||||
|
||||
this.getTrend = this.getTrend_ZBXNEXT1193;
|
||||
//getTrend = getTrend_30;
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
/**
|
||||
* General Zabbix API methods
|
||||
*/
|
||||
import { getBackendSrv } from '@grafana/runtime';
|
||||
|
||||
export class ZabbixAPICore {
|
||||
|
||||
/** @ngInject */
|
||||
constructor(backendSrv) {
|
||||
this.backendSrv = backendSrv;
|
||||
constructor() {
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -50,7 +50,7 @@ export class ZabbixAPICore {
|
||||
}
|
||||
|
||||
datasourceRequest(requestOptions) {
|
||||
return this.backendSrv.datasourceRequest(requestOptions)
|
||||
return getBackendSrv().datasourceRequest(requestOptions)
|
||||
.then((response) => {
|
||||
if (!response.data) {
|
||||
return Promise.reject(new ZabbixAPIError({data: "General Error, no data"}));
|
||||
|
||||
@@ -25,7 +25,7 @@ const REQUESTS_TO_BIND = [
|
||||
];
|
||||
|
||||
export class Zabbix {
|
||||
constructor(options, datasourceSrv, backendSrv) {
|
||||
constructor(options, datasourceSrv) {
|
||||
let {
|
||||
url,
|
||||
username,
|
||||
@@ -49,7 +49,7 @@ export class Zabbix {
|
||||
};
|
||||
this.cachingProxy = new CachingProxy(cacheOptions);
|
||||
|
||||
this.zabbixAPI = new ZabbixAPIConnector(url, username, password, zabbixVersion, basicAuth, withCredentials, backendSrv);
|
||||
this.zabbixAPI = new ZabbixAPIConnector(url, username, password, zabbixVersion, basicAuth, withCredentials);
|
||||
|
||||
this.proxyfyRequests();
|
||||
this.cacheRequests();
|
||||
|
||||
@@ -13,9 +13,9 @@ describe('Zabbix', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
ctx.options = options;
|
||||
ctx.backendSrv = mocks.backendSrvMock;
|
||||
// ctx.backendSrv = mocks.backendSrvMock;
|
||||
ctx.datasourceSrv = mocks.datasourceSrvMock;
|
||||
zabbix = new Zabbix(ctx.options, ctx.backendSrvMock, ctx.datasourceSrvMock);
|
||||
zabbix = new Zabbix(ctx.options, ctx.datasourceSrvMock);
|
||||
});
|
||||
|
||||
describe('When querying proxies', () => {
|
||||
|
||||
Reference in New Issue
Block a user