From 869634ef62a88c0186278be59dc540c033f573c6 Mon Sep 17 00:00:00 2001 From: Alexander Zobnin Date: Fri, 19 Apr 2019 12:56:51 +0300 Subject: [PATCH] Fix ds provisioning with direct DB connection enabled (#723) * fix ds provisioning with direct DB connection #711 * fix linter error --- src/datasource-zabbix/config.controller.js | 19 ++++++++++++++++++- src/datasource-zabbix/partials/config.html | 6 +++--- src/datasource-zabbix/specs/utils.spec.js | 2 +- .../zabbix/connectors/dbConnector.js | 3 +++ 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/src/datasource-zabbix/config.controller.js b/src/datasource-zabbix/config.controller.js index 0c875947e..342c4f046 100644 --- a/src/datasource-zabbix/config.controller.js +++ b/src/datasource-zabbix/config.controller.js @@ -28,9 +28,16 @@ export class ZabbixDSConfigController { this.current.jsonData = migrateDSConfig(this.current.jsonData); _.defaults(this.current.jsonData, defaultConfig); + + this.dbConnectionEnable = this.current.jsonData.dbConnectionEnable; + this.dbConnectionDatasourceId = this.current.jsonData.dbConnectionDatasourceId; + this.dbDataSources = this.getSupportedDBDataSources(); this.zabbixVersions = _.cloneDeep(zabbixVersions); this.autoDetectZabbixVersion(); + if (!this.dbConnectionDatasourceId) { + this.loadCurrentDBDatasource(); + } } getSupportedDBDataSources() { @@ -41,11 +48,21 @@ export class ZabbixDSConfigController { } getCurrentDatasourceType() { - const dsId = this.current.jsonData.dbConnectionDatasourceId; + const dsId = this.dbConnectionDatasourceId; const currentDs = _.find(this.dbDataSources, { 'id': dsId }); return currentDs ? currentDs.type : null; } + loadCurrentDBDatasource() { + const dsName= this.current.jsonData.dbConnectionDatasourceName; + this.datasourceSrv.loadDatasource(dsName) + .then(ds => { + if (ds) { + this.dbConnectionDatasourceId = ds.id; + } + }); + } + autoDetectZabbixVersion() { if (!this.current.id) { return; diff --git a/src/datasource-zabbix/partials/config.html b/src/datasource-zabbix/partials/config.html index 1e9f6821f..8fd1ac134 100644 --- a/src/datasource-zabbix/partials/config.html +++ b/src/datasource-zabbix/partials/config.html @@ -88,9 +88,9 @@

Zabbix API details

Direct DB Connection

+ checked="ctrl.dbConnectionEnable"> -
+
Data Source @@ -103,7 +103,7 @@

Direct DB Connection

-
diff --git a/src/datasource-zabbix/specs/utils.spec.js b/src/datasource-zabbix/specs/utils.spec.js index 3367f1f9e..01cc76fe4 100644 --- a/src/datasource-zabbix/specs/utils.spec.js +++ b/src/datasource-zabbix/specs/utils.spec.js @@ -155,7 +155,7 @@ describe('Utils', () => { depth: 2 }, { - array: [ [[1, 2], [3, 4]], [[1, 2], [3, 4]] ], + array: [[[1, 2], [3, 4]], [[1, 2], [3, 4]]], depth: 3 }, ]; diff --git a/src/datasource-zabbix/zabbix/connectors/dbConnector.js b/src/datasource-zabbix/zabbix/connectors/dbConnector.js index 8f3ee5ac3..c4039a165 100644 --- a/src/datasource-zabbix/zabbix/connectors/dbConnector.js +++ b/src/datasource-zabbix/zabbix/connectors/dbConnector.js @@ -65,6 +65,9 @@ export class DBConnector { if (!this.datasourceName) { this.datasourceName = ds.name; } + if (!this.datasourceId) { + this.datasourceId = ds.id; + } return ds; }); }