Skip to content

Commit

Permalink
Fix ds provisioning with direct DB connection enabled (#723)
Browse files Browse the repository at this point in the history
* fix ds provisioning with direct DB connection #711

* fix linter error
  • Loading branch information
alexanderzobnin authored Apr 19, 2019
1 parent e4bbecb commit 869634e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
19 changes: 18 additions & 1 deletion src/datasource-zabbix/config.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/datasource-zabbix/partials/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ <h3 class="page-heading">Zabbix API details</h3>
<h3 class="page-heading">Direct DB Connection</h3>
<gf-form-switch class="gf-form" label-class="width-12"
label="Enable"
checked="ctrl.current.jsonData.dbConnectionEnable">
checked="ctrl.dbConnectionEnable">
</gf-form-switch>
<div ng-if="ctrl.current.jsonData.dbConnectionEnable">
<div ng-if="ctrl.dbConnectionEnable">
<div class="gf-form max-width-30">
<span class="gf-form-label width-12">
Data Source
Expand All @@ -103,7 +103,7 @@ <h3 class="page-heading">Direct DB Connection</h3>
</info-popover>
</span>
<div class="gf-form-select-wrapper max-width-16">
<select class="gf-form-input" ng-model="ctrl.current.jsonData.dbConnectionDatasourceId"
<select class="gf-form-input" ng-model="ctrl.dbConnectionDatasourceId"
ng-options="ds.id as ds.name for ds in ctrl.dbDataSources">
</select>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/datasource-zabbix/specs/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
];
Expand Down
3 changes: 3 additions & 0 deletions src/datasource-zabbix/zabbix/connectors/dbConnector.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ export class DBConnector {
if (!this.datasourceName) {
this.datasourceName = ds.name;
}
if (!this.datasourceId) {
this.datasourceId = ds.id;
}
return ds;
});
}
Expand Down

0 comments on commit 869634e

Please sign in to comment.