use direct db connection datasource name for provisioning, #614
This commit is contained in:
@@ -51,16 +51,21 @@ System.register(['lodash'], function (_export, _context) {
|
||||
value: function loadDBDataSource() {
|
||||
var _this = this;
|
||||
|
||||
var ds = _.find(this.datasourceSrv.getAll(), { 'id': this.datasourceId });
|
||||
if (ds) {
|
||||
return this.datasourceSrv.loadDatasource(ds.name).then(function (ds) {
|
||||
_this.datasourceName = ds.name;
|
||||
if (!this.datasourceName && this.datasourceId !== undefined) {
|
||||
var ds = _.find(this.datasourceSrv.getAll(), { 'id': this.datasourceId });
|
||||
if (!ds) {
|
||||
return Promise.reject('SQL Data Source with ID ' + this.datasourceId + ' not found');
|
||||
}
|
||||
this.datasourceName = ds.name;
|
||||
}
|
||||
if (this.datasourceName) {
|
||||
return this.datasourceSrv.loadDatasource(this.datasourceName).then(function (ds) {
|
||||
_this.datasourceTypeId = ds.meta.id;
|
||||
_this.datasourceTypeName = ds.meta.name;
|
||||
return ds;
|
||||
});
|
||||
} else {
|
||||
return Promise.reject('SQL Data Source with ID ' + this.datasourceId + ' not found');
|
||||
return Promise.reject('SQL Data Source name should be specified');
|
||||
}
|
||||
}
|
||||
}, {
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"version":3,"sources":["../../../../src/datasource-zabbix/zabbix/connectors/dbConnector.js"],"names":["_","DBConnector","options","backendSrv","datasourceSrv","datasourceId","datasourceName","datasourceTypeId","datasourceTypeName","ds","find","getAll","loadDatasource","name","then","meta","id","Promise","reject","ZabbixNotImplemented","methodName","code","message"],"mappings":";;;;;;;;;;;;;;;AAAOA,O;;;;;;;;;;;;;;;;;;;;;AAMcC,iB;AACnB,6BAAYC,OAAZ,EAAqBC,UAArB,EAAiCC,aAAjC,EAAgD;AAAA;;AAC9C,eAAKD,UAAL,GAAkBA,UAAlB;AACA,eAAKC,aAAL,GAAqBA,aAArB;AACA,eAAKC,YAAL,GAAoBH,QAAQG,YAA5B;AACA,eAAKC,cAAL,GAAsBJ,QAAQI,cAA9B;AACA,eAAKC,gBAAL,GAAwB,IAAxB;AACA,eAAKC,kBAAL,GAA0B,IAA1B;AACD;;;;6CAEkB;AAAA;;AACjB,gBAAIC,KAAKT,EAAEU,IAAF,CAAO,KAAKN,aAAL,CAAmBO,MAAnB,EAAP,EAAoC,EAAC,MAAM,KAAKN,YAAZ,EAApC,CAAT;AACA,gBAAII,EAAJ,EAAQ;AACN,qBAAO,KAAKL,aAAL,CAAmBQ,cAAnB,CAAkCH,GAAGI,IAArC,EACNC,IADM,CACD,cAAM;AACV,sBAAKR,cAAL,GAAsBG,GAAGI,IAAzB;AACA,sBAAKN,gBAAL,GAAwBE,GAAGM,IAAH,CAAQC,EAAhC;AACA,sBAAKR,kBAAL,GAA0BC,GAAGM,IAAH,CAAQF,IAAlC;AACA,uBAAOJ,EAAP;AACD,eANM,CAAP;AAOD,aARD,MAQO;AACL,qBAAOQ,QAAQC,MAAR,8BAA0C,KAAKb,YAA/C,gBAAP;AACD;AACF;;;2CAKgB;AACf,kBAAM,IAAIc,oBAAJ,CAAyB,kBAAzB,CAAN;AACD;;;uCAKY;AACX,kBAAM,IAAIA,oBAAJ,CAAyB,cAAzB,CAAN;AACD;;;sCAKW;AACV,kBAAM,IAAIA,oBAAJ,CAAyB,aAAzB,CAAN;AACD;;;;;;yBA5CkBlB,W;;sCAgDRkB,oB;AACX,sCAAYC,UAAZ,EAAwB;AAAA;;AACtB,eAAKC,IAAL,GAAY,IAAZ;AACA,eAAKR,IAAL,GAAY,sBAAZ;AACA,eAAKS,OAAL,2CAAoDF,cAAc,EAAlE;AACD;;;;qCAEU;AACT,mBAAO,KAAKE,OAAZ;AACD","file":"dbConnector.js","sourcesContent":["import _ from 'lodash';\n\n/**\n * Base class for external history database connectors. Subclasses should implement `getHistory()`, `getTrends()` and\n * `testDataSource()` methods, which describe how to fetch data from source other than Zabbix API.\n */\nexport default class DBConnector {\n constructor(options, backendSrv, datasourceSrv) {\n this.backendSrv = backendSrv;\n this.datasourceSrv = datasourceSrv;\n this.datasourceId = options.datasourceId;\n this.datasourceName = options.datasourceName;\n this.datasourceTypeId = null;\n this.datasourceTypeName = null;\n }\n\n loadDBDataSource() {\n let ds = _.find(this.datasourceSrv.getAll(), {'id': this.datasourceId});\n if (ds) {\n return this.datasourceSrv.loadDatasource(ds.name)\n .then(ds => {\n this.datasourceName = ds.name;\n this.datasourceTypeId = ds.meta.id;\n this.datasourceTypeName = ds.meta.name;\n return ds;\n });\n } else {\n return Promise.reject(`SQL Data Source with ID ${this.datasourceId} not found`);\n }\n }\n\n /**\n * Send test request to datasource in order to ensure it's working.\n */\n testDataSource() {\n throw new ZabbixNotImplemented('testDataSource()');\n }\n\n /**\n * Get history data from external sources.\n */\n getHistory() {\n throw new ZabbixNotImplemented('getHistory()');\n }\n\n /**\n * Get trends data from external sources.\n */\n getTrends() {\n throw new ZabbixNotImplemented('getTrends()');\n }\n}\n\n// Define Zabbix DB Connector exception type for non-implemented methods\nexport class ZabbixNotImplemented {\n constructor(methodName) {\n this.code = null;\n this.name = 'ZabbixNotImplemented';\n this.message = `Zabbix DB Connector Error: method ${methodName || ''} should be implemented in subclass of DBConnector`;\n }\n\n toString() {\n return this.message;\n }\n}\n"]}
|
||||
{"version":3,"sources":["../../../../src/datasource-zabbix/zabbix/connectors/dbConnector.js"],"names":["_","DBConnector","options","backendSrv","datasourceSrv","datasourceId","datasourceName","datasourceTypeId","datasourceTypeName","undefined","ds","find","getAll","Promise","reject","name","loadDatasource","then","meta","id","ZabbixNotImplemented","methodName","code","message"],"mappings":";;;;;;;;;;;;;;;AAAOA,O;;;;;;;;;;;;;;;;;;;;;AAMcC,iB;AACnB,6BAAYC,OAAZ,EAAqBC,UAArB,EAAiCC,aAAjC,EAAgD;AAAA;;AAC9C,eAAKD,UAAL,GAAkBA,UAAlB;AACA,eAAKC,aAAL,GAAqBA,aAArB;AACA,eAAKC,YAAL,GAAoBH,QAAQG,YAA5B;AACA,eAAKC,cAAL,GAAsBJ,QAAQI,cAA9B;AACA,eAAKC,gBAAL,GAAwB,IAAxB;AACA,eAAKC,kBAAL,GAA0B,IAA1B;AACD;;;;6CAEkB;AAAA;;AACjB,gBAAI,CAAC,KAAKF,cAAN,IAAwB,KAAKD,YAAL,KAAsBI,SAAlD,EAA6D;AAC3D,kBAAIC,KAAKV,EAAEW,IAAF,CAAO,KAAKP,aAAL,CAAmBQ,MAAnB,EAAP,EAAoC,EAAC,MAAM,KAAKP,YAAZ,EAApC,CAAT;AACA,kBAAI,CAACK,EAAL,EAAS;AACP,uBAAOG,QAAQC,MAAR,8BAA0C,KAAKT,YAA/C,gBAAP;AACD;AACD,mBAAKC,cAAL,GAAsBI,GAAGK,IAAzB;AACD;AACD,gBAAI,KAAKT,cAAT,EAAyB;AACvB,qBAAO,KAAKF,aAAL,CAAmBY,cAAnB,CAAkC,KAAKV,cAAvC,EACNW,IADM,CACD,cAAM;AACV,sBAAKV,gBAAL,GAAwBG,GAAGQ,IAAH,CAAQC,EAAhC;AACA,sBAAKX,kBAAL,GAA0BE,GAAGQ,IAAH,CAAQH,IAAlC;AACA,uBAAOL,EAAP;AACD,eALM,CAAP;AAMD,aAPD,MAOO;AACL,qBAAOG,QAAQC,MAAR,4CAAP;AACD;AACF;;;2CAKgB;AACf,kBAAM,IAAIM,oBAAJ,CAAyB,kBAAzB,CAAN;AACD;;;uCAKY;AACX,kBAAM,IAAIA,oBAAJ,CAAyB,cAAzB,CAAN;AACD;;;sCAKW;AACV,kBAAM,IAAIA,oBAAJ,CAAyB,aAAzB,CAAN;AACD;;;;;;yBAjDkBnB,W;;sCAqDRmB,oB;AACX,sCAAYC,UAAZ,EAAwB;AAAA;;AACtB,eAAKC,IAAL,GAAY,IAAZ;AACA,eAAKP,IAAL,GAAY,sBAAZ;AACA,eAAKQ,OAAL,2CAAoDF,cAAc,EAAlE;AACD;;;;qCAEU;AACT,mBAAO,KAAKE,OAAZ;AACD","file":"dbConnector.js","sourcesContent":["import _ from 'lodash';\n\n/**\n * Base class for external history database connectors. Subclasses should implement `getHistory()`, `getTrends()` and\n * `testDataSource()` methods, which describe how to fetch data from source other than Zabbix API.\n */\nexport default class DBConnector {\n constructor(options, backendSrv, datasourceSrv) {\n this.backendSrv = backendSrv;\n this.datasourceSrv = datasourceSrv;\n this.datasourceId = options.datasourceId;\n this.datasourceName = options.datasourceName;\n this.datasourceTypeId = null;\n this.datasourceTypeName = null;\n }\n\n loadDBDataSource() {\n if (!this.datasourceName && this.datasourceId !== undefined) {\n let ds = _.find(this.datasourceSrv.getAll(), {'id': this.datasourceId});\n if (!ds) {\n return Promise.reject(`SQL Data Source with ID ${this.datasourceId} not found`);\n }\n this.datasourceName = ds.name;\n }\n if (this.datasourceName) {\n return this.datasourceSrv.loadDatasource(this.datasourceName)\n .then(ds => {\n this.datasourceTypeId = ds.meta.id;\n this.datasourceTypeName = ds.meta.name;\n return ds;\n });\n } else {\n return Promise.reject(`SQL Data Source name should be specified`);\n }\n }\n\n /**\n * Send test request to datasource in order to ensure it's working.\n */\n testDataSource() {\n throw new ZabbixNotImplemented('testDataSource()');\n }\n\n /**\n * Get history data from external sources.\n */\n getHistory() {\n throw new ZabbixNotImplemented('getHistory()');\n }\n\n /**\n * Get trends data from external sources.\n */\n getTrends() {\n throw new ZabbixNotImplemented('getTrends()');\n }\n}\n\n// Define Zabbix DB Connector exception type for non-implemented methods\nexport class ZabbixNotImplemented {\n constructor(methodName) {\n this.code = null;\n this.name = 'ZabbixNotImplemented';\n this.message = `Zabbix DB Connector Error: method ${methodName || ''} should be implemented in subclass of DBConnector`;\n }\n\n toString() {\n return this.message;\n }\n}\n"]}
|
||||
8
dist/datasource-zabbix/zabbix/zabbix.js
vendored
8
dist/datasource-zabbix/zabbix/zabbix.js
vendored
@@ -174,7 +174,8 @@ System.register(['lodash', '../utils', '../responseHandler', './connectors/zabbi
|
||||
withCredentials = options.withCredentials,
|
||||
cacheTTL = options.cacheTTL,
|
||||
enableDirectDBConnection = options.enableDirectDBConnection,
|
||||
datasourceId = options.datasourceId;
|
||||
dbConnectionDatasourceId = options.dbConnectionDatasourceId,
|
||||
dbConnectionDatasourceName = options.dbConnectionDatasourceName;
|
||||
|
||||
|
||||
this.enableDirectDBConnection = enableDirectDBConnection;
|
||||
@@ -189,7 +190,10 @@ System.register(['lodash', '../utils', '../responseHandler', './connectors/zabbi
|
||||
this.zabbixAPI = new ZabbixAPIConnector(url, username, password, basicAuth, withCredentials, backendSrv);
|
||||
|
||||
if (enableDirectDBConnection) {
|
||||
var dbConnectorOptions = { datasourceId: datasourceId };
|
||||
var dbConnectorOptions = {
|
||||
datasourceId: dbConnectionDatasourceId,
|
||||
datasourceName: dbConnectionDatasourceName
|
||||
};
|
||||
this.dbConnector = new SQLConnector(dbConnectorOptions, backendSrv, datasourceSrv);
|
||||
this.getHistoryDB = this.cachingProxy.proxyfyWithCache(this.dbConnector.getHistory, 'getHistory', this.dbConnector);
|
||||
this.getTrendsDB = this.cachingProxy.proxyfyWithCache(this.dbConnector.getTrends, 'getTrends', this.dbConnector);
|
||||
|
||||
2
dist/datasource-zabbix/zabbix/zabbix.js.map
vendored
2
dist/datasource-zabbix/zabbix/zabbix.js.map
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user