autodetect zabbix version

This commit is contained in:
Alexander Zobnin
2018-10-18 20:27:23 +03:00
parent a3f50904ce
commit 92a08a5c58
6 changed files with 77 additions and 3 deletions

View File

@@ -2,6 +2,11 @@ import _ from 'lodash';
import { migrateDSConfig } from './migrations';
const SUPPORTED_SQL_DS = ['mysql', 'postgres'];
const zabbixVersions = [
{ name: '2.x', value: 2 },
{ name: '3.x', value: 3 },
{ name: '4.x', value: 4 },
];
const defaultConfig = {
trends: false,
@@ -10,7 +15,8 @@ const defaultConfig = {
alerting: false,
addThresholds: false,
alertingMinSeverity: 3,
disableReadOnlyUsersAck: false
disableReadOnlyUsersAck: false,
zabbixVersion: 3,
};
export class ZabbixDSConfigController {
@@ -22,6 +28,8 @@ export class ZabbixDSConfigController {
this.current.jsonData = migrateDSConfig(this.current.jsonData);
_.defaults(this.current.jsonData, defaultConfig);
this.sqlDataSources = this.getSupportedSQLDataSources();
this.zabbixVersions = _.cloneDeep(zabbixVersions);
this.autoDetectZabbixVersion();
}
getSupportedSQLDataSources() {
@@ -30,4 +38,23 @@ export class ZabbixDSConfigController {
return _.includes(SUPPORTED_SQL_DS, ds.type);
});
}
autoDetectZabbixVersion() {
if (!this.current.id) {
return;
}
this.datasourceSrv.loadDatasource(this.current.name)
.then(ds => {
return ds.getVersion();
})
.then(version => {
if (version) {
if (!_.find(zabbixVersions, ['value', version])) {
this.zabbixVersions.push({ name: version + '.x', value: version });
}
this.current.jsonData.zabbixVersion = version;
}
});
}
}