mysql-connector: add config options for selecting data source
and load SQL data source during plugin init
This commit is contained in:
74
dist/datasource-zabbix/config.controller.js
vendored
Normal file
74
dist/datasource-zabbix/config.controller.js
vendored
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
System.register(['lodash'], function (_export, _context) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var _, _createClass, SUPPORTED_SQL_DS, defaultConfig, ZabbixDSConfigController;
|
||||||
|
|
||||||
|
function _classCallCheck(instance, Constructor) {
|
||||||
|
if (!(instance instanceof Constructor)) {
|
||||||
|
throw new TypeError("Cannot call a class as a function");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
setters: [function (_lodash) {
|
||||||
|
_ = _lodash.default;
|
||||||
|
}],
|
||||||
|
execute: function () {
|
||||||
|
_createClass = function () {
|
||||||
|
function defineProperties(target, props) {
|
||||||
|
for (var i = 0; i < props.length; i++) {
|
||||||
|
var descriptor = props[i];
|
||||||
|
descriptor.enumerable = descriptor.enumerable || false;
|
||||||
|
descriptor.configurable = true;
|
||||||
|
if ("value" in descriptor) descriptor.writable = true;
|
||||||
|
Object.defineProperty(target, descriptor.key, descriptor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return function (Constructor, protoProps, staticProps) {
|
||||||
|
if (protoProps) defineProperties(Constructor.prototype, protoProps);
|
||||||
|
if (staticProps) defineProperties(Constructor, staticProps);
|
||||||
|
return Constructor;
|
||||||
|
};
|
||||||
|
}();
|
||||||
|
|
||||||
|
SUPPORTED_SQL_DS = ['mysql'];
|
||||||
|
defaultConfig = {
|
||||||
|
dbConnection: {
|
||||||
|
enable: false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
_export('ZabbixDSConfigController', ZabbixDSConfigController = function () {
|
||||||
|
/** @ngInject */
|
||||||
|
function ZabbixDSConfigController($scope, $injector, datasourceSrv) {
|
||||||
|
_classCallCheck(this, ZabbixDSConfigController);
|
||||||
|
|
||||||
|
this.datasourceSrv = datasourceSrv;
|
||||||
|
|
||||||
|
_.defaults(this.current.jsonData, defaultConfig);
|
||||||
|
this.sqlDataSources = this.getSupportedSQLDataSources();
|
||||||
|
}
|
||||||
|
|
||||||
|
_createClass(ZabbixDSConfigController, [{
|
||||||
|
key: 'getSupportedSQLDataSources',
|
||||||
|
value: function getSupportedSQLDataSources() {
|
||||||
|
var datasources = this.datasourceSrv.getAll();
|
||||||
|
return _.filter(datasources, function (ds) {
|
||||||
|
return _.includes(SUPPORTED_SQL_DS, ds.type);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}]);
|
||||||
|
|
||||||
|
return ZabbixDSConfigController;
|
||||||
|
}());
|
||||||
|
|
||||||
|
_export('ZabbixDSConfigController', ZabbixDSConfigController);
|
||||||
|
|
||||||
|
ZabbixDSConfigController.templateUrl = 'datasource-zabbix/partials/config.html';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
//# sourceMappingURL=config.controller.js.map
|
||||||
1
dist/datasource-zabbix/config.controller.js.map
vendored
Normal file
1
dist/datasource-zabbix/config.controller.js.map
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"sources":["../../src/datasource-zabbix/config.controller.js"],"names":["_","SUPPORTED_SQL_DS","defaultConfig","dbConnection","enable","ZabbixDSConfigController","$scope","$injector","datasourceSrv","defaults","current","jsonData","sqlDataSources","getSupportedSQLDataSources","datasources","getAll","filter","includes","ds","type","templateUrl"],"mappings":";;;;;;;;;;;;;;;AAAOA,O;;;;;;;;;;;;;;;;;;;;;AAEDC,sB,GAAmB,CAAC,OAAD,C;AAEnBC,mB,GAAgB;AACpBC,sBAAc;AACZC,kBAAQ;AADI;AADM,O;;0CAMTC,wB;AACX;AACA,0CAAYC,MAAZ,EAAoBC,SAApB,EAA+BC,aAA/B,EAA8C;AAAA;;AAC5C,eAAKA,aAAL,GAAqBA,aAArB;;AAEAR,YAAES,QAAF,CAAW,KAAKC,OAAL,CAAaC,QAAxB,EAAkCT,aAAlC;AACA,eAAKU,cAAL,GAAsB,KAAKC,0BAAL,EAAtB;AACD;;;;uDAE4B;AAC3B,gBAAIC,cAAc,KAAKN,aAAL,CAAmBO,MAAnB,EAAlB;AACA,mBAAOf,EAAEgB,MAAF,CAASF,WAAT,EAAsB,cAAM;AACjC,qBAAOd,EAAEiB,QAAF,CAAWhB,gBAAX,EAA6BiB,GAAGC,IAAhC,CAAP;AACD,aAFM,CAAP;AAGD;;;;;;;;AAGHd,+BAAyBe,WAAzB,GAAuC,wCAAvC","file":"config.controller.js","sourcesContent":["import _ from 'lodash';\n\nconst SUPPORTED_SQL_DS = ['mysql'];\n\nconst defaultConfig = {\n dbConnection: {\n enable: false,\n }\n};\n\nexport class ZabbixDSConfigController {\n /** @ngInject */\n constructor($scope, $injector, datasourceSrv) {\n this.datasourceSrv = datasourceSrv;\n\n _.defaults(this.current.jsonData, defaultConfig);\n this.sqlDataSources = this.getSupportedSQLDataSources();\n }\n\n getSupportedSQLDataSources() {\n let datasources = this.datasourceSrv.getAll();\n return _.filter(datasources, ds => {\n return _.includes(SUPPORTED_SQL_DS, ds.type);\n });\n }\n}\n\nZabbixDSConfigController.templateUrl = 'datasource-zabbix/partials/config.html';\n"]}
|
||||||
106
dist/datasource-zabbix/datasource.js
vendored
106
dist/datasource-zabbix/datasource.js
vendored
@@ -183,12 +183,15 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
|||||||
_export('ZabbixAPIDatasource', ZabbixAPIDatasource = function () {
|
_export('ZabbixAPIDatasource', ZabbixAPIDatasource = function () {
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
function ZabbixAPIDatasource(instanceSettings, templateSrv, alertSrv, dashboardSrv, zabbixAlertingSrv, Zabbix) {
|
function ZabbixAPIDatasource(instanceSettings, templateSrv, alertSrv, dashboardSrv, datasourceSrv, zabbixAlertingSrv, Zabbix) {
|
||||||
|
var _this = this;
|
||||||
|
|
||||||
_classCallCheck(this, ZabbixAPIDatasource);
|
_classCallCheck(this, ZabbixAPIDatasource);
|
||||||
|
|
||||||
this.templateSrv = templateSrv;
|
this.templateSrv = templateSrv;
|
||||||
this.alertSrv = alertSrv;
|
this.alertSrv = alertSrv;
|
||||||
this.dashboardSrv = dashboardSrv;
|
this.dashboardSrv = dashboardSrv;
|
||||||
|
this.datasourceSrv = datasourceSrv;
|
||||||
this.zabbixAlertingSrv = zabbixAlertingSrv;
|
this.zabbixAlertingSrv = zabbixAlertingSrv;
|
||||||
|
|
||||||
// General data source settings
|
// General data source settings
|
||||||
@@ -217,35 +220,48 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
|||||||
|
|
||||||
this.zabbix = new Zabbix(this.url, this.username, this.password, this.basicAuth, this.withCredentials, this.cacheTTL);
|
this.zabbix = new Zabbix(this.url, this.username, this.password, this.basicAuth, this.withCredentials, this.cacheTTL);
|
||||||
|
|
||||||
|
// Try to use direct DB connection
|
||||||
|
this.enableDirectDBConnection = instanceSettings.jsonData.dbConnection.enable;
|
||||||
|
if (this.enableDirectDBConnection) {
|
||||||
|
this.loadSQLDataSource(instanceSettings.jsonData.dbConnection.datasourceId).then(function () {}).catch(function (error) {
|
||||||
|
_this.enableDirectDBConnection = false;
|
||||||
|
_this.alertSrv.set("SQL Data Source Error", error, 'error');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Use custom format for template variables
|
// Use custom format for template variables
|
||||||
this.replaceTemplateVars = _.partial(replaceTemplateVars, this.templateSrv);
|
this.replaceTemplateVars = _.partial(replaceTemplateVars, this.templateSrv);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////
|
|
||||||
// Datasource methods //
|
|
||||||
////////////////////////
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Query panel data. Calls for each panel in dashboard.
|
|
||||||
* @param {Object} options Contains time range, targets and other info.
|
|
||||||
* @return {Object} Grafana metrics object with timeseries data for each target.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
_createClass(ZabbixAPIDatasource, [{
|
_createClass(ZabbixAPIDatasource, [{
|
||||||
|
key: 'loadSQLDataSource',
|
||||||
|
value: function loadSQLDataSource(datasourceId) {
|
||||||
|
var _this2 = this;
|
||||||
|
|
||||||
|
var ds = _.find(this.datasourceSrv.getAll(), { 'id': datasourceId });
|
||||||
|
if (ds) {
|
||||||
|
return this.datasourceSrv.loadDatasource(ds.name).then(function (ds) {
|
||||||
|
console.log('Data source loaded', ds);
|
||||||
|
_this2.sqlDataSource = ds;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return Promise.reject('SQL Data Source with ID ' + datasourceId + ' not found');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, {
|
||||||
key: 'query',
|
key: 'query',
|
||||||
value: function query(options) {
|
value: function query(options) {
|
||||||
var _this = this;
|
var _this3 = this;
|
||||||
|
|
||||||
// Get alerts for current panel
|
// Get alerts for current panel
|
||||||
if (this.alertingEnabled) {
|
if (this.alertingEnabled) {
|
||||||
this.alertQuery(options).then(function (alert) {
|
this.alertQuery(options).then(function (alert) {
|
||||||
_this.zabbixAlertingSrv.setPanelAlertState(options.panelId, alert.state);
|
_this3.zabbixAlertingSrv.setPanelAlertState(options.panelId, alert.state);
|
||||||
|
|
||||||
_this.zabbixAlertingSrv.removeZabbixThreshold(options.panelId);
|
_this3.zabbixAlertingSrv.removeZabbixThreshold(options.panelId);
|
||||||
if (_this.addThresholds) {
|
if (_this3.addThresholds) {
|
||||||
_.forEach(alert.thresholds, function (threshold) {
|
_.forEach(alert.thresholds, function (threshold) {
|
||||||
_this.zabbixAlertingSrv.setPanelThreshold(options.panelId, threshold);
|
_this3.zabbixAlertingSrv.setPanelThreshold(options.panelId, threshold);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -258,7 +274,7 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
|||||||
|
|
||||||
// Prevent changes of original object
|
// Prevent changes of original object
|
||||||
var target = _.cloneDeep(t);
|
var target = _.cloneDeep(t);
|
||||||
_this.replaceTargetVariables(target, options);
|
_this3.replaceTargetVariables(target, options);
|
||||||
|
|
||||||
// Apply Time-related functions (timeShift(), etc)
|
// Apply Time-related functions (timeShift(), etc)
|
||||||
var timeFunctions = bindFunctionDefs(target.functions, 'Time');
|
var timeFunctions = bindFunctionDefs(target.functions, 'Time');
|
||||||
@@ -273,7 +289,7 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
|||||||
}
|
}
|
||||||
var timeRange = [timeFrom, timeTo];
|
var timeRange = [timeFrom, timeTo];
|
||||||
|
|
||||||
var useTrends = _this.isUseTrends(timeRange);
|
var useTrends = _this3.isUseTrends(timeRange);
|
||||||
|
|
||||||
// Metrics or Text query mode
|
// Metrics or Text query mode
|
||||||
if (target.mode !== c.MODE_ITSERVICE) {
|
if (target.mode !== c.MODE_ITSERVICE) {
|
||||||
@@ -286,9 +302,9 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!target.mode || target.mode === c.MODE_METRICS) {
|
if (!target.mode || target.mode === c.MODE_METRICS) {
|
||||||
return _this.queryNumericData(target, timeRange, useTrends, options);
|
return _this3.queryNumericData(target, timeRange, useTrends, options);
|
||||||
} else if (target.mode === c.MODE_TEXT) {
|
} else if (target.mode === c.MODE_TEXT) {
|
||||||
return _this.queryTextData(target, timeRange);
|
return _this3.queryTextData(target, timeRange);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -299,7 +315,7 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return _this.zabbix.getSLA(target.itservice.serviceid, timeRange).then(function (slaObject) {
|
return _this3.zabbix.getSLA(target.itservice.serviceid, timeRange).then(function (slaObject) {
|
||||||
return responseHandler.handleSLAResponse(target.itservice, target.slaProperty, slaObject);
|
return responseHandler.handleSLAResponse(target.itservice, target.slaProperty, slaObject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -313,7 +329,7 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
|||||||
}, {
|
}, {
|
||||||
key: 'queryNumericData',
|
key: 'queryNumericData',
|
||||||
value: function queryNumericData(target, timeRange, useTrends, options) {
|
value: function queryNumericData(target, timeRange, useTrends, options) {
|
||||||
var _this2 = this;
|
var _this4 = this;
|
||||||
|
|
||||||
var _timeRange = _slicedToArray(timeRange, 2),
|
var _timeRange = _slicedToArray(timeRange, 2),
|
||||||
timeFrom = _timeRange[0],
|
timeFrom = _timeRange[0],
|
||||||
@@ -326,8 +342,8 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
|||||||
var getHistoryPromise = void 0;
|
var getHistoryPromise = void 0;
|
||||||
|
|
||||||
if (useTrends) {
|
if (useTrends) {
|
||||||
var valueType = _this2.getTrendValueType(target);
|
var valueType = _this4.getTrendValueType(target);
|
||||||
getHistoryPromise = _this2.zabbix.getTrend(items, timeFrom, timeTo).then(function (history) {
|
getHistoryPromise = _this4.zabbix.getTrend(items, timeFrom, timeTo).then(function (history) {
|
||||||
return responseHandler.handleTrends(history, items, valueType);
|
return responseHandler.handleTrends(history, items, valueType);
|
||||||
}).then(function (timeseries) {
|
}).then(function (timeseries) {
|
||||||
// Sort trend data, issue #202
|
// Sort trend data, issue #202
|
||||||
@@ -341,14 +357,14 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Use history
|
// Use history
|
||||||
getHistoryPromise = _this2.zabbix.getHistory(items, timeFrom, timeTo).then(function (history) {
|
getHistoryPromise = _this4.zabbix.getHistory(items, timeFrom, timeTo).then(function (history) {
|
||||||
return responseHandler.handleHistory(history, items);
|
return responseHandler.handleHistory(history, items);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return getHistoryPromise;
|
return getHistoryPromise;
|
||||||
}).then(function (timeseries) {
|
}).then(function (timeseries) {
|
||||||
return _this2.applyDataProcessingFunctions(timeseries, target);
|
return _this4.applyDataProcessingFunctions(timeseries, target);
|
||||||
}).then(function (timeseries) {
|
}).then(function (timeseries) {
|
||||||
return downsampleSeries(timeseries, options);
|
return downsampleSeries(timeseries, options);
|
||||||
}).catch(function (error) {
|
}).catch(function (error) {
|
||||||
@@ -427,7 +443,7 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
|||||||
}, {
|
}, {
|
||||||
key: 'queryTextData',
|
key: 'queryTextData',
|
||||||
value: function queryTextData(target, timeRange) {
|
value: function queryTextData(target, timeRange) {
|
||||||
var _this3 = this;
|
var _this5 = this;
|
||||||
|
|
||||||
var _timeRange2 = _slicedToArray(timeRange, 2),
|
var _timeRange2 = _slicedToArray(timeRange, 2),
|
||||||
timeFrom = _timeRange2[0],
|
timeFrom = _timeRange2[0],
|
||||||
@@ -438,7 +454,7 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
|||||||
};
|
};
|
||||||
return this.zabbix.getItemsFromTarget(target, options).then(function (items) {
|
return this.zabbix.getItemsFromTarget(target, options).then(function (items) {
|
||||||
if (items.length) {
|
if (items.length) {
|
||||||
return _this3.zabbix.getHistory(items, timeFrom, timeTo).then(function (history) {
|
return _this5.zabbix.getHistory(items, timeFrom, timeTo).then(function (history) {
|
||||||
return responseHandler.handleText(history, items, target);
|
return responseHandler.handleText(history, items, target);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -449,12 +465,12 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
|||||||
}, {
|
}, {
|
||||||
key: 'testDatasource',
|
key: 'testDatasource',
|
||||||
value: function testDatasource() {
|
value: function testDatasource() {
|
||||||
var _this4 = this;
|
var _this6 = this;
|
||||||
|
|
||||||
var zabbixVersion = void 0;
|
var zabbixVersion = void 0;
|
||||||
return this.zabbix.getVersion().then(function (version) {
|
return this.zabbix.getVersion().then(function (version) {
|
||||||
zabbixVersion = version;
|
zabbixVersion = version;
|
||||||
return _this4.zabbix.login();
|
return _this6.zabbix.login();
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
return {
|
return {
|
||||||
status: "success",
|
status: "success",
|
||||||
@@ -480,14 +496,14 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
|||||||
}, {
|
}, {
|
||||||
key: 'metricFindQuery',
|
key: 'metricFindQuery',
|
||||||
value: function metricFindQuery(query) {
|
value: function metricFindQuery(query) {
|
||||||
var _this5 = this;
|
var _this7 = this;
|
||||||
|
|
||||||
var result = void 0;
|
var result = void 0;
|
||||||
var parts = [];
|
var parts = [];
|
||||||
|
|
||||||
// Split query. Query structure: group.host.app.item
|
// Split query. Query structure: group.host.app.item
|
||||||
_.each(utils.splitTemplateQuery(query), function (part) {
|
_.each(utils.splitTemplateQuery(query), function (part) {
|
||||||
part = _this5.replaceTemplateVars(part, {});
|
part = _this7.replaceTemplateVars(part, {});
|
||||||
|
|
||||||
// Replace wildcard to regex
|
// Replace wildcard to regex
|
||||||
if (part === '*') {
|
if (part === '*') {
|
||||||
@@ -524,7 +540,7 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
|||||||
}, {
|
}, {
|
||||||
key: 'annotationQuery',
|
key: 'annotationQuery',
|
||||||
value: function annotationQuery(options) {
|
value: function annotationQuery(options) {
|
||||||
var _this6 = this;
|
var _this8 = this;
|
||||||
|
|
||||||
var timeFrom = Math.ceil(dateMath.parse(options.rangeRaw.from) / 1000);
|
var timeFrom = Math.ceil(dateMath.parse(options.rangeRaw.from) / 1000);
|
||||||
var timeTo = Math.ceil(dateMath.parse(options.rangeRaw.to) / 1000);
|
var timeTo = Math.ceil(dateMath.parse(options.rangeRaw.to) / 1000);
|
||||||
@@ -542,7 +558,7 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
|||||||
return getTriggers.then(function (triggers) {
|
return getTriggers.then(function (triggers) {
|
||||||
|
|
||||||
// Filter triggers by description
|
// Filter triggers by description
|
||||||
var triggerName = _this6.replaceTemplateVars(annotation.trigger, {});
|
var triggerName = _this8.replaceTemplateVars(annotation.trigger, {});
|
||||||
if (utils.isRegex(triggerName)) {
|
if (utils.isRegex(triggerName)) {
|
||||||
triggers = _.filter(triggers, function (trigger) {
|
triggers = _.filter(triggers, function (trigger) {
|
||||||
return utils.buildRegex(triggerName).test(trigger.description);
|
return utils.buildRegex(triggerName).test(trigger.description);
|
||||||
@@ -559,7 +575,7 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
|||||||
});
|
});
|
||||||
|
|
||||||
var objectids = _.map(triggers, 'triggerid');
|
var objectids = _.map(triggers, 'triggerid');
|
||||||
return _this6.zabbix.getEvents(objectids, timeFrom, timeTo, showOkEvents).then(function (events) {
|
return _this8.zabbix.getEvents(objectids, timeFrom, timeTo, showOkEvents).then(function (events) {
|
||||||
var indexedTriggers = _.keyBy(triggers, 'triggerid');
|
var indexedTriggers = _.keyBy(triggers, 'triggerid');
|
||||||
|
|
||||||
// Hide acknowledged events if option enabled
|
// Hide acknowledged events if option enabled
|
||||||
@@ -593,23 +609,23 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
|||||||
}, {
|
}, {
|
||||||
key: 'alertQuery',
|
key: 'alertQuery',
|
||||||
value: function alertQuery(options) {
|
value: function alertQuery(options) {
|
||||||
var _this7 = this;
|
var _this9 = this;
|
||||||
|
|
||||||
var enabled_targets = filterEnabledTargets(options.targets);
|
var enabled_targets = filterEnabledTargets(options.targets);
|
||||||
var getPanelItems = _.map(enabled_targets, function (t) {
|
var getPanelItems = _.map(enabled_targets, function (t) {
|
||||||
var target = _.cloneDeep(t);
|
var target = _.cloneDeep(t);
|
||||||
_this7.replaceTargetVariables(target, options);
|
_this9.replaceTargetVariables(target, options);
|
||||||
return _this7.zabbix.getItemsFromTarget(target, { itemtype: 'num' });
|
return _this9.zabbix.getItemsFromTarget(target, { itemtype: 'num' });
|
||||||
});
|
});
|
||||||
|
|
||||||
return Promise.all(getPanelItems).then(function (results) {
|
return Promise.all(getPanelItems).then(function (results) {
|
||||||
var items = _.flatten(results);
|
var items = _.flatten(results);
|
||||||
var itemids = _.map(items, 'itemid');
|
var itemids = _.map(items, 'itemid');
|
||||||
|
|
||||||
return _this7.zabbix.getAlerts(itemids);
|
return _this9.zabbix.getAlerts(itemids);
|
||||||
}).then(function (triggers) {
|
}).then(function (triggers) {
|
||||||
triggers = _.filter(triggers, function (trigger) {
|
triggers = _.filter(triggers, function (trigger) {
|
||||||
return trigger.priority >= _this7.alertingMinSeverity;
|
return trigger.priority >= _this9.alertingMinSeverity;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!triggers || triggers.length === 0) {
|
if (!triggers || triggers.length === 0) {
|
||||||
@@ -637,12 +653,12 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
|||||||
}, {
|
}, {
|
||||||
key: 'replaceTargetVariables',
|
key: 'replaceTargetVariables',
|
||||||
value: function replaceTargetVariables(target, options) {
|
value: function replaceTargetVariables(target, options) {
|
||||||
var _this8 = this;
|
var _this10 = this;
|
||||||
|
|
||||||
var parts = ['group', 'host', 'application', 'item'];
|
var parts = ['group', 'host', 'application', 'item'];
|
||||||
_.forEach(parts, function (p) {
|
_.forEach(parts, function (p) {
|
||||||
if (target[p] && target[p].filter) {
|
if (target[p] && target[p].filter) {
|
||||||
target[p].filter = _this8.replaceTemplateVars(target[p].filter, options.scopedVars);
|
target[p].filter = _this10.replaceTemplateVars(target[p].filter, options.scopedVars);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
target.textFilter = this.replaceTemplateVars(target.textFilter, options.scopedVars);
|
target.textFilter = this.replaceTemplateVars(target.textFilter, options.scopedVars);
|
||||||
@@ -650,9 +666,9 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
|||||||
_.forEach(target.functions, function (func) {
|
_.forEach(target.functions, function (func) {
|
||||||
func.params = _.map(func.params, function (param) {
|
func.params = _.map(func.params, function (param) {
|
||||||
if (typeof param === 'number') {
|
if (typeof param === 'number') {
|
||||||
return +_this8.templateSrv.replace(param.toString(), options.scopedVars);
|
return +_this10.templateSrv.replace(param.toString(), options.scopedVars);
|
||||||
} else {
|
} else {
|
||||||
return _this8.templateSrv.replace(param, options.scopedVars);
|
return _this10.templateSrv.replace(param, options.scopedVars);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
2
dist/datasource-zabbix/datasource.js.map
vendored
2
dist/datasource-zabbix/datasource.js.map
vendored
File diff suppressed because one or more lines are too long
14
dist/datasource-zabbix/module.js
vendored
14
dist/datasource-zabbix/module.js
vendored
@@ -1,9 +1,9 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
System.register(['./datasource', './query.controller'], function (_export, _context) {
|
System.register(['./datasource', './query.controller', './config.controller'], function (_export, _context) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
var ZabbixAPIDatasource, ZabbixQueryController, ZabbixConfigController, ZabbixQueryOptionsController, ZabbixAnnotationsQueryController;
|
var ZabbixAPIDatasource, ZabbixQueryController, ZabbixDSConfigController, ZabbixQueryOptionsController, ZabbixAnnotationsQueryController;
|
||||||
|
|
||||||
function _classCallCheck(instance, Constructor) {
|
function _classCallCheck(instance, Constructor) {
|
||||||
if (!(instance instanceof Constructor)) {
|
if (!(instance instanceof Constructor)) {
|
||||||
@@ -16,14 +16,10 @@ System.register(['./datasource', './query.controller'], function (_export, _cont
|
|||||||
ZabbixAPIDatasource = _datasource.ZabbixAPIDatasource;
|
ZabbixAPIDatasource = _datasource.ZabbixAPIDatasource;
|
||||||
}, function (_queryController) {
|
}, function (_queryController) {
|
||||||
ZabbixQueryController = _queryController.ZabbixQueryController;
|
ZabbixQueryController = _queryController.ZabbixQueryController;
|
||||||
|
}, function (_configController) {
|
||||||
|
ZabbixDSConfigController = _configController.ZabbixDSConfigController;
|
||||||
}],
|
}],
|
||||||
execute: function () {
|
execute: function () {
|
||||||
_export('ConfigCtrl', ZabbixConfigController = function ZabbixConfigController() {
|
|
||||||
_classCallCheck(this, ZabbixConfigController);
|
|
||||||
});
|
|
||||||
|
|
||||||
ZabbixConfigController.templateUrl = 'datasource-zabbix/partials/config.html';
|
|
||||||
|
|
||||||
_export('QueryOptionsCtrl', ZabbixQueryOptionsController = function ZabbixQueryOptionsController() {
|
_export('QueryOptionsCtrl', ZabbixQueryOptionsController = function ZabbixQueryOptionsController() {
|
||||||
_classCallCheck(this, ZabbixQueryOptionsController);
|
_classCallCheck(this, ZabbixQueryOptionsController);
|
||||||
});
|
});
|
||||||
@@ -38,7 +34,7 @@ System.register(['./datasource', './query.controller'], function (_export, _cont
|
|||||||
|
|
||||||
_export('Datasource', ZabbixAPIDatasource);
|
_export('Datasource', ZabbixAPIDatasource);
|
||||||
|
|
||||||
_export('ConfigCtrl', ZabbixConfigController);
|
_export('ConfigCtrl', ZabbixDSConfigController);
|
||||||
|
|
||||||
_export('QueryCtrl', ZabbixQueryController);
|
_export('QueryCtrl', ZabbixQueryController);
|
||||||
|
|
||||||
|
|||||||
2
dist/datasource-zabbix/module.js.map
vendored
2
dist/datasource-zabbix/module.js.map
vendored
@@ -1 +1 @@
|
|||||||
{"version":3,"sources":["../../src/datasource-zabbix/module.js"],"names":["ZabbixAPIDatasource","ZabbixQueryController","ZabbixConfigController","templateUrl","ZabbixQueryOptionsController","ZabbixAnnotationsQueryController"],"mappings":";;;;;;;;;;;;;;;AAAQA,yB,eAAAA,mB;;AACAC,2B,oBAAAA,qB;;;4BAEFC,sB;;;;AACNA,6BAAuBC,WAAvB,GAAqC,wCAArC;;kCAEMC,4B;;;;AACNA,mCAA6BD,WAA7B,GAA2C,+CAA3C;;sCAEME,gC;;;;AACNA,uCAAiCF,WAAjC,GAA+C,oDAA/C;;4BAGEH,mB;;4BACAE,sB;;2BACAD,qB;;kCACAG,4B;;sCACAC,gC","file":"module.js","sourcesContent":["import {ZabbixAPIDatasource} from './datasource';\nimport {ZabbixQueryController} from './query.controller';\n\nclass ZabbixConfigController {}\nZabbixConfigController.templateUrl = 'datasource-zabbix/partials/config.html';\n\nclass ZabbixQueryOptionsController {}\nZabbixQueryOptionsController.templateUrl = 'datasource-zabbix/partials/query.options.html';\n\nclass ZabbixAnnotationsQueryController {}\nZabbixAnnotationsQueryController.templateUrl = 'datasource-zabbix/partials/annotations.editor.html';\n\nexport {\n ZabbixAPIDatasource as Datasource,\n ZabbixConfigController as ConfigCtrl,\n ZabbixQueryController as QueryCtrl,\n ZabbixQueryOptionsController as QueryOptionsCtrl,\n ZabbixAnnotationsQueryController as AnnotationsQueryCtrl\n};\n"]}
|
{"version":3,"sources":["../../src/datasource-zabbix/module.js"],"names":["ZabbixAPIDatasource","ZabbixQueryController","ZabbixDSConfigController","ZabbixQueryOptionsController","templateUrl","ZabbixAnnotationsQueryController"],"mappings":";;;;;;;;;;;;;;;AAAQA,yB,eAAAA,mB;;AACAC,2B,oBAAAA,qB;;AACAC,8B,qBAAAA,wB;;;kCAEFC,4B;;;;AACNA,mCAA6BC,WAA7B,GAA2C,+CAA3C;;sCAEMC,gC;;;;AACNA,uCAAiCD,WAAjC,GAA+C,oDAA/C;;4BAGEJ,mB;;4BACAE,wB;;2BACAD,qB;;kCACAE,4B;;sCACAE,gC","file":"module.js","sourcesContent":["import {ZabbixAPIDatasource} from './datasource';\nimport {ZabbixQueryController} from './query.controller';\nimport {ZabbixDSConfigController} from './config.controller';\n\nclass ZabbixQueryOptionsController {}\nZabbixQueryOptionsController.templateUrl = 'datasource-zabbix/partials/query.options.html';\n\nclass ZabbixAnnotationsQueryController {}\nZabbixAnnotationsQueryController.templateUrl = 'datasource-zabbix/partials/annotations.editor.html';\n\nexport {\n ZabbixAPIDatasource as Datasource,\n ZabbixDSConfigController as ConfigCtrl,\n ZabbixQueryController as QueryCtrl,\n ZabbixQueryOptionsController as QueryOptionsCtrl,\n ZabbixAnnotationsQueryController as AnnotationsQueryCtrl\n};\n"]}
|
||||||
18
dist/datasource-zabbix/partials/config.html
vendored
18
dist/datasource-zabbix/partials/config.html
vendored
@@ -75,6 +75,24 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="gf-form-group">
|
||||||
|
<h3 class="page-heading">Direct DB Connection</h3>
|
||||||
|
<gf-form-switch class="gf-form" label-class="width-9"
|
||||||
|
label="Enable"
|
||||||
|
checked="ctrl.current.jsonData.dbConnection.enable">
|
||||||
|
</gf-form-switch>
|
||||||
|
<div ng-if="ctrl.current.jsonData.dbConnection.enable">
|
||||||
|
<div class="gf-form max-width-20">
|
||||||
|
<span class="gf-form-label width-9">SQL Data Source</span>
|
||||||
|
<div class="gf-form-select-wrapper max-width-16">
|
||||||
|
<select class="gf-form-input" ng-model="ctrl.current.jsonData.dbConnection.datasourceId"
|
||||||
|
ng-options="ds.id as ds.name for ds in ctrl.sqlDataSources">
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="gf-form-group">
|
<div class="gf-form-group">
|
||||||
<h3 class="page-heading">Alerting</h3>
|
<h3 class="page-heading">Alerting</h3>
|
||||||
<gf-form-switch class="gf-form" label-class="width-9"
|
<gf-form-switch class="gf-form" label-class="width-9"
|
||||||
|
|||||||
50
dist/test/datasource-zabbix/config.controller.js
vendored
Normal file
50
dist/test/datasource-zabbix/config.controller.js
vendored
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.ZabbixDSConfigController = undefined;
|
||||||
|
|
||||||
|
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
||||||
|
|
||||||
|
var _lodash = require('lodash');
|
||||||
|
|
||||||
|
var _lodash2 = _interopRequireDefault(_lodash);
|
||||||
|
|
||||||
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||||
|
|
||||||
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||||
|
|
||||||
|
var SUPPORTED_SQL_DS = ['mysql'];
|
||||||
|
|
||||||
|
var defaultConfig = {
|
||||||
|
dbConnection: {
|
||||||
|
enable: false
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var ZabbixDSConfigController = exports.ZabbixDSConfigController = function () {
|
||||||
|
/** @ngInject */
|
||||||
|
function ZabbixDSConfigController($scope, $injector, datasourceSrv) {
|
||||||
|
_classCallCheck(this, ZabbixDSConfigController);
|
||||||
|
|
||||||
|
this.datasourceSrv = datasourceSrv;
|
||||||
|
|
||||||
|
_lodash2.default.defaults(this.current.jsonData, defaultConfig);
|
||||||
|
this.sqlDataSources = this.getSupportedSQLDataSources();
|
||||||
|
}
|
||||||
|
|
||||||
|
_createClass(ZabbixDSConfigController, [{
|
||||||
|
key: 'getSupportedSQLDataSources',
|
||||||
|
value: function getSupportedSQLDataSources() {
|
||||||
|
var datasources = this.datasourceSrv.getAll();
|
||||||
|
return _lodash2.default.filter(datasources, function (ds) {
|
||||||
|
return _lodash2.default.includes(SUPPORTED_SQL_DS, ds.type);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}]);
|
||||||
|
|
||||||
|
return ZabbixDSConfigController;
|
||||||
|
}();
|
||||||
|
|
||||||
|
ZabbixDSConfigController.templateUrl = 'datasource-zabbix/partials/config.html';
|
||||||
117
dist/test/datasource-zabbix/datasource.js
vendored
117
dist/test/datasource-zabbix/datasource.js
vendored
@@ -56,12 +56,15 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
|||||||
var ZabbixAPIDatasource = function () {
|
var ZabbixAPIDatasource = function () {
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
function ZabbixAPIDatasource(instanceSettings, templateSrv, alertSrv, dashboardSrv, zabbixAlertingSrv, Zabbix) {
|
function ZabbixAPIDatasource(instanceSettings, templateSrv, alertSrv, dashboardSrv, datasourceSrv, zabbixAlertingSrv, Zabbix) {
|
||||||
|
var _this = this;
|
||||||
|
|
||||||
_classCallCheck(this, ZabbixAPIDatasource);
|
_classCallCheck(this, ZabbixAPIDatasource);
|
||||||
|
|
||||||
this.templateSrv = templateSrv;
|
this.templateSrv = templateSrv;
|
||||||
this.alertSrv = alertSrv;
|
this.alertSrv = alertSrv;
|
||||||
this.dashboardSrv = dashboardSrv;
|
this.dashboardSrv = dashboardSrv;
|
||||||
|
this.datasourceSrv = datasourceSrv;
|
||||||
this.zabbixAlertingSrv = zabbixAlertingSrv;
|
this.zabbixAlertingSrv = zabbixAlertingSrv;
|
||||||
|
|
||||||
// General data source settings
|
// General data source settings
|
||||||
@@ -90,35 +93,59 @@ var ZabbixAPIDatasource = function () {
|
|||||||
|
|
||||||
this.zabbix = new Zabbix(this.url, this.username, this.password, this.basicAuth, this.withCredentials, this.cacheTTL);
|
this.zabbix = new Zabbix(this.url, this.username, this.password, this.basicAuth, this.withCredentials, this.cacheTTL);
|
||||||
|
|
||||||
|
// Try to use direct DB connection
|
||||||
|
this.enableDirectDBConnection = instanceSettings.jsonData.dbConnection.enable;
|
||||||
|
if (this.enableDirectDBConnection) {
|
||||||
|
this.loadSQLDataSource(instanceSettings.jsonData.dbConnection.datasourceId).then(function () {}).catch(function (error) {
|
||||||
|
_this.enableDirectDBConnection = false;
|
||||||
|
_this.alertSrv.set("SQL Data Source Error", error, 'error');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Use custom format for template variables
|
// Use custom format for template variables
|
||||||
this.replaceTemplateVars = _lodash2.default.partial(replaceTemplateVars, this.templateSrv);
|
this.replaceTemplateVars = _lodash2.default.partial(replaceTemplateVars, this.templateSrv);
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////
|
|
||||||
// Datasource methods //
|
|
||||||
////////////////////////
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Query panel data. Calls for each panel in dashboard.
|
|
||||||
* @param {Object} options Contains time range, targets and other info.
|
|
||||||
* @return {Object} Grafana metrics object with timeseries data for each target.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
_createClass(ZabbixAPIDatasource, [{
|
_createClass(ZabbixAPIDatasource, [{
|
||||||
|
key: 'loadSQLDataSource',
|
||||||
|
value: function loadSQLDataSource(datasourceId) {
|
||||||
|
var _this2 = this;
|
||||||
|
|
||||||
|
var ds = _lodash2.default.find(this.datasourceSrv.getAll(), { 'id': datasourceId });
|
||||||
|
if (ds) {
|
||||||
|
return this.datasourceSrv.loadDatasource(ds.name).then(function (ds) {
|
||||||
|
console.log('Data source loaded', ds);
|
||||||
|
_this2.sqlDataSource = ds;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return Promise.reject('SQL Data Source with ID ' + datasourceId + ' not found');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////
|
||||||
|
// Datasource methods //
|
||||||
|
////////////////////////
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query panel data. Calls for each panel in dashboard.
|
||||||
|
* @param {Object} options Contains time range, targets and other info.
|
||||||
|
* @return {Object} Grafana metrics object with timeseries data for each target.
|
||||||
|
*/
|
||||||
|
|
||||||
|
}, {
|
||||||
key: 'query',
|
key: 'query',
|
||||||
value: function query(options) {
|
value: function query(options) {
|
||||||
var _this = this;
|
var _this3 = this;
|
||||||
|
|
||||||
// Get alerts for current panel
|
// Get alerts for current panel
|
||||||
if (this.alertingEnabled) {
|
if (this.alertingEnabled) {
|
||||||
this.alertQuery(options).then(function (alert) {
|
this.alertQuery(options).then(function (alert) {
|
||||||
_this.zabbixAlertingSrv.setPanelAlertState(options.panelId, alert.state);
|
_this3.zabbixAlertingSrv.setPanelAlertState(options.panelId, alert.state);
|
||||||
|
|
||||||
_this.zabbixAlertingSrv.removeZabbixThreshold(options.panelId);
|
_this3.zabbixAlertingSrv.removeZabbixThreshold(options.panelId);
|
||||||
if (_this.addThresholds) {
|
if (_this3.addThresholds) {
|
||||||
_lodash2.default.forEach(alert.thresholds, function (threshold) {
|
_lodash2.default.forEach(alert.thresholds, function (threshold) {
|
||||||
_this.zabbixAlertingSrv.setPanelThreshold(options.panelId, threshold);
|
_this3.zabbixAlertingSrv.setPanelThreshold(options.panelId, threshold);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -131,7 +158,7 @@ var ZabbixAPIDatasource = function () {
|
|||||||
|
|
||||||
// Prevent changes of original object
|
// Prevent changes of original object
|
||||||
var target = _lodash2.default.cloneDeep(t);
|
var target = _lodash2.default.cloneDeep(t);
|
||||||
_this.replaceTargetVariables(target, options);
|
_this3.replaceTargetVariables(target, options);
|
||||||
|
|
||||||
// Apply Time-related functions (timeShift(), etc)
|
// Apply Time-related functions (timeShift(), etc)
|
||||||
var timeFunctions = bindFunctionDefs(target.functions, 'Time');
|
var timeFunctions = bindFunctionDefs(target.functions, 'Time');
|
||||||
@@ -146,7 +173,7 @@ var ZabbixAPIDatasource = function () {
|
|||||||
}
|
}
|
||||||
var timeRange = [timeFrom, timeTo];
|
var timeRange = [timeFrom, timeTo];
|
||||||
|
|
||||||
var useTrends = _this.isUseTrends(timeRange);
|
var useTrends = _this3.isUseTrends(timeRange);
|
||||||
|
|
||||||
// Metrics or Text query mode
|
// Metrics or Text query mode
|
||||||
if (target.mode !== c.MODE_ITSERVICE) {
|
if (target.mode !== c.MODE_ITSERVICE) {
|
||||||
@@ -159,9 +186,9 @@ var ZabbixAPIDatasource = function () {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!target.mode || target.mode === c.MODE_METRICS) {
|
if (!target.mode || target.mode === c.MODE_METRICS) {
|
||||||
return _this.queryNumericData(target, timeRange, useTrends, options);
|
return _this3.queryNumericData(target, timeRange, useTrends, options);
|
||||||
} else if (target.mode === c.MODE_TEXT) {
|
} else if (target.mode === c.MODE_TEXT) {
|
||||||
return _this.queryTextData(target, timeRange);
|
return _this3.queryTextData(target, timeRange);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,7 +199,7 @@ var ZabbixAPIDatasource = function () {
|
|||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return _this.zabbix.getSLA(target.itservice.serviceid, timeRange).then(function (slaObject) {
|
return _this3.zabbix.getSLA(target.itservice.serviceid, timeRange).then(function (slaObject) {
|
||||||
return _responseHandler2.default.handleSLAResponse(target.itservice, target.slaProperty, slaObject);
|
return _responseHandler2.default.handleSLAResponse(target.itservice, target.slaProperty, slaObject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -186,7 +213,7 @@ var ZabbixAPIDatasource = function () {
|
|||||||
}, {
|
}, {
|
||||||
key: 'queryNumericData',
|
key: 'queryNumericData',
|
||||||
value: function queryNumericData(target, timeRange, useTrends, options) {
|
value: function queryNumericData(target, timeRange, useTrends, options) {
|
||||||
var _this2 = this;
|
var _this4 = this;
|
||||||
|
|
||||||
var _timeRange = _slicedToArray(timeRange, 2),
|
var _timeRange = _slicedToArray(timeRange, 2),
|
||||||
timeFrom = _timeRange[0],
|
timeFrom = _timeRange[0],
|
||||||
@@ -199,8 +226,8 @@ var ZabbixAPIDatasource = function () {
|
|||||||
var getHistoryPromise = void 0;
|
var getHistoryPromise = void 0;
|
||||||
|
|
||||||
if (useTrends) {
|
if (useTrends) {
|
||||||
var valueType = _this2.getTrendValueType(target);
|
var valueType = _this4.getTrendValueType(target);
|
||||||
getHistoryPromise = _this2.zabbix.getTrend(items, timeFrom, timeTo).then(function (history) {
|
getHistoryPromise = _this4.zabbix.getTrend(items, timeFrom, timeTo).then(function (history) {
|
||||||
return _responseHandler2.default.handleTrends(history, items, valueType);
|
return _responseHandler2.default.handleTrends(history, items, valueType);
|
||||||
}).then(function (timeseries) {
|
}).then(function (timeseries) {
|
||||||
// Sort trend data, issue #202
|
// Sort trend data, issue #202
|
||||||
@@ -214,14 +241,14 @@ var ZabbixAPIDatasource = function () {
|
|||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
// Use history
|
// Use history
|
||||||
getHistoryPromise = _this2.zabbix.getHistory(items, timeFrom, timeTo).then(function (history) {
|
getHistoryPromise = _this4.zabbix.getHistory(items, timeFrom, timeTo).then(function (history) {
|
||||||
return _responseHandler2.default.handleHistory(history, items);
|
return _responseHandler2.default.handleHistory(history, items);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return getHistoryPromise;
|
return getHistoryPromise;
|
||||||
}).then(function (timeseries) {
|
}).then(function (timeseries) {
|
||||||
return _this2.applyDataProcessingFunctions(timeseries, target);
|
return _this4.applyDataProcessingFunctions(timeseries, target);
|
||||||
}).then(function (timeseries) {
|
}).then(function (timeseries) {
|
||||||
return downsampleSeries(timeseries, options);
|
return downsampleSeries(timeseries, options);
|
||||||
}).catch(function (error) {
|
}).catch(function (error) {
|
||||||
@@ -300,7 +327,7 @@ var ZabbixAPIDatasource = function () {
|
|||||||
}, {
|
}, {
|
||||||
key: 'queryTextData',
|
key: 'queryTextData',
|
||||||
value: function queryTextData(target, timeRange) {
|
value: function queryTextData(target, timeRange) {
|
||||||
var _this3 = this;
|
var _this5 = this;
|
||||||
|
|
||||||
var _timeRange2 = _slicedToArray(timeRange, 2),
|
var _timeRange2 = _slicedToArray(timeRange, 2),
|
||||||
timeFrom = _timeRange2[0],
|
timeFrom = _timeRange2[0],
|
||||||
@@ -311,7 +338,7 @@ var ZabbixAPIDatasource = function () {
|
|||||||
};
|
};
|
||||||
return this.zabbix.getItemsFromTarget(target, options).then(function (items) {
|
return this.zabbix.getItemsFromTarget(target, options).then(function (items) {
|
||||||
if (items.length) {
|
if (items.length) {
|
||||||
return _this3.zabbix.getHistory(items, timeFrom, timeTo).then(function (history) {
|
return _this5.zabbix.getHistory(items, timeFrom, timeTo).then(function (history) {
|
||||||
return _responseHandler2.default.handleText(history, items, target);
|
return _responseHandler2.default.handleText(history, items, target);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -328,12 +355,12 @@ var ZabbixAPIDatasource = function () {
|
|||||||
}, {
|
}, {
|
||||||
key: 'testDatasource',
|
key: 'testDatasource',
|
||||||
value: function testDatasource() {
|
value: function testDatasource() {
|
||||||
var _this4 = this;
|
var _this6 = this;
|
||||||
|
|
||||||
var zabbixVersion = void 0;
|
var zabbixVersion = void 0;
|
||||||
return this.zabbix.getVersion().then(function (version) {
|
return this.zabbix.getVersion().then(function (version) {
|
||||||
zabbixVersion = version;
|
zabbixVersion = version;
|
||||||
return _this4.zabbix.login();
|
return _this6.zabbix.login();
|
||||||
}).then(function () {
|
}).then(function () {
|
||||||
return {
|
return {
|
||||||
status: "success",
|
status: "success",
|
||||||
@@ -372,14 +399,14 @@ var ZabbixAPIDatasource = function () {
|
|||||||
}, {
|
}, {
|
||||||
key: 'metricFindQuery',
|
key: 'metricFindQuery',
|
||||||
value: function metricFindQuery(query) {
|
value: function metricFindQuery(query) {
|
||||||
var _this5 = this;
|
var _this7 = this;
|
||||||
|
|
||||||
var result = void 0;
|
var result = void 0;
|
||||||
var parts = [];
|
var parts = [];
|
||||||
|
|
||||||
// Split query. Query structure: group.host.app.item
|
// Split query. Query structure: group.host.app.item
|
||||||
_lodash2.default.each(utils.splitTemplateQuery(query), function (part) {
|
_lodash2.default.each(utils.splitTemplateQuery(query), function (part) {
|
||||||
part = _this5.replaceTemplateVars(part, {});
|
part = _this7.replaceTemplateVars(part, {});
|
||||||
|
|
||||||
// Replace wildcard to regex
|
// Replace wildcard to regex
|
||||||
if (part === '*') {
|
if (part === '*') {
|
||||||
@@ -421,7 +448,7 @@ var ZabbixAPIDatasource = function () {
|
|||||||
}, {
|
}, {
|
||||||
key: 'annotationQuery',
|
key: 'annotationQuery',
|
||||||
value: function annotationQuery(options) {
|
value: function annotationQuery(options) {
|
||||||
var _this6 = this;
|
var _this8 = this;
|
||||||
|
|
||||||
var timeFrom = Math.ceil(dateMath.parse(options.rangeRaw.from) / 1000);
|
var timeFrom = Math.ceil(dateMath.parse(options.rangeRaw.from) / 1000);
|
||||||
var timeTo = Math.ceil(dateMath.parse(options.rangeRaw.to) / 1000);
|
var timeTo = Math.ceil(dateMath.parse(options.rangeRaw.to) / 1000);
|
||||||
@@ -439,7 +466,7 @@ var ZabbixAPIDatasource = function () {
|
|||||||
return getTriggers.then(function (triggers) {
|
return getTriggers.then(function (triggers) {
|
||||||
|
|
||||||
// Filter triggers by description
|
// Filter triggers by description
|
||||||
var triggerName = _this6.replaceTemplateVars(annotation.trigger, {});
|
var triggerName = _this8.replaceTemplateVars(annotation.trigger, {});
|
||||||
if (utils.isRegex(triggerName)) {
|
if (utils.isRegex(triggerName)) {
|
||||||
triggers = _lodash2.default.filter(triggers, function (trigger) {
|
triggers = _lodash2.default.filter(triggers, function (trigger) {
|
||||||
return utils.buildRegex(triggerName).test(trigger.description);
|
return utils.buildRegex(triggerName).test(trigger.description);
|
||||||
@@ -456,7 +483,7 @@ var ZabbixAPIDatasource = function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
var objectids = _lodash2.default.map(triggers, 'triggerid');
|
var objectids = _lodash2.default.map(triggers, 'triggerid');
|
||||||
return _this6.zabbix.getEvents(objectids, timeFrom, timeTo, showOkEvents).then(function (events) {
|
return _this8.zabbix.getEvents(objectids, timeFrom, timeTo, showOkEvents).then(function (events) {
|
||||||
var indexedTriggers = _lodash2.default.keyBy(triggers, 'triggerid');
|
var indexedTriggers = _lodash2.default.keyBy(triggers, 'triggerid');
|
||||||
|
|
||||||
// Hide acknowledged events if option enabled
|
// Hide acknowledged events if option enabled
|
||||||
@@ -497,23 +524,23 @@ var ZabbixAPIDatasource = function () {
|
|||||||
}, {
|
}, {
|
||||||
key: 'alertQuery',
|
key: 'alertQuery',
|
||||||
value: function alertQuery(options) {
|
value: function alertQuery(options) {
|
||||||
var _this7 = this;
|
var _this9 = this;
|
||||||
|
|
||||||
var enabled_targets = filterEnabledTargets(options.targets);
|
var enabled_targets = filterEnabledTargets(options.targets);
|
||||||
var getPanelItems = _lodash2.default.map(enabled_targets, function (t) {
|
var getPanelItems = _lodash2.default.map(enabled_targets, function (t) {
|
||||||
var target = _lodash2.default.cloneDeep(t);
|
var target = _lodash2.default.cloneDeep(t);
|
||||||
_this7.replaceTargetVariables(target, options);
|
_this9.replaceTargetVariables(target, options);
|
||||||
return _this7.zabbix.getItemsFromTarget(target, { itemtype: 'num' });
|
return _this9.zabbix.getItemsFromTarget(target, { itemtype: 'num' });
|
||||||
});
|
});
|
||||||
|
|
||||||
return Promise.all(getPanelItems).then(function (results) {
|
return Promise.all(getPanelItems).then(function (results) {
|
||||||
var items = _lodash2.default.flatten(results);
|
var items = _lodash2.default.flatten(results);
|
||||||
var itemids = _lodash2.default.map(items, 'itemid');
|
var itemids = _lodash2.default.map(items, 'itemid');
|
||||||
|
|
||||||
return _this7.zabbix.getAlerts(itemids);
|
return _this9.zabbix.getAlerts(itemids);
|
||||||
}).then(function (triggers) {
|
}).then(function (triggers) {
|
||||||
triggers = _lodash2.default.filter(triggers, function (trigger) {
|
triggers = _lodash2.default.filter(triggers, function (trigger) {
|
||||||
return trigger.priority >= _this7.alertingMinSeverity;
|
return trigger.priority >= _this9.alertingMinSeverity;
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!triggers || triggers.length === 0) {
|
if (!triggers || triggers.length === 0) {
|
||||||
@@ -544,12 +571,12 @@ var ZabbixAPIDatasource = function () {
|
|||||||
}, {
|
}, {
|
||||||
key: 'replaceTargetVariables',
|
key: 'replaceTargetVariables',
|
||||||
value: function replaceTargetVariables(target, options) {
|
value: function replaceTargetVariables(target, options) {
|
||||||
var _this8 = this;
|
var _this10 = this;
|
||||||
|
|
||||||
var parts = ['group', 'host', 'application', 'item'];
|
var parts = ['group', 'host', 'application', 'item'];
|
||||||
_lodash2.default.forEach(parts, function (p) {
|
_lodash2.default.forEach(parts, function (p) {
|
||||||
if (target[p] && target[p].filter) {
|
if (target[p] && target[p].filter) {
|
||||||
target[p].filter = _this8.replaceTemplateVars(target[p].filter, options.scopedVars);
|
target[p].filter = _this10.replaceTemplateVars(target[p].filter, options.scopedVars);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
target.textFilter = this.replaceTemplateVars(target.textFilter, options.scopedVars);
|
target.textFilter = this.replaceTemplateVars(target.textFilter, options.scopedVars);
|
||||||
@@ -557,9 +584,9 @@ var ZabbixAPIDatasource = function () {
|
|||||||
_lodash2.default.forEach(target.functions, function (func) {
|
_lodash2.default.forEach(target.functions, function (func) {
|
||||||
func.params = _lodash2.default.map(func.params, function (param) {
|
func.params = _lodash2.default.map(func.params, function (param) {
|
||||||
if (typeof param === 'number') {
|
if (typeof param === 'number') {
|
||||||
return +_this8.templateSrv.replace(param.toString(), options.scopedVars);
|
return +_this10.templateSrv.replace(param.toString(), options.scopedVars);
|
||||||
} else {
|
} else {
|
||||||
return _this8.templateSrv.replace(param, options.scopedVars);
|
return _this10.templateSrv.replace(param, options.scopedVars);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
10
dist/test/datasource-zabbix/module.js
vendored
10
dist/test/datasource-zabbix/module.js
vendored
@@ -9,14 +9,10 @@ var _datasource = require('./datasource');
|
|||||||
|
|
||||||
var _query = require('./query.controller');
|
var _query = require('./query.controller');
|
||||||
|
|
||||||
|
var _config = require('./config.controller');
|
||||||
|
|
||||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||||
|
|
||||||
var ZabbixConfigController = function ZabbixConfigController() {
|
|
||||||
_classCallCheck(this, ZabbixConfigController);
|
|
||||||
};
|
|
||||||
|
|
||||||
ZabbixConfigController.templateUrl = 'datasource-zabbix/partials/config.html';
|
|
||||||
|
|
||||||
var ZabbixQueryOptionsController = function ZabbixQueryOptionsController() {
|
var ZabbixQueryOptionsController = function ZabbixQueryOptionsController() {
|
||||||
_classCallCheck(this, ZabbixQueryOptionsController);
|
_classCallCheck(this, ZabbixQueryOptionsController);
|
||||||
};
|
};
|
||||||
@@ -30,7 +26,7 @@ var ZabbixAnnotationsQueryController = function ZabbixAnnotationsQueryController
|
|||||||
ZabbixAnnotationsQueryController.templateUrl = 'datasource-zabbix/partials/annotations.editor.html';
|
ZabbixAnnotationsQueryController.templateUrl = 'datasource-zabbix/partials/annotations.editor.html';
|
||||||
|
|
||||||
exports.Datasource = _datasource.ZabbixAPIDatasource;
|
exports.Datasource = _datasource.ZabbixAPIDatasource;
|
||||||
exports.ConfigCtrl = ZabbixConfigController;
|
exports.ConfigCtrl = _config.ZabbixDSConfigController;
|
||||||
exports.QueryCtrl = _query.ZabbixQueryController;
|
exports.QueryCtrl = _query.ZabbixQueryController;
|
||||||
exports.QueryOptionsCtrl = ZabbixQueryOptionsController;
|
exports.QueryOptionsCtrl = ZabbixQueryOptionsController;
|
||||||
exports.AnnotationsQueryCtrl = ZabbixAnnotationsQueryController;
|
exports.AnnotationsQueryCtrl = ZabbixAnnotationsQueryController;
|
||||||
|
|||||||
28
src/datasource-zabbix/config.controller.js
Normal file
28
src/datasource-zabbix/config.controller.js
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
import _ from 'lodash';
|
||||||
|
|
||||||
|
const SUPPORTED_SQL_DS = ['mysql'];
|
||||||
|
|
||||||
|
const defaultConfig = {
|
||||||
|
dbConnection: {
|
||||||
|
enable: false,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export class ZabbixDSConfigController {
|
||||||
|
/** @ngInject */
|
||||||
|
constructor($scope, $injector, datasourceSrv) {
|
||||||
|
this.datasourceSrv = datasourceSrv;
|
||||||
|
|
||||||
|
_.defaults(this.current.jsonData, defaultConfig);
|
||||||
|
this.sqlDataSources = this.getSupportedSQLDataSources();
|
||||||
|
}
|
||||||
|
|
||||||
|
getSupportedSQLDataSources() {
|
||||||
|
let datasources = this.datasourceSrv.getAll();
|
||||||
|
return _.filter(datasources, ds => {
|
||||||
|
return _.includes(SUPPORTED_SQL_DS, ds.type);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ZabbixDSConfigController.templateUrl = 'datasource-zabbix/partials/config.html';
|
||||||
@@ -13,10 +13,11 @@ import {ZabbixAPIError} from './zabbixAPICore.service.js';
|
|||||||
class ZabbixAPIDatasource {
|
class ZabbixAPIDatasource {
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
constructor(instanceSettings, templateSrv, alertSrv, dashboardSrv, zabbixAlertingSrv, Zabbix) {
|
constructor(instanceSettings, templateSrv, alertSrv, dashboardSrv, datasourceSrv, zabbixAlertingSrv, Zabbix) {
|
||||||
this.templateSrv = templateSrv;
|
this.templateSrv = templateSrv;
|
||||||
this.alertSrv = alertSrv;
|
this.alertSrv = alertSrv;
|
||||||
this.dashboardSrv = dashboardSrv;
|
this.dashboardSrv = dashboardSrv;
|
||||||
|
this.datasourceSrv = datasourceSrv;
|
||||||
this.zabbixAlertingSrv = zabbixAlertingSrv;
|
this.zabbixAlertingSrv = zabbixAlertingSrv;
|
||||||
|
|
||||||
// General data source settings
|
// General data source settings
|
||||||
@@ -45,10 +46,33 @@ class ZabbixAPIDatasource {
|
|||||||
|
|
||||||
this.zabbix = new Zabbix(this.url, this.username, this.password, this.basicAuth, this.withCredentials, this.cacheTTL);
|
this.zabbix = new Zabbix(this.url, this.username, this.password, this.basicAuth, this.withCredentials, this.cacheTTL);
|
||||||
|
|
||||||
|
// Try to use direct DB connection
|
||||||
|
this.enableDirectDBConnection = instanceSettings.jsonData.dbConnection.enable;
|
||||||
|
if (this.enableDirectDBConnection) {
|
||||||
|
this.loadSQLDataSource(instanceSettings.jsonData.dbConnection.datasourceId)
|
||||||
|
.then(() => {})
|
||||||
|
.catch(error => {
|
||||||
|
this.enableDirectDBConnection = false;
|
||||||
|
this.alertSrv.set("SQL Data Source Error", error, 'error');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Use custom format for template variables
|
// Use custom format for template variables
|
||||||
this.replaceTemplateVars = _.partial(replaceTemplateVars, this.templateSrv);
|
this.replaceTemplateVars = _.partial(replaceTemplateVars, this.templateSrv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loadSQLDataSource(datasourceId) {
|
||||||
|
let ds = _.find(this.datasourceSrv.getAll(), {'id': datasourceId});
|
||||||
|
if (ds) {
|
||||||
|
return this.datasourceSrv.loadDatasource(ds.name).then(ds => {
|
||||||
|
console.log('Data source loaded', ds);
|
||||||
|
this.sqlDataSource = ds;
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
return Promise.reject(`SQL Data Source with ID ${datasourceId} not found`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////
|
////////////////////////
|
||||||
// Datasource methods //
|
// Datasource methods //
|
||||||
////////////////////////
|
////////////////////////
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import {ZabbixAPIDatasource} from './datasource';
|
import {ZabbixAPIDatasource} from './datasource';
|
||||||
import {ZabbixQueryController} from './query.controller';
|
import {ZabbixQueryController} from './query.controller';
|
||||||
|
import {ZabbixDSConfigController} from './config.controller';
|
||||||
class ZabbixConfigController {}
|
|
||||||
ZabbixConfigController.templateUrl = 'datasource-zabbix/partials/config.html';
|
|
||||||
|
|
||||||
class ZabbixQueryOptionsController {}
|
class ZabbixQueryOptionsController {}
|
||||||
ZabbixQueryOptionsController.templateUrl = 'datasource-zabbix/partials/query.options.html';
|
ZabbixQueryOptionsController.templateUrl = 'datasource-zabbix/partials/query.options.html';
|
||||||
@@ -12,7 +10,7 @@ ZabbixAnnotationsQueryController.templateUrl = 'datasource-zabbix/partials/annot
|
|||||||
|
|
||||||
export {
|
export {
|
||||||
ZabbixAPIDatasource as Datasource,
|
ZabbixAPIDatasource as Datasource,
|
||||||
ZabbixConfigController as ConfigCtrl,
|
ZabbixDSConfigController as ConfigCtrl,
|
||||||
ZabbixQueryController as QueryCtrl,
|
ZabbixQueryController as QueryCtrl,
|
||||||
ZabbixQueryOptionsController as QueryOptionsCtrl,
|
ZabbixQueryOptionsController as QueryOptionsCtrl,
|
||||||
ZabbixAnnotationsQueryController as AnnotationsQueryCtrl
|
ZabbixAnnotationsQueryController as AnnotationsQueryCtrl
|
||||||
|
|||||||
@@ -75,6 +75,24 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="gf-form-group">
|
||||||
|
<h3 class="page-heading">Direct DB Connection</h3>
|
||||||
|
<gf-form-switch class="gf-form" label-class="width-9"
|
||||||
|
label="Enable"
|
||||||
|
checked="ctrl.current.jsonData.dbConnection.enable">
|
||||||
|
</gf-form-switch>
|
||||||
|
<div ng-if="ctrl.current.jsonData.dbConnection.enable">
|
||||||
|
<div class="gf-form max-width-20">
|
||||||
|
<span class="gf-form-label width-9">SQL Data Source</span>
|
||||||
|
<div class="gf-form-select-wrapper max-width-16">
|
||||||
|
<select class="gf-form-input" ng-model="ctrl.current.jsonData.dbConnection.datasourceId"
|
||||||
|
ng-options="ds.id as ds.name for ds in ctrl.sqlDataSources">
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="gf-form-group">
|
<div class="gf-form-group">
|
||||||
<h3 class="page-heading">Alerting</h3>
|
<h3 class="page-heading">Alerting</h3>
|
||||||
<gf-form-switch class="gf-form" label-class="width-9"
|
<gf-form-switch class="gf-form" label-class="width-9"
|
||||||
|
|||||||
Reference in New Issue
Block a user