mysql-connector: test MySQL data source during ds config
This commit is contained in:
@@ -318,6 +318,13 @@ class ZabbixAPIDatasource {
|
||||
zabbixVersion = version;
|
||||
return this.zabbix.login();
|
||||
})
|
||||
.then(() => {
|
||||
if (this.enableDirectDBConnection) {
|
||||
return this.zabbix.dbConnector.testSQLDataSource();
|
||||
} else {
|
||||
return Promise.resolve();
|
||||
}
|
||||
})
|
||||
.then(() => {
|
||||
return {
|
||||
status: "success",
|
||||
@@ -332,6 +339,12 @@ class ZabbixAPIDatasource {
|
||||
title: error.message,
|
||||
message: error.data
|
||||
};
|
||||
} else if (error.data && error.data.message) {
|
||||
return {
|
||||
status: "error",
|
||||
title: "Connection failed",
|
||||
message: error.data.message
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
status: "error",
|
||||
|
||||
@@ -39,11 +39,12 @@ function ZabbixDBConnectorFactory(datasourceSrv, backendSrv) {
|
||||
|
||||
this.sqlDataSourceId = sqlDataSourceId;
|
||||
this.limit = limit || DEFAULT_QUERY_LIMIT;
|
||||
|
||||
// Try to load DS with given id to check it's exist
|
||||
this.loadSQLDataSource(sqlDataSourceId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to load DS with given id to check it's exist.
|
||||
* @param {*} datasourceId ID of SQL data source
|
||||
*/
|
||||
loadSQLDataSource(datasourceId) {
|
||||
let ds = _.find(datasourceSrv.getAll(), {'id': datasourceId});
|
||||
if (ds) {
|
||||
@@ -56,6 +57,14 @@ function ZabbixDBConnectorFactory(datasourceSrv, backendSrv) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to invoke test query for one of Zabbix database tables.
|
||||
*/
|
||||
testSQLDataSource() {
|
||||
let testQuery = `SELECT itemid AS metric, clock AS time_sec, value_avg AS value FROM trends_uint LIMIT 1`;
|
||||
return this.invokeSQLQuery(testQuery);
|
||||
}
|
||||
|
||||
getHistory(items, timeFrom, timeTill, options) {
|
||||
let {intervalMs, consolidateBy} = options;
|
||||
let intervalSec = Math.ceil(intervalMs / 1000);
|
||||
@@ -70,7 +79,7 @@ function ZabbixDBConnectorFactory(datasourceSrv, backendSrv) {
|
||||
let table = HISTORY_TO_TABLE_MAP[value_type];
|
||||
|
||||
let query = `
|
||||
SELECT itemid AS metric, clock AS time_sec, ${aggFunction}(value) as value
|
||||
SELECT itemid AS metric, clock AS time_sec, ${aggFunction}(value) AS value
|
||||
FROM ${table}
|
||||
WHERE itemid IN (${itemids})
|
||||
AND clock > ${timeFrom} AND clock < ${timeTill}
|
||||
@@ -102,7 +111,7 @@ function ZabbixDBConnectorFactory(datasourceSrv, backendSrv) {
|
||||
valueColumn = consolidateByTrendColumns[valueColumn];
|
||||
|
||||
let query = `
|
||||
SELECT itemid AS metric, clock AS time_sec, ${aggFunction}(${valueColumn}) as value
|
||||
SELECT itemid AS metric, clock AS time_sec, ${aggFunction}(${valueColumn}) AS value
|
||||
FROM ${table}
|
||||
WHERE itemid IN (${itemids})
|
||||
AND clock > ${timeFrom} AND clock < ${timeTill}
|
||||
|
||||
Reference in New Issue
Block a user