autodetect zabbix version
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -29,6 +29,7 @@ awsconfig
|
||||
/public_gen
|
||||
/tmp
|
||||
vendor/phantomjs/phantomjs
|
||||
yarn-error.log
|
||||
|
||||
# Built plugin
|
||||
dist/
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,8 @@ import responseHandler from './responseHandler';
|
||||
import { Zabbix } from './zabbix/zabbix';
|
||||
import { ZabbixAPIError } from './zabbix/connectors/zabbix_api/zabbixAPICore';
|
||||
|
||||
const DEFAULT_ZABBIX_VERSION = 3;
|
||||
|
||||
export class ZabbixDatasource {
|
||||
|
||||
/** @ngInject */
|
||||
@@ -47,6 +49,7 @@ export class ZabbixDatasource {
|
||||
|
||||
// Other options
|
||||
this.disableReadOnlyUsersAck = jsonData.disableReadOnlyUsersAck;
|
||||
this.zabbixVersion = jsonData.zabbixVersion || DEFAULT_ZABBIX_VERSION;
|
||||
|
||||
// Direct DB Connection options
|
||||
this.enableDirectDBConnection = jsonData.dbConnectionEnable || false;
|
||||
@@ -59,6 +62,7 @@ export class ZabbixDatasource {
|
||||
password: this.password,
|
||||
basicAuth: this.basicAuth,
|
||||
withCredentials: this.withCredentials,
|
||||
zabbixVersion: this.zabbixVersion,
|
||||
cacheTTL: this.cacheTTL,
|
||||
enableDirectDBConnection: this.enableDirectDBConnection,
|
||||
dbConnectionDatasourceId: this.dbConnectionDatasourceId,
|
||||
@@ -380,6 +384,20 @@ export class ZabbixDatasource {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Zabbix version
|
||||
*/
|
||||
getVersion() {
|
||||
return this.zabbix.getVersion()
|
||||
.then(version => {
|
||||
const zabbixVersion = utils.parseVersion(version);
|
||||
if (!zabbixVersion) {
|
||||
return null;
|
||||
}
|
||||
return zabbixVersion.major;
|
||||
});
|
||||
}
|
||||
|
||||
////////////////
|
||||
// Templating //
|
||||
////////////////
|
||||
|
||||
@@ -67,12 +67,21 @@
|
||||
Zabbix data source caches metric names in memory. Specify how often data will be updated.
|
||||
</info-popover>
|
||||
</span>
|
||||
<input class="gf-form-input max-width-5"
|
||||
<input class="gf-form-input max-width-7"
|
||||
type="text"
|
||||
ng-model='ctrl.current.jsonData.cacheTTL'
|
||||
placeholder="1h">
|
||||
</input>
|
||||
</div>
|
||||
|
||||
<div class="gf-form max-width-20">
|
||||
<span class="gf-form-label width-12">Zabbix version</span>
|
||||
<div class="gf-form-select-wrapper max-width-7">
|
||||
<select class="gf-form-input" ng-model="ctrl.current.jsonData.zabbixVersion"
|
||||
ng-options="s.value as s.name for s in ctrl.zabbixVersions">
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="gf-form-group">
|
||||
|
||||
@@ -240,6 +240,24 @@ export function sequence(funcsArray) {
|
||||
};
|
||||
}
|
||||
|
||||
const versionPattern = /^(\d+)(?:\.(\d+))?(?:\.(\d+))?(?:-([0-9A-Za-z\.]+))?/;
|
||||
|
||||
export function isValidVersion(version) {
|
||||
return versionPattern.exec(version);
|
||||
}
|
||||
|
||||
export function parseVersion(version) {
|
||||
const match = versionPattern.exec(version);
|
||||
if (!match) {
|
||||
return null;
|
||||
}
|
||||
const major = Number(match[1]);
|
||||
const minor = Number(match[2] || 0);
|
||||
const patch = Number(match[3] || 0);
|
||||
const meta = match[4];
|
||||
return { major, minor, patch, meta };
|
||||
}
|
||||
|
||||
// Fix for backward compatibility with lodash 2.4
|
||||
if (!_.includes) {
|
||||
_.includes = _.contains;
|
||||
|
||||
@@ -92,7 +92,8 @@ export class ZabbixAPIConnector {
|
||||
acknowledgeEvent(eventid, message) {
|
||||
var params = {
|
||||
eventids: eventid,
|
||||
message: message
|
||||
message: message,
|
||||
action: 6
|
||||
};
|
||||
|
||||
return this.request('event.acknowledge', params);
|
||||
|
||||
Reference in New Issue
Block a user