Migrate backendSrv to getBackendSrv, fix direct DB connection
This commit is contained in:
@@ -29,8 +29,9 @@
|
|||||||
"@babel/preset-env": "^7.7.7",
|
"@babel/preset-env": "^7.7.7",
|
||||||
"@babel/preset-react": "^7.6.3",
|
"@babel/preset-react": "^7.6.3",
|
||||||
"@emotion/core": "^10.0.27",
|
"@emotion/core": "^10.0.27",
|
||||||
"@grafana/data": "^6.4.2",
|
"@grafana/data": "^6.7.0",
|
||||||
"@grafana/ui": "^6.4.2",
|
"@grafana/ui": "^6.7.0",
|
||||||
|
"@grafana/runtime": "^6.7.0",
|
||||||
"@types/classnames": "^2.2.6",
|
"@types/classnames": "^2.2.6",
|
||||||
"@types/grafana": "github:CorpGlory/types-grafana",
|
"@types/grafana": "github:CorpGlory/types-grafana",
|
||||||
"@types/jest": "^23.1.1",
|
"@types/jest": "^23.1.1",
|
||||||
@@ -70,7 +71,7 @@
|
|||||||
"react": "^16.7.0",
|
"react": "^16.7.0",
|
||||||
"react-dom": "^16.7.0",
|
"react-dom": "^16.7.0",
|
||||||
"react-popper": "^1.3.2",
|
"react-popper": "^1.3.2",
|
||||||
"react-table": "^6.8.6",
|
"react-table-6": "^6.8.6",
|
||||||
"react-test-renderer": "^16.7.0",
|
"react-test-renderer": "^16.7.0",
|
||||||
"react-transition-group": "^2.5.2",
|
"react-transition-group": "^2.5.2",
|
||||||
"rst2html": "github:thoward/rst2html#990cb89",
|
"rst2html": "github:thoward/rst2html#990cb89",
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import React, { FC } from 'react';
|
import React, { FC } from 'react';
|
||||||
import { css, cx } from 'emotion';
|
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 { isRegex, variableRegex } from '../utils';
|
||||||
|
import { GrafanaTheme } from '@grafana/data';
|
||||||
|
|
||||||
const variablePattern = RegExp(`^${variableRegex.source}`);
|
const variablePattern = RegExp(`^${variableRegex.source}`);
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ const DEFAULT_ZABBIX_VERSION = 3;
|
|||||||
export class ZabbixDatasource {
|
export class ZabbixDatasource {
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
constructor(instanceSettings, templateSrv, backendSrv, datasourceSrv, zabbixAlertingSrv) {
|
constructor(instanceSettings, templateSrv, datasourceSrv, zabbixAlertingSrv) {
|
||||||
this.templateSrv = templateSrv;
|
this.templateSrv = templateSrv;
|
||||||
this.zabbixAlertingSrv = zabbixAlertingSrv;
|
this.zabbixAlertingSrv = zabbixAlertingSrv;
|
||||||
|
|
||||||
@@ -75,7 +75,7 @@ export class ZabbixDatasource {
|
|||||||
dbConnectionRetentionPolicy: this.dbConnectionRetentionPolicy,
|
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.templateSrv = mocks.templateSrvMock;
|
||||||
ctx.backendSrv = mocks.backendSrvMock;
|
// ctx.backendSrv = mocks.backendSrvMock;
|
||||||
ctx.datasourceSrv = mocks.datasourceSrvMock;
|
ctx.datasourceSrv = mocks.datasourceSrvMock;
|
||||||
ctx.zabbixAlertingSrv = mocks.zabbixAlertingSrvMock;
|
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', () => {
|
describe('When querying data', () => {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import { getBackendSrv } from '@grafana/runtime';
|
||||||
import { compactQuery } from '../../../utils';
|
import { compactQuery } from '../../../utils';
|
||||||
import mysql from './mysql';
|
import mysql from './mysql';
|
||||||
import postgres from './postgres';
|
import postgres from './postgres';
|
||||||
@@ -17,8 +18,7 @@ export class SQLConnector extends DBConnector {
|
|||||||
this.sqlDialect = null;
|
this.sqlDialect = null;
|
||||||
|
|
||||||
super.loadDBDataSource()
|
super.loadDBDataSource()
|
||||||
.then(ds => {
|
.then(() => {
|
||||||
this.backendSrv = ds.backendSrv;
|
|
||||||
this.loadSQLDialect();
|
this.loadSQLDialect();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -96,7 +96,7 @@ export class SQLConnector extends DBConnector {
|
|||||||
maxDataPoints: this.limit
|
maxDataPoints: this.limit
|
||||||
};
|
};
|
||||||
|
|
||||||
return this.backendSrv.datasourceRequest({
|
return getBackendSrv().datasourceRequest({
|
||||||
url: '/api/tsdb/query',
|
url: '/api/tsdb/query',
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
data: {
|
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.
|
* Wraps API calls and provides high-level methods.
|
||||||
*/
|
*/
|
||||||
export class ZabbixAPIConnector {
|
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.url = api_url;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
@@ -26,7 +26,7 @@ export class ZabbixAPIConnector {
|
|||||||
this.loginErrorCount = 0;
|
this.loginErrorCount = 0;
|
||||||
this.maxLoginAttempts = 3;
|
this.maxLoginAttempts = 3;
|
||||||
|
|
||||||
this.zabbixAPICore = new ZabbixAPICore(backendSrv);
|
this.zabbixAPICore = new ZabbixAPICore();
|
||||||
|
|
||||||
this.getTrend = this.getTrend_ZBXNEXT1193;
|
this.getTrend = this.getTrend_ZBXNEXT1193;
|
||||||
//getTrend = getTrend_30;
|
//getTrend = getTrend_30;
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
/**
|
/**
|
||||||
* General Zabbix API methods
|
* General Zabbix API methods
|
||||||
*/
|
*/
|
||||||
|
import { getBackendSrv } from '@grafana/runtime';
|
||||||
|
|
||||||
export class ZabbixAPICore {
|
export class ZabbixAPICore {
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
constructor(backendSrv) {
|
constructor() {
|
||||||
this.backendSrv = backendSrv;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -50,7 +50,7 @@ export class ZabbixAPICore {
|
|||||||
}
|
}
|
||||||
|
|
||||||
datasourceRequest(requestOptions) {
|
datasourceRequest(requestOptions) {
|
||||||
return this.backendSrv.datasourceRequest(requestOptions)
|
return getBackendSrv().datasourceRequest(requestOptions)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (!response.data) {
|
if (!response.data) {
|
||||||
return Promise.reject(new ZabbixAPIError({data: "General Error, no data"}));
|
return Promise.reject(new ZabbixAPIError({data: "General Error, no data"}));
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ const REQUESTS_TO_BIND = [
|
|||||||
];
|
];
|
||||||
|
|
||||||
export class Zabbix {
|
export class Zabbix {
|
||||||
constructor(options, datasourceSrv, backendSrv) {
|
constructor(options, datasourceSrv) {
|
||||||
let {
|
let {
|
||||||
url,
|
url,
|
||||||
username,
|
username,
|
||||||
@@ -49,7 +49,7 @@ export class Zabbix {
|
|||||||
};
|
};
|
||||||
this.cachingProxy = new CachingProxy(cacheOptions);
|
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.proxyfyRequests();
|
||||||
this.cacheRequests();
|
this.cacheRequests();
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ describe('Zabbix', () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
ctx.options = options;
|
ctx.options = options;
|
||||||
ctx.backendSrv = mocks.backendSrvMock;
|
// ctx.backendSrv = mocks.backendSrvMock;
|
||||||
ctx.datasourceSrv = mocks.datasourceSrvMock;
|
ctx.datasourceSrv = mocks.datasourceSrvMock;
|
||||||
zabbix = new Zabbix(ctx.options, ctx.backendSrvMock, ctx.datasourceSrvMock);
|
zabbix = new Zabbix(ctx.options, ctx.datasourceSrvMock);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('When querying proxies', () => {
|
describe('When querying proxies', () => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { PureComponent } from 'react';
|
import React, { PureComponent } from 'react';
|
||||||
import ReactTable from 'react-table';
|
import ReactTable from 'react-table-6';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
@@ -18,8 +18,8 @@ export interface ProblemListProps {
|
|||||||
timeRange?: GFTimeRange;
|
timeRange?: GFTimeRange;
|
||||||
pageSize?: number;
|
pageSize?: number;
|
||||||
fontSize?: number;
|
fontSize?: number;
|
||||||
getProblemEvents: (problem: ZBXTrigger) => ZBXEvent[];
|
getProblemEvents: (problem: ZBXTrigger) => Promise<ZBXEvent[]>;
|
||||||
getProblemAlerts: (problem: ZBXTrigger) => ZBXAlert[];
|
getProblemAlerts: (problem: ZBXTrigger) => Promise<ZBXAlert[]>;
|
||||||
onProblemAck?: (problem: ZBXTrigger, data: AckProblemData) => void;
|
onProblemAck?: (problem: ZBXTrigger, data: AckProblemData) => void;
|
||||||
onTagClick?: (tag: ZBXTag, datasource: string, ctrlKey?: boolean, shiftKey?: boolean) => void;
|
onTagClick?: (tag: ZBXTag, datasource: string, ctrlKey?: boolean, shiftKey?: boolean) => void;
|
||||||
onPageSizeChange?: (pageSize: number, pageIndex: number) => void;
|
onPageSizeChange?: (pageSize: number, pageIndex: number) => void;
|
||||||
@@ -163,6 +163,7 @@ export default class ProblemList extends PureComponent<ProblemListProps, Problem
|
|||||||
getProblemAlerts={this.props.getProblemAlerts}
|
getProblemAlerts={this.props.getProblemAlerts}
|
||||||
onProblemAck={this.handleProblemAck}
|
onProblemAck={this.handleProblemAck}
|
||||||
onTagClick={this.handleTagClick}
|
onTagClick={this.handleTagClick}
|
||||||
|
subRows={false}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
expanded={this.getExpandedPage(this.state.page)}
|
expanded={this.getExpandedPage(this.state.page)}
|
||||||
@@ -179,7 +180,7 @@ export default class ProblemList extends PureComponent<ProblemListProps, Problem
|
|||||||
function SeverityCell(props: RTCell<ZBXTrigger>, problemSeverityDesc: TriggerSeverity[], markAckEvents?: boolean, ackEventColor?: string) {
|
function SeverityCell(props: RTCell<ZBXTrigger>, problemSeverityDesc: TriggerSeverity[], markAckEvents?: boolean, ackEventColor?: string) {
|
||||||
const problem = props.original;
|
const problem = props.original;
|
||||||
let color: string;
|
let color: string;
|
||||||
|
|
||||||
let severityDesc: TriggerSeverity;
|
let severityDesc: TriggerSeverity;
|
||||||
severityDesc = _.find(problemSeverityDesc, s => s.priority === Number(props.original.priority));
|
severityDesc = _.find(problemSeverityDesc, s => s.priority === Number(props.original.priority));
|
||||||
if (problem.lastEvent && problem.lastEvent.severity) {
|
if (problem.lastEvent && problem.lastEvent.severity) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { DataQuery } from '@grafana/ui/';
|
import { DataQuery } from '@grafana/data';
|
||||||
import * as utils from '../datasource-zabbix/utils';
|
import * as utils from '../datasource-zabbix/utils';
|
||||||
import { ZBXTrigger } from './types';
|
import { ZBXTrigger } from './types';
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// DEPENDENCIES
|
// DEPENDENCIES
|
||||||
@import '../../node_modules/react-table/react-table.css';
|
@import '../../node_modules/react-table-6/react-table.css';
|
||||||
|
|
||||||
@import 'variables';
|
@import 'variables';
|
||||||
@import 'panel-triggers';
|
@import 'panel-triggers';
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ module.exports = {
|
|||||||
externals: [
|
externals: [
|
||||||
// remove the line below if you don't want to use builtin versions
|
// remove the line below if you don't want to use builtin versions
|
||||||
'jquery', 'lodash', 'moment', 'angular', 'emotion',
|
'jquery', 'lodash', 'moment', 'angular', 'emotion',
|
||||||
'react', 'react-dom', '@grafana/ui', '@grafana/data',
|
'react', 'react-dom', '@grafana/ui', '@grafana/data', '@grafana/runtime',
|
||||||
function (context, request, callback) {
|
function (context, request, callback) {
|
||||||
var prefix = 'grafana/';
|
var prefix = 'grafana/';
|
||||||
if (request.indexOf(prefix) === 0) {
|
if (request.indexOf(prefix) === 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user