mysql-connector: test MySQL data source during ds config

This commit is contained in:
Alexander Zobnin
2017-07-25 13:02:59 +03:00
parent ffeaeab988
commit 4ec84b21e5
8 changed files with 86 additions and 17 deletions

View File

@@ -526,6 +526,12 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
return this.zabbix.getVersion().then(function (version) {
zabbixVersion = version;
return _this5.zabbix.login();
}).then(function () {
if (_this5.enableDirectDBConnection) {
return _this5.zabbix.dbConnector.testSQLDataSource();
} else {
return Promise.resolve();
}
}).then(function () {
return {
status: "success",
@@ -539,6 +545,12 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
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",

File diff suppressed because one or more lines are too long

View File

@@ -24,11 +24,14 @@ System.register(['angular', 'lodash'], function (_export, _context) {
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
*/
_createClass(ZabbixDBConnector, [{
key: 'loadSQLDataSource',
value: function loadSQLDataSource(datasourceId) {
@@ -41,6 +44,12 @@ System.register(['angular', 'lodash'], function (_export, _context) {
return Promise.reject('SQL Data Source with ID ' + datasourceId + ' not found');
}
}
}, {
key: 'testSQLDataSource',
value: function testSQLDataSource() {
var testQuery = 'SELECT itemid AS metric, clock AS time_sec, value_avg AS value FROM trends_uint LIMIT 1';
return this.invokeSQLQuery(testQuery);
}
}, {
key: 'getHistory',
value: function getHistory(items, timeFrom, timeTill, options) {
@@ -60,7 +69,7 @@ System.register(['angular', 'lodash'], function (_export, _context) {
var itemids = _.map(items, 'itemid').join(', ');
var table = HISTORY_TO_TABLE_MAP[value_type];
var query = '\n SELECT itemid AS metric, clock AS time_sec, ' + aggFunction + '(value) as value\n FROM ' + table + '\n WHERE itemid IN (' + itemids + ')\n AND clock > ' + timeFrom + ' AND clock < ' + timeTill + '\n GROUP BY time_sec DIV ' + intervalSec + ', metric\n ';
var query = '\n SELECT itemid AS metric, clock AS time_sec, ' + aggFunction + '(value) AS value\n FROM ' + table + '\n WHERE itemid IN (' + itemids + ')\n AND clock > ' + timeFrom + ' AND clock < ' + timeTill + '\n GROUP BY time_sec DIV ' + intervalSec + ', metric\n ';
query = compactSQLQuery(query);
return _this.invokeSQLQuery(query);
@@ -91,7 +100,7 @@ System.register(['angular', 'lodash'], function (_export, _context) {
var valueColumn = _.includes(['avg', 'min', 'max'], consolidateBy) ? consolidateBy : 'avg';
valueColumn = consolidateByTrendColumns[valueColumn];
var query = '\n SELECT itemid AS metric, clock AS time_sec, ' + aggFunction + '(' + valueColumn + ') as value\n FROM ' + table + '\n WHERE itemid IN (' + itemids + ')\n AND clock > ' + timeFrom + ' AND clock < ' + timeTill + '\n GROUP BY time_sec DIV ' + intervalSec + ', metric\n ';
var query = '\n SELECT itemid AS metric, clock AS time_sec, ' + aggFunction + '(' + valueColumn + ') AS value\n FROM ' + table + '\n WHERE itemid IN (' + itemids + ')\n AND clock > ' + timeFrom + ' AND clock < ' + timeTill + '\n GROUP BY time_sec DIV ' + intervalSec + ', metric\n ';
query = compactSQLQuery(query);
return _this2.invokeSQLQuery(query);

File diff suppressed because one or more lines are too long