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 @@