Merge branch 'master' into metric-functions
This commit is contained in:
34
CHANGELOG.md
34
CHANGELOG.md
@@ -1,15 +1,33 @@
|
||||
# Change Log
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## [Unreleased]
|
||||
### Added
|
||||
- `consolidateBy` function, which allows to specify aggregation function for time series data.
|
||||
- Direct DB Connection, which allows to use existing SQL data source for querying history data directly from Zabbix database.
|
||||
- **Docs**: Direct DB Connection reference and configuration.
|
||||
|
||||
### Changed
|
||||
- IT Services query editor. Now user able to select multiple services by using regex, [#415](https://github.com/alexanderzobnin/grafana-zabbix/issues/415)
|
||||
|
||||
### Fixed
|
||||
- Item name expanding when key contains commas in quoted params, like my_key["a=1,b=2",c,d]
|
||||
- Incorrect points order when trends are used [#202](https://github.com/alexanderzobnin/grafana-zabbix/issues/202)
|
||||
- Triggers panel styles for light theme
|
||||
- Bug with text metrics when singlestat or table shows NaN, [#325](https://github.com/alexanderzobnin/grafana-zabbix/issues/325)
|
||||
- Template variables support in annotations and triggers panel (trigger name field), [#428](https://github.com/alexanderzobnin/grafana-zabbix/issues/428)
|
||||
- Parsing of template variable query with braces, [#432](https://github.com/alexanderzobnin/grafana-zabbix/issues/432)
|
||||
|
||||
|
||||
## [3.5.1] - 2017-07-10
|
||||
### Fixed
|
||||
- Bug with alerting when template queries are used, [#424](https://github.com/alexanderzobnin/grafana-zabbix/issues/424)
|
||||
|
||||
|
||||
## [3.5.0] - 2017-07-05
|
||||
### Added
|
||||
- rate() function, which calculates per-second rate for growing counters.
|
||||
- Benchmarks for time series functions. Used [Benchmark.js](https://github.com/bestiejs/benchmark.js) library.
|
||||
|
||||
### Changed
|
||||
- Template query format. New format is `{group}{host}{app}{item}`. It allows to use names with dot. Updated
|
||||
@@ -19,9 +37,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
- Improved performance of groupBy() functions (at 6-10x faster than old).
|
||||
- Fill empty intervals by _null_ when aggregations are used, [#388](https://github.com/alexanderzobnin/grafana-zabbix/issues/388)
|
||||
|
||||
### Added
|
||||
- rate() function, which calculates per-second rate for growing counters.
|
||||
- Benchmarks for time series functions. Used [Benchmark.js](https://github.com/bestiejs/benchmark.js) library.
|
||||
### Fixed
|
||||
- Item name expanding when key contains commas in quoted params, like my_key["a=1,b=2",c,d]
|
||||
- Incorrect points order when trends are used [#202](https://github.com/alexanderzobnin/grafana-zabbix/issues/202)
|
||||
- Triggers panel styles for light theme
|
||||
- Bug with text metrics when singlestat or table shows NaN, [#325](https://github.com/alexanderzobnin/grafana-zabbix/issues/325)
|
||||
|
||||
|
||||
## [3.4.0] - 2017-05-17
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# Zabbix plugin for Grafana
|
||||
|
||||
[](https://github.com/alexanderzobnin/grafana-zabbix/releases)
|
||||
[](https://github.com/alexanderzobnin/grafana-zabbix/blob/master/CHANGELOG.md)
|
||||
[](http://docs.grafana-zabbix.org)
|
||||
[](https://twitter.com/alexanderzobnin)
|
||||
[](https://paypal.me/alexanderzobnin/10)
|
||||
|
||||
32
dist/README.md
vendored
32
dist/README.md
vendored
@@ -1,28 +1,22 @@
|
||||
## Zabbix plugin for Grafana
|
||||
# Zabbix plugin for Grafana
|
||||
|
||||
[](https://github.com/alexanderzobnin/grafana-zabbix/releases)
|
||||
[](https://github.com/alexanderzobnin/grafana-zabbix/blob/master/CHANGELOG.md)
|
||||
[](http://docs.grafana-zabbix.org)
|
||||
[](https://github.com/alexanderzobnin/grafana-zabbix/blob/master/LICENSE)
|
||||
|
||||
Zabbix plugin allows to show different type of data from [Zabbix](http://www.zabbix.com/)
|
||||
monitoring system.
|
||||
Visualize your Zabbix metrics with the leading open source software for time series analytics.
|
||||
|
||||
### Live Demo
|
||||
|
||||
Check out the [live demo](http://play.grafana-zabbix.org/) with dashboard examples.
|
||||
See all features overview and dashboards examples at Grafana-Zabbix [Live demo](http://play.grafana-zabbix.org) site.
|
||||
|
||||
### Features
|
||||
|
||||
#### Flexible metric editor
|
||||
* Regex-based metric filtering
|
||||
* Client-side data processing functions
|
||||
* Template variables support
|
||||
|
||||
#### Templated dashboards support
|
||||
Group, host, application or item names can be replaced with a template variable. This allows you to create generic dashboards that can quickly be changed to show stats for a specific cluster, server or application.
|
||||
|
||||
#### Annotations support
|
||||
* Display zabbix events on graphs
|
||||
* Show acknowledges for problems
|
||||
|
||||
#### Triggers panel
|
||||
Panel for showing Zabbix triggers (like Last 20 issues) with some customizable features.
|
||||
- Select multiple metrics [by using Regex](http://docs.grafana-zabbix.org/guides/gettingstarted/#multiple-items-on-one-graph)
|
||||
- Create interactive and reusable dashboards with [template variables](http://docs.grafana-zabbix.org/guides/templating/)
|
||||
- Show events on graphs with [Annotations](http://docs.grafana.org/reference/annotations/)
|
||||
- Display active problems with Triggers panel
|
||||
- Transform and shape your data with [metric processing functions](http://docs.grafana-zabbix.org/reference/functions/) (Avg, Median, Min, Max, Multiply, Summarize, Time shift, Alias)
|
||||
- Find problems faster with [Alerting](http://docs.grafana-zabbix.org/reference/alerting/) feature
|
||||
- Mix metrics from multiple data sources in the same dashboard or even graph
|
||||
- Discover and share [dashboards](https://grafana.com/dashboards) in the official library
|
||||
|
||||
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"]}
|
||||
10
dist/datasource-zabbix/constants.js
vendored
10
dist/datasource-zabbix/constants.js
vendored
@@ -3,7 +3,7 @@
|
||||
System.register([], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var MODE_METRICS, MODE_TEXT, MODE_ITSERVICE, SEV_NOT_CLASSIFIED, SEV_INFORMATION, SEV_WARNING, SEV_AVERAGE, SEV_HIGH, SEV_DISASTER, SHOW_ALL_TRIGGERS, SHOW_ALL_EVENTS, SHOW_OK_EVENTS, DATAPOINT_VALUE, DATAPOINT_TS;
|
||||
var MODE_METRICS, MODE_ITSERVICE, MODE_TEXT, MODE_ITEMID, SEV_NOT_CLASSIFIED, SEV_INFORMATION, SEV_WARNING, SEV_AVERAGE, SEV_HIGH, SEV_DISASTER, SHOW_ALL_TRIGGERS, SHOW_ALL_EVENTS, SHOW_OK_EVENTS, DATAPOINT_VALUE, DATAPOINT_TS;
|
||||
return {
|
||||
setters: [],
|
||||
execute: function () {
|
||||
@@ -11,13 +11,17 @@ System.register([], function (_export, _context) {
|
||||
|
||||
_export("MODE_METRICS", MODE_METRICS);
|
||||
|
||||
_export("MODE_ITSERVICE", MODE_ITSERVICE = 1);
|
||||
|
||||
_export("MODE_ITSERVICE", MODE_ITSERVICE);
|
||||
|
||||
_export("MODE_TEXT", MODE_TEXT = 2);
|
||||
|
||||
_export("MODE_TEXT", MODE_TEXT);
|
||||
|
||||
_export("MODE_ITSERVICE", MODE_ITSERVICE = 1);
|
||||
_export("MODE_ITEMID", MODE_ITEMID = 3);
|
||||
|
||||
_export("MODE_ITSERVICE", MODE_ITSERVICE);
|
||||
_export("MODE_ITEMID", MODE_ITEMID);
|
||||
|
||||
_export("SEV_NOT_CLASSIFIED", SEV_NOT_CLASSIFIED = 0);
|
||||
|
||||
|
||||
2
dist/datasource-zabbix/constants.js.map
vendored
2
dist/datasource-zabbix/constants.js.map
vendored
@@ -1 +1 @@
|
||||
{"version":3,"sources":["../../src/datasource-zabbix/constants.js"],"names":["MODE_METRICS","MODE_TEXT","MODE_ITSERVICE","SEV_NOT_CLASSIFIED","SEV_INFORMATION","SEV_WARNING","SEV_AVERAGE","SEV_HIGH","SEV_DISASTER","SHOW_ALL_TRIGGERS","SHOW_ALL_EVENTS","SHOW_OK_EVENTS","DATAPOINT_VALUE","DATAPOINT_TS"],"mappings":";;;;;;;;;8BACaA,Y,GAAe,C;;;;2BACfC,S,GAAY,C;;;;gCACZC,c,GAAiB,C;;;;oCAGjBC,kB,GAAqB,C;;;;iCACrBC,e,GAAkB,C;;;;6BAClBC,W,GAAc,C;;;;6BACdC,W,GAAc,C;;;;0BACdC,Q,GAAW,C;;;;8BACXC,Y,GAAe,C;;;;mCAEfC,iB,GAAoB,CAAC,CAAD,EAAI,CAAJ,C;;;;iCACpBC,e,GAAkB,CAAC,CAAD,EAAI,CAAJ,C;;;;gCAClBC,c,GAAiB,C;;;;iCAGjBC,e,GAAkB,C;;;;8BAClBC,Y,GAAe,C","file":"constants.js","sourcesContent":["// Editor modes\nexport const MODE_METRICS = 0;\nexport const MODE_TEXT = 2;\nexport const MODE_ITSERVICE = 1;\n\n// Triggers severity\nexport const SEV_NOT_CLASSIFIED = 0;\nexport const SEV_INFORMATION = 1;\nexport const SEV_WARNING = 2;\nexport const SEV_AVERAGE = 3;\nexport const SEV_HIGH = 4;\nexport const SEV_DISASTER = 5;\n\nexport const SHOW_ALL_TRIGGERS = [0, 1];\nexport const SHOW_ALL_EVENTS = [0, 1];\nexport const SHOW_OK_EVENTS = 1;\n\n// Data point\nexport const DATAPOINT_VALUE = 0;\nexport const DATAPOINT_TS = 1;\n"]}
|
||||
{"version":3,"sources":["../../src/datasource-zabbix/constants.js"],"names":["MODE_METRICS","MODE_ITSERVICE","MODE_TEXT","MODE_ITEMID","SEV_NOT_CLASSIFIED","SEV_INFORMATION","SEV_WARNING","SEV_AVERAGE","SEV_HIGH","SEV_DISASTER","SHOW_ALL_TRIGGERS","SHOW_ALL_EVENTS","SHOW_OK_EVENTS","DATAPOINT_VALUE","DATAPOINT_TS"],"mappings":";;;;;;;;;8BACaA,Y,GAAe,C;;;;gCACfC,c,GAAiB,C;;;;2BACjBC,S,GAAY,C;;;;6BACZC,W,GAAc,C;;;;oCAGdC,kB,GAAqB,C;;;;iCACrBC,e,GAAkB,C;;;;6BAClBC,W,GAAc,C;;;;6BACdC,W,GAAc,C;;;;0BACdC,Q,GAAW,C;;;;8BACXC,Y,GAAe,C;;;;mCAEfC,iB,GAAoB,CAAC,CAAD,EAAI,CAAJ,C;;;;iCACpBC,e,GAAkB,CAAC,CAAD,EAAI,CAAJ,C;;;;gCAClBC,c,GAAiB,C;;;;iCAGjBC,e,GAAkB,C;;;;8BAClBC,Y,GAAe,C","file":"constants.js","sourcesContent":["// Editor modes\nexport const MODE_METRICS = 0;\nexport const MODE_ITSERVICE = 1;\nexport const MODE_TEXT = 2;\nexport const MODE_ITEMID = 3;\n\n// Triggers severity\nexport const SEV_NOT_CLASSIFIED = 0;\nexport const SEV_INFORMATION = 1;\nexport const SEV_WARNING = 2;\nexport const SEV_AVERAGE = 3;\nexport const SEV_HIGH = 4;\nexport const SEV_DISASTER = 5;\n\nexport const SHOW_ALL_TRIGGERS = [0, 1];\nexport const SHOW_ALL_EVENTS = [0, 1];\nexport const SHOW_OK_EVENTS = 1;\n\n// Data point\nexport const DATAPOINT_VALUE = 0;\nexport const DATAPOINT_TS = 1;\n"]}
|
||||
228
dist/datasource-zabbix/datasource.js
vendored
228
dist/datasource-zabbix/datasource.js
vendored
@@ -23,10 +23,23 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
||||
});
|
||||
}
|
||||
|
||||
function getConsolidateBy(target) {
|
||||
var consolidateBy = 'avg';
|
||||
var funcDef = _.find(target.functions, function (func) {
|
||||
return func.def.name === 'consolidateBy';
|
||||
});
|
||||
if (funcDef && funcDef.params && funcDef.params.length) {
|
||||
consolidateBy = funcDef.params[0];
|
||||
}
|
||||
return consolidateBy;
|
||||
}
|
||||
|
||||
function downsampleSeries(timeseries_data, options) {
|
||||
var defaultAgg = dataProcessor.aggregationFunctions['avg'];
|
||||
var consolidateByFunc = dataProcessor.aggregationFunctions[options.consolidateBy] || defaultAgg;
|
||||
return _.map(timeseries_data, function (timeseries) {
|
||||
if (timeseries.datapoints.length > options.maxDataPoints) {
|
||||
timeseries.datapoints = dataProcessor.groupBy(options.interval, dataProcessor.AVERAGE, timeseries.datapoints);
|
||||
timeseries.datapoints = dataProcessor.groupBy(options.interval, consolidateByFunc, timeseries.datapoints);
|
||||
}
|
||||
return timeseries;
|
||||
});
|
||||
@@ -58,6 +71,13 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
||||
return '(' + escapedValues.join('|') + ')';
|
||||
}
|
||||
|
||||
function zabbixItemIdsTemplateFormat(value) {
|
||||
if (typeof value === 'string') {
|
||||
return value;
|
||||
}
|
||||
return value.join(',');
|
||||
}
|
||||
|
||||
/**
|
||||
* If template variables are used in request, replace it using regex format
|
||||
* and wrap with '/' for proper multi-value work. Example:
|
||||
@@ -191,6 +211,9 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
||||
this.dashboardSrv = dashboardSrv;
|
||||
this.zabbixAlertingSrv = zabbixAlertingSrv;
|
||||
|
||||
// Use custom format for template variables
|
||||
this.replaceTemplateVars = _.partial(replaceTemplateVars, this.templateSrv);
|
||||
|
||||
// General data source settings
|
||||
this.name = instanceSettings.name;
|
||||
this.url = instanceSettings.url;
|
||||
@@ -215,10 +238,21 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
||||
this.addThresholds = instanceSettings.jsonData.addThresholds;
|
||||
this.alertingMinSeverity = instanceSettings.jsonData.alertingMinSeverity || c.SEV_WARNING;
|
||||
|
||||
this.zabbix = new Zabbix(this.url, this.username, this.password, this.basicAuth, this.withCredentials, this.cacheTTL);
|
||||
// Direct DB Connection options
|
||||
this.enableDirectDBConnection = instanceSettings.jsonData.dbConnection.enable;
|
||||
this.sqlDatasourceId = instanceSettings.jsonData.dbConnection.datasourceId;
|
||||
|
||||
// Use custom format for template variables
|
||||
this.replaceTemplateVars = _.partial(replaceTemplateVars, this.templateSrv);
|
||||
var zabbixOptions = {
|
||||
username: this.username,
|
||||
password: this.password,
|
||||
basicAuth: this.basicAuth,
|
||||
withCredentials: this.withCredentials,
|
||||
cacheTTL: this.cacheTTL,
|
||||
enableDirectDBConnection: this.enableDirectDBConnection,
|
||||
sqlDatasourceId: this.sqlDatasourceId
|
||||
};
|
||||
|
||||
this.zabbix = new Zabbix(this.url, zabbixOptions);
|
||||
}
|
||||
|
||||
////////////////////////
|
||||
@@ -253,6 +287,11 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
||||
|
||||
// Create request for each target
|
||||
var promises = _.map(options.targets, function (t) {
|
||||
// Don't request undefined and hidden targets
|
||||
if (t.hide) {
|
||||
return [];
|
||||
}
|
||||
|
||||
var timeFrom = Math.ceil(dateMath.parse(options.range.from) / 1000);
|
||||
var timeTo = Math.ceil(dateMath.parse(options.range.to) / 1000);
|
||||
|
||||
@@ -276,7 +315,7 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
||||
var useTrends = _this.isUseTrends(timeRange);
|
||||
|
||||
// Metrics or Text query mode
|
||||
if (target.mode !== c.MODE_ITSERVICE) {
|
||||
if (target.mode === c.MODE_METRICS || target.mode === c.MODE_TEXT || target.mode === c.MODE_ITEMID) {
|
||||
// Migrate old targets
|
||||
target = migrations.migrate(target);
|
||||
|
||||
@@ -289,20 +328,13 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
||||
return _this.queryNumericData(target, timeRange, useTrends, options);
|
||||
} else if (target.mode === c.MODE_TEXT) {
|
||||
return _this.queryTextData(target, timeRange);
|
||||
} else if (target.mode === c.MODE_ITEMID) {
|
||||
return _this.queryItemIdData(target, timeRange, useTrends, options);
|
||||
}
|
||||
} else if (target.mode === c.MODE_ITSERVICE) {
|
||||
// IT services mode
|
||||
return _this.queryITServiceData(target, timeRange, options);
|
||||
}
|
||||
|
||||
// IT services mode
|
||||
else if (target.mode === c.MODE_ITSERVICE) {
|
||||
// Don't show undefined and hidden targets
|
||||
if (target.hide || !target.itservice || !target.slaProperty) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return _this.zabbix.getSLA(target.itservice.serviceid, timeRange).then(function (slaObject) {
|
||||
return responseHandler.handleSLAResponse(target.itservice, target.slaProperty, slaObject);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Data for panel (all targets)
|
||||
@@ -315,19 +347,33 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
||||
value: function queryNumericData(target, timeRange, useTrends, options) {
|
||||
var _this2 = this;
|
||||
|
||||
var _timeRange = _slicedToArray(timeRange, 2),
|
||||
timeFrom = _timeRange[0],
|
||||
timeTo = _timeRange[1];
|
||||
|
||||
var getItemOptions = {
|
||||
itemtype: 'num'
|
||||
};
|
||||
return this.zabbix.getItemsFromTarget(target, getItemOptions).then(function (items) {
|
||||
var getHistoryPromise = void 0;
|
||||
return _this2.queryNumericDataForItems(items, target, timeRange, useTrends, options);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'queryNumericDataForItems',
|
||||
value: function queryNumericDataForItems(items, target, timeRange, useTrends, options) {
|
||||
var _this3 = this;
|
||||
|
||||
if (useTrends) {
|
||||
var valueType = _this2.getTrendValueType(target);
|
||||
getHistoryPromise = _this2.zabbix.getTrend(items, timeFrom, timeTo).then(function (history) {
|
||||
var _timeRange = _slicedToArray(timeRange, 2),
|
||||
timeFrom = _timeRange[0],
|
||||
timeTo = _timeRange[1];
|
||||
|
||||
var getHistoryPromise = void 0;
|
||||
options.consolidateBy = getConsolidateBy(target);
|
||||
|
||||
if (useTrends) {
|
||||
if (this.enableDirectDBConnection) {
|
||||
getHistoryPromise = this.zabbix.getTrendsDB(items, timeFrom, timeTo, options).then(function (history) {
|
||||
return _this3.zabbix.dbConnector.handleGrafanaTSResponse(history, items);
|
||||
});
|
||||
} else {
|
||||
var valueType = this.getTrendValueType(target);
|
||||
getHistoryPromise = this.zabbix.getTrend(items, timeFrom, timeTo).then(function (history) {
|
||||
return responseHandler.handleTrends(history, items, valueType);
|
||||
}).then(function (timeseries) {
|
||||
// Sort trend data, issue #202
|
||||
@@ -336,19 +382,24 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
||||
return point[c.DATAPOINT_TS];
|
||||
});
|
||||
});
|
||||
|
||||
return timeseries;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// Use history
|
||||
if (this.enableDirectDBConnection) {
|
||||
getHistoryPromise = this.zabbix.getHistoryDB(items, timeFrom, timeTo, options).then(function (history) {
|
||||
return _this3.zabbix.dbConnector.handleGrafanaTSResponse(history, items);
|
||||
});
|
||||
} else {
|
||||
// Use history
|
||||
getHistoryPromise = _this2.zabbix.getHistory(items, timeFrom, timeTo).then(function (history) {
|
||||
getHistoryPromise = this.zabbix.getHistory(items, timeFrom, timeTo).then(function (history) {
|
||||
return responseHandler.handleHistory(history, items);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return getHistoryPromise;
|
||||
}).then(function (timeseries) {
|
||||
return _this2.applyDataProcessingFunctions(timeseries, target);
|
||||
return getHistoryPromise.then(function (timeseries) {
|
||||
return _this3.applyDataProcessingFunctions(timeseries, target);
|
||||
}).then(function (timeseries) {
|
||||
return downsampleSeries(timeseries, options);
|
||||
}).catch(function (error) {
|
||||
@@ -427,7 +478,7 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
||||
}, {
|
||||
key: 'queryTextData',
|
||||
value: function queryTextData(target, timeRange) {
|
||||
var _this3 = this;
|
||||
var _this4 = this;
|
||||
|
||||
var _timeRange2 = _slicedToArray(timeRange, 2),
|
||||
timeFrom = _timeRange2[0],
|
||||
@@ -438,7 +489,7 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
||||
};
|
||||
return this.zabbix.getItemsFromTarget(target, options).then(function (items) {
|
||||
if (items.length) {
|
||||
return _this3.zabbix.getHistory(items, timeFrom, timeTo).then(function (history) {
|
||||
return _this4.zabbix.getHistory(items, timeFrom, timeTo).then(function (history) {
|
||||
return responseHandler.handleText(history, items, target);
|
||||
});
|
||||
} else {
|
||||
@@ -446,15 +497,79 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
||||
}
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'queryItemIdData',
|
||||
value: function queryItemIdData(target, timeRange, useTrends, options) {
|
||||
var _this5 = this;
|
||||
|
||||
var itemids = target.itemids;
|
||||
itemids = this.templateSrv.replace(itemids, options.scopedVars, zabbixItemIdsTemplateFormat);
|
||||
itemids = _.map(itemids.split(','), function (itemid) {
|
||||
return itemid.trim();
|
||||
});
|
||||
|
||||
if (!itemids) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return this.zabbix.getItemsByIDs(itemids).then(function (items) {
|
||||
return _this5.queryNumericDataForItems(items, target, timeRange, useTrends, options);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'queryITServiceData',
|
||||
value: function queryITServiceData(target, timeRange, options) {
|
||||
var _this6 = this;
|
||||
|
||||
// Don't show undefined and hidden targets
|
||||
if (target.hide || !target.itservice && !target.itServiceFilter || !target.slaProperty) {
|
||||
return [];
|
||||
}
|
||||
|
||||
var itServiceIds = [];
|
||||
var itServices = [];
|
||||
var itServiceFilter = void 0;
|
||||
var isOldVersion = target.itservice && !target.itServiceFilter;
|
||||
|
||||
if (isOldVersion) {
|
||||
// Backward compatibility
|
||||
itServiceFilter = '/.*/';
|
||||
} else {
|
||||
itServiceFilter = this.replaceTemplateVars(target.itServiceFilter, options.scopedVars);
|
||||
}
|
||||
|
||||
return this.zabbix.getITServices(itServiceFilter).then(function (itservices) {
|
||||
itServices = itservices;
|
||||
if (isOldVersion) {
|
||||
itServices = _.filter(itServices, { 'serviceid': target.itservice.serviceid });
|
||||
}
|
||||
|
||||
itServiceIds = _.map(itServices, 'serviceid');
|
||||
return itServiceIds;
|
||||
}).then(function (serviceids) {
|
||||
return _this6.zabbix.getSLA(serviceids, timeRange);
|
||||
}).then(function (slaResponse) {
|
||||
return _.map(itServiceIds, function (serviceid) {
|
||||
var itservice = _.find(itServices, { 'serviceid': serviceid });
|
||||
return responseHandler.handleSLAResponse(itservice, target.slaProperty, slaResponse);
|
||||
});
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'testDatasource',
|
||||
value: function testDatasource() {
|
||||
var _this4 = this;
|
||||
var _this7 = this;
|
||||
|
||||
var zabbixVersion = void 0;
|
||||
return this.zabbix.getVersion().then(function (version) {
|
||||
zabbixVersion = version;
|
||||
return _this4.zabbix.login();
|
||||
return _this7.zabbix.login();
|
||||
}).then(function () {
|
||||
if (_this7.enableDirectDBConnection) {
|
||||
return _this7.zabbix.dbConnector.testSQLDataSource();
|
||||
} else {
|
||||
return Promise.resolve();
|
||||
}
|
||||
}).then(function () {
|
||||
return {
|
||||
status: "success",
|
||||
@@ -468,6 +583,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",
|
||||
@@ -480,14 +601,14 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
||||
}, {
|
||||
key: 'metricFindQuery',
|
||||
value: function metricFindQuery(query) {
|
||||
var _this5 = this;
|
||||
var _this8 = this;
|
||||
|
||||
var result = void 0;
|
||||
var parts = [];
|
||||
|
||||
// Split query. Query structure: group.host.app.item
|
||||
_.each(utils.splitTemplateQuery(query), function (part) {
|
||||
part = _this5.replaceTemplateVars(part, {});
|
||||
part = _this8.replaceTemplateVars(part, {});
|
||||
|
||||
// Replace wildcard to regex
|
||||
if (part === '*') {
|
||||
@@ -524,7 +645,7 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
||||
}, {
|
||||
key: 'annotationQuery',
|
||||
value: function annotationQuery(options) {
|
||||
var _this6 = this;
|
||||
var _this9 = this;
|
||||
|
||||
var timeFrom = Math.ceil(dateMath.parse(options.rangeRaw.from) / 1000);
|
||||
var timeTo = Math.ceil(dateMath.parse(options.rangeRaw.to) / 1000);
|
||||
@@ -542,13 +663,14 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
||||
return getTriggers.then(function (triggers) {
|
||||
|
||||
// Filter triggers by description
|
||||
if (utils.isRegex(annotation.trigger)) {
|
||||
var triggerName = _this9.replaceTemplateVars(annotation.trigger, {});
|
||||
if (utils.isRegex(triggerName)) {
|
||||
triggers = _.filter(triggers, function (trigger) {
|
||||
return utils.buildRegex(annotation.trigger).test(trigger.description);
|
||||
return utils.buildRegex(triggerName).test(trigger.description);
|
||||
});
|
||||
} else if (annotation.trigger) {
|
||||
} else if (triggerName) {
|
||||
triggers = _.filter(triggers, function (trigger) {
|
||||
return trigger.description === annotation.trigger;
|
||||
return trigger.description === triggerName;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -558,7 +680,7 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
||||
});
|
||||
|
||||
var objectids = _.map(triggers, 'triggerid');
|
||||
return _this6.zabbix.getEvents(objectids, timeFrom, timeTo, showOkEvents).then(function (events) {
|
||||
return _this9.zabbix.getEvents(objectids, timeFrom, timeTo, showOkEvents).then(function (events) {
|
||||
var indexedTriggers = _.keyBy(triggers, 'triggerid');
|
||||
|
||||
// Hide acknowledged events if option enabled
|
||||
@@ -592,21 +714,23 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
||||
}, {
|
||||
key: 'alertQuery',
|
||||
value: function alertQuery(options) {
|
||||
var _this7 = this;
|
||||
var _this10 = this;
|
||||
|
||||
var enabled_targets = filterEnabledTargets(options.targets);
|
||||
var getPanelItems = _.map(enabled_targets, function (target) {
|
||||
return _this7.zabbix.getItemsFromTarget(target, { itemtype: 'num' });
|
||||
var getPanelItems = _.map(enabled_targets, function (t) {
|
||||
var target = _.cloneDeep(t);
|
||||
_this10.replaceTargetVariables(target, options);
|
||||
return _this10.zabbix.getItemsFromTarget(target, { itemtype: 'num' });
|
||||
});
|
||||
|
||||
return Promise.all(getPanelItems).then(function (results) {
|
||||
var items = _.flatten(results);
|
||||
var itemids = _.map(items, 'itemid');
|
||||
|
||||
return _this7.zabbix.getAlerts(itemids);
|
||||
return _this10.zabbix.getAlerts(itemids);
|
||||
}).then(function (triggers) {
|
||||
triggers = _.filter(triggers, function (trigger) {
|
||||
return trigger.priority >= _this7.alertingMinSeverity;
|
||||
return trigger.priority >= _this10.alertingMinSeverity;
|
||||
});
|
||||
|
||||
if (!triggers || triggers.length === 0) {
|
||||
@@ -634,12 +758,12 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
||||
}, {
|
||||
key: 'replaceTargetVariables',
|
||||
value: function replaceTargetVariables(target, options) {
|
||||
var _this8 = this;
|
||||
var _this11 = this;
|
||||
|
||||
var parts = ['group', 'host', 'application', 'item'];
|
||||
_.forEach(parts, function (p) {
|
||||
if (target[p] && target[p].filter) {
|
||||
target[p].filter = _this8.replaceTemplateVars(target[p].filter, options.scopedVars);
|
||||
target[p].filter = _this11.replaceTemplateVars(target[p].filter, options.scopedVars);
|
||||
}
|
||||
});
|
||||
target.textFilter = this.replaceTemplateVars(target.textFilter, options.scopedVars);
|
||||
@@ -647,9 +771,9 @@ System.register(['lodash', 'app/core/utils/datemath', './utils', './migrations',
|
||||
_.forEach(target.functions, function (func) {
|
||||
func.params = _.map(func.params, function (param) {
|
||||
if (typeof param === 'number') {
|
||||
return +_this8.templateSrv.replace(param.toString(), options.scopedVars);
|
||||
return +_this11.templateSrv.replace(param.toString(), options.scopedVars);
|
||||
} else {
|
||||
return _this8.templateSrv.replace(param, options.scopedVars);
|
||||
return _this11.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';
|
||||
|
||||
System.register(['./datasource', './query.controller'], function (_export, _context) {
|
||||
System.register(['./datasource', './query.controller', './config.controller'], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var ZabbixAPIDatasource, ZabbixQueryController, ZabbixConfigController, ZabbixQueryOptionsController, ZabbixAnnotationsQueryController;
|
||||
var ZabbixAPIDatasource, ZabbixQueryController, ZabbixDSConfigController, ZabbixQueryOptionsController, ZabbixAnnotationsQueryController;
|
||||
|
||||
function _classCallCheck(instance, Constructor) {
|
||||
if (!(instance instanceof Constructor)) {
|
||||
@@ -16,14 +16,10 @@ System.register(['./datasource', './query.controller'], function (_export, _cont
|
||||
ZabbixAPIDatasource = _datasource.ZabbixAPIDatasource;
|
||||
}, function (_queryController) {
|
||||
ZabbixQueryController = _queryController.ZabbixQueryController;
|
||||
}, function (_configController) {
|
||||
ZabbixDSConfigController = _configController.ZabbixDSConfigController;
|
||||
}],
|
||||
execute: function () {
|
||||
_export('ConfigCtrl', ZabbixConfigController = function ZabbixConfigController() {
|
||||
_classCallCheck(this, ZabbixConfigController);
|
||||
});
|
||||
|
||||
ZabbixConfigController.templateUrl = 'datasource-zabbix/partials/config.html';
|
||||
|
||||
_export('QueryOptionsCtrl', ZabbixQueryOptionsController = function ZabbixQueryOptionsController() {
|
||||
_classCallCheck(this, ZabbixQueryOptionsController);
|
||||
});
|
||||
@@ -38,7 +34,7 @@ System.register(['./datasource', './query.controller'], function (_export, _cont
|
||||
|
||||
_export('Datasource', ZabbixAPIDatasource);
|
||||
|
||||
_export('ConfigCtrl', ZabbixConfigController);
|
||||
_export('ConfigCtrl', ZabbixDSConfigController);
|
||||
|
||||
_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"]}
|
||||
59
dist/datasource-zabbix/partials/config.html
vendored
59
dist/datasource-zabbix/partials/config.html
vendored
@@ -76,24 +76,53 @@
|
||||
</div>
|
||||
|
||||
<div class="gf-form-group">
|
||||
<h3 class="page-heading">Alerting</h3>
|
||||
<gf-form-switch class="gf-form" label-class="width-9"
|
||||
label="Enable alerting"
|
||||
checked="ctrl.current.jsonData.alerting">
|
||||
<h3 class="page-heading">Direct DB Connection</h3>
|
||||
<gf-form-switch class="gf-form" label-class="width-12"
|
||||
label="Enable"
|
||||
checked="ctrl.current.jsonData.dbConnection.enable">
|
||||
</gf-form-switch>
|
||||
<gf-form-switch class="gf-form" label-class="width-9"
|
||||
label="Add thresholds"
|
||||
checked="ctrl.current.jsonData.addThresholds">
|
||||
</gf-form-switch>
|
||||
<div class="gf-form max-width-20">
|
||||
<span class="gf-form-label width-9">Min severity</span>
|
||||
<div ng-if="ctrl.current.jsonData.dbConnection.enable">
|
||||
<div class="gf-form max-width-20">
|
||||
<span class="gf-form-label width-12">
|
||||
SQL Data Source
|
||||
<info-popover mode="right-normal">
|
||||
Select SQL Data Source for Zabbix database.
|
||||
In order to use this feature you should <a href="/datasources/new" target="_blank">create</a> and
|
||||
configure it first. Zabbix plugin uses this data source for querying history data directly from database.
|
||||
This way usually faster than pulling data from Zabbix API, especially on the wide time ranges, and reduces
|
||||
amount of data transfered.
|
||||
</info-popover>
|
||||
</span>
|
||||
<div class="gf-form-select-wrapper max-width-16">
|
||||
<select class="gf-form-input" ng-model="ctrl.current.jsonData.alertingMinSeverity"
|
||||
ng-options="s.val as s.text for s in [
|
||||
{val: 0, text: 'Not classified'}, {val: 1, text:'Information'},
|
||||
{val: 2, text: 'Warning'}, {val: 3, text: 'Average'},
|
||||
{val: 4, text: 'High'}, {val: 5, text: 'Disaster'}]">
|
||||
<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">
|
||||
<h3 class="page-heading">Alerting</h3>
|
||||
<gf-form-switch class="gf-form" label-class="width-12"
|
||||
label="Enable alerting"
|
||||
checked="ctrl.current.jsonData.alerting">
|
||||
</gf-form-switch>
|
||||
<div ng-if="ctrl.current.jsonData.alerting">
|
||||
<gf-form-switch class="gf-form" label-class="width-12"
|
||||
label="Add thresholds"
|
||||
checked="ctrl.current.jsonData.addThresholds">
|
||||
</gf-form-switch>
|
||||
<div class="gf-form max-width-20">
|
||||
<span class="gf-form-label width-12">Min severity</span>
|
||||
<div class="gf-form-select-wrapper max-width-16">
|
||||
<select class="gf-form-input" ng-model="ctrl.current.jsonData.alertingMinSeverity"
|
||||
ng-options="s.val as s.text for s in [
|
||||
{val: 0, text: 'Not classified'}, {val: 1, text:'Information'},
|
||||
{val: 2, text: 'Warning'}, {val: 3, text: 'Average'},
|
||||
{val: 4, text: 'High'}, {val: 5, text: 'Disaster'}]">
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<select class="gf-form-input"
|
||||
ng-change="ctrl.switchEditorMode(ctrl.target.mode)"
|
||||
ng-model="ctrl.target.mode"
|
||||
ng-options="v.mode as v.text for (k, v) in ctrl.editorModes">
|
||||
ng-options="m.mode as m.text for m in ctrl.editorModes">
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
@@ -17,27 +17,29 @@
|
||||
</div>
|
||||
|
||||
<!-- IT Service editor -->
|
||||
<div class="gf-form-inline" ng-show="ctrl.target.mode == 1">
|
||||
<div class="gf-form-inline" ng-show="ctrl.target.mode == editorMode.ITSERVICE">
|
||||
<div class="gf-form max-width-20">
|
||||
<label class="gf-form-label query-keyword width-7">IT Service</label>
|
||||
<div class="gf-form-select-wrapper max-width-20">
|
||||
<select class="gf-form-input"
|
||||
ng-change="ctrl.selectITService()"
|
||||
ng-model="ctrl.target.itservice"
|
||||
bs-tooltip="ctrl.target.itservice.name.length > 25 ? ctrl.target.itservice.name : ''"
|
||||
ng-options="itservice.name for itservice in ctrl.itserviceList track by itservice.name">
|
||||
<option value="">-- Select IT service --</option>
|
||||
</select>
|
||||
</div>
|
||||
<input type="text"
|
||||
ng-model="ctrl.target.itServiceFilter"
|
||||
bs-typeahead="ctrl.getITServices"
|
||||
ng-blur="ctrl.onTargetBlur()"
|
||||
data-min-length=0
|
||||
data-items=100
|
||||
class="gf-form-input"
|
||||
ng-class="{
|
||||
'zbx-variable': ctrl.isVariable(ctrl.target.itServiceFilter),
|
||||
'zbx-regex': ctrl.isRegex(ctrl.target.itServiceFilter)
|
||||
}">
|
||||
</input>
|
||||
</div>
|
||||
<div class="gf-form">
|
||||
<label class="gf-form-label query-keyword">IT service property</label>
|
||||
<label class="gf-form-label query-keyword">Property</label>
|
||||
<div class="gf-form-select-wrapper">
|
||||
<select class="gf-form-input"
|
||||
ng-change="ctrl.selectITService()"
|
||||
ng-model="ctrl.target.slaProperty"
|
||||
ng-options="slaProperty.name for slaProperty in ctrl.slaPropertyList track by slaProperty.name">
|
||||
<option value="">-- Property --</option>
|
||||
ng-change="ctrl.onTargetBlur()"
|
||||
ng-model="ctrl.target.slaProperty"
|
||||
ng-options="slaProperty.name for slaProperty in ctrl.slaPropertyList track by slaProperty.name">
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
@@ -46,7 +48,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="gf-form-inline" ng-hide="ctrl.target.mode == 1">
|
||||
<div class="gf-form-inline" ng-show="ctrl.target.mode == editorMode.METRICS || ctrl.target.mode == editorMode.TEXT">
|
||||
<!-- Select Group -->
|
||||
<div class="gf-form max-width-20">
|
||||
<label class="gf-form-label query-keyword width-7">Group</label>
|
||||
@@ -83,7 +85,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="gf-form-inline" ng-hide="ctrl.target.mode == 1">
|
||||
<div class="gf-form-inline" ng-show="ctrl.target.mode == editorMode.METRICS || ctrl.target.mode == editorMode.TEXT">
|
||||
<!-- Select Application -->
|
||||
<div class="gf-form max-width-20">
|
||||
<label class="gf-form-label query-keyword width-7">Application</label>
|
||||
@@ -129,7 +131,7 @@
|
||||
<!-- Query options -->
|
||||
<div class="gf-form-group" ng-if="ctrl.showQueryOptions">
|
||||
<div class="gf-form offset-width-7">
|
||||
<gf-form-switch class="gf-form" ng-hide="ctrl.target.mode == 2"
|
||||
<gf-form-switch class="gf-form"
|
||||
label="Show disabled items"
|
||||
checked="ctrl.target.options.showDisabledItems"
|
||||
on-change="ctrl.onQueryOptionChange()">
|
||||
@@ -137,8 +139,30 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Item IDs editor mode -->
|
||||
<div class="gf-form-inline" ng-show="ctrl.target.mode == editorMode.ITEMID">
|
||||
<div class="gf-form max-width-20">
|
||||
<label class="gf-form-label query-keyword width-7">Item IDs</label>
|
||||
<input type="text"
|
||||
ng-model="ctrl.target.itemids"
|
||||
bs-typeahead="ctrl.getVariables"
|
||||
ng-blur="ctrl.onTargetBlur()"
|
||||
data-min-length=0
|
||||
data-items=100
|
||||
class="gf-form-input"
|
||||
ng-class="{
|
||||
'zbx-variable': ctrl.isVariable(ctrl.target.itServiceFilter),
|
||||
'zbx-regex': ctrl.isRegex(ctrl.target.itServiceFilter)
|
||||
}">
|
||||
</input>
|
||||
</div>
|
||||
<div class="gf-form gf-form--grow">
|
||||
<div class="gf-form-label gf-form-label--grow"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Metric processing functions -->
|
||||
<div class="gf-form-inline" ng-hide="ctrl.target.mode">
|
||||
<div class="gf-form-inline" ng-show="ctrl.target.mode == editorMode.METRICS || ctrl.target.mode == editorMode.ITEMID">
|
||||
<div class="gf-form">
|
||||
<label class="gf-form-label query-keyword width-7">Functions</label>
|
||||
<div ng-repeat="func in ctrl.target.functions" class="gf-form-label query-part" metric-function-editor></div>
|
||||
@@ -151,7 +175,7 @@
|
||||
</div>
|
||||
|
||||
<!-- Text mode options -->
|
||||
<div class="gf-form-inline" ng-show="ctrl.target.mode == 2">
|
||||
<div class="gf-form-inline" ng-show="ctrl.target.mode == editorMode.TEXT">
|
||||
<!-- Text metric regex -->
|
||||
<div class="gf-form max-width-20">
|
||||
<label class="gf-form-label query-keyword width-7">Text filter</label>
|
||||
@@ -165,6 +189,8 @@
|
||||
|
||||
<gf-form-switch class="gf-form" label="Use capture groups" checked="ctrl.target.useCaptureGroups" on-change="ctrl.onTargetBlur()">
|
||||
</gf-form-switch>
|
||||
<div class="gf-form gf-form--grow">
|
||||
<div class="gf-form-label gf-form-label--grow"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</query-editor-row>
|
||||
|
||||
89
dist/datasource-zabbix/query.controller.js
vendored
89
dist/datasource-zabbix/query.controller.js
vendored
@@ -1,9 +1,9 @@
|
||||
'use strict';
|
||||
|
||||
System.register(['app/plugins/sdk', 'angular', 'lodash', './constants', './utils', './metricFunctions', './migrations', './add-metric-function.directive', './metric-function-editor.directive', './css/query-editor.css!'], function (_export, _context) {
|
||||
System.register(['app/plugins/sdk', 'lodash', './constants', './utils', './metricFunctions', './migrations', './add-metric-function.directive', './metric-function-editor.directive', './css/query-editor.css!'], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var QueryCtrl, angular, _, c, utils, metricFunctions, migrations, _createClass, ZabbixQueryController;
|
||||
var QueryCtrl, _, c, utils, metricFunctions, migrations, _createClass, ZabbixQueryController;
|
||||
|
||||
function _classCallCheck(instance, Constructor) {
|
||||
if (!(instance instanceof Constructor)) {
|
||||
@@ -38,8 +38,6 @@ System.register(['app/plugins/sdk', 'angular', 'lodash', './constants', './utils
|
||||
return {
|
||||
setters: [function (_appPluginsSdk) {
|
||||
QueryCtrl = _appPluginsSdk.QueryCtrl;
|
||||
}, function (_angular) {
|
||||
angular = _angular.default;
|
||||
}, function (_lodash) {
|
||||
_ = _lodash.default;
|
||||
}, function (_constants) {
|
||||
@@ -85,17 +83,24 @@ System.register(['app/plugins/sdk', 'angular', 'lodash', './constants', './utils
|
||||
_this.replaceTemplateVars = _this.datasource.replaceTemplateVars;
|
||||
_this.templateSrv = templateSrv;
|
||||
|
||||
_this.editorModes = {
|
||||
0: { value: 'num', text: 'Metrics', mode: c.MODE_METRICS },
|
||||
1: { value: 'itservice', text: 'IT Services', mode: c.MODE_ITSERVICE },
|
||||
2: { value: 'text', text: 'Text', mode: c.MODE_TEXT }
|
||||
_this.editorModes = [{ value: 'num', text: 'Metrics', mode: c.MODE_METRICS }, { value: 'text', text: 'Text', mode: c.MODE_TEXT }, { value: 'itservice', text: 'IT Services', mode: c.MODE_ITSERVICE }, { value: 'itemid', text: 'Item ID', mode: c.MODE_ITEMID }];
|
||||
|
||||
_this.$scope.editorMode = {
|
||||
METRICS: c.MODE_METRICS,
|
||||
TEXT: c.MODE_TEXT,
|
||||
ITSERVICE: c.MODE_ITSERVICE,
|
||||
ITEMID: c.MODE_ITEMID
|
||||
};
|
||||
|
||||
_this.slaPropertyList = [{ name: "Status", property: "status" }, { name: "SLA", property: "sla" }, { name: "OK time", property: "okTime" }, { name: "Problem time", property: "problemTime" }, { name: "Down time", property: "downtimeTime" }];
|
||||
|
||||
// Map functions for bs-typeahead
|
||||
_this.getGroupNames = _.bind(_this.getMetricNames, _this, 'groupList');
|
||||
_this.getHostNames = _.bind(_this.getMetricNames, _this, 'hostList', true);
|
||||
_this.getApplicationNames = _.bind(_this.getMetricNames, _this, 'appList');
|
||||
_this.getItemNames = _.bind(_this.getMetricNames, _this, 'itemList');
|
||||
_this.getITServices = _.bind(_this.getMetricNames, _this, 'itServiceList');
|
||||
_this.getVariables = _.bind(_this.getTemplateVariables, _this);
|
||||
|
||||
// Update metric suggestion when template variable was changed
|
||||
$rootScope.$on('template-variable-value-updated', function () {
|
||||
@@ -122,14 +127,14 @@ System.register(['app/plugins/sdk', 'angular', 'lodash', './constants', './utils
|
||||
|
||||
// Load default values
|
||||
var targetDefaults = {
|
||||
mode: c.MODE_METRICS,
|
||||
group: { filter: "" },
|
||||
host: { filter: "" },
|
||||
application: { filter: "" },
|
||||
item: { filter: "" },
|
||||
functions: [],
|
||||
options: {
|
||||
showDisabledItems: false
|
||||
'mode': c.MODE_METRICS,
|
||||
'group': { 'filter': "" },
|
||||
'host': { 'filter': "" },
|
||||
'application': { 'filter': "" },
|
||||
'item': { 'filter': "" },
|
||||
'functions': [],
|
||||
'options': {
|
||||
'showDisabledItems': false
|
||||
}
|
||||
};
|
||||
_.defaults(target, targetDefaults);
|
||||
@@ -141,13 +146,10 @@ System.register(['app/plugins/sdk', 'angular', 'lodash', './constants', './utils
|
||||
|
||||
if (target.mode === c.MODE_METRICS || target.mode === c.MODE_TEXT) {
|
||||
|
||||
this.downsampleFunctionList = [{ name: "avg", value: "avg" }, { name: "min", value: "min" }, { name: "max", value: "max" }, { name: "sum", value: "sum" }, { name: "count", value: "count" }];
|
||||
|
||||
this.initFilters();
|
||||
} else if (target.mode === c.MODE_ITSERVICE) {
|
||||
this.slaPropertyList = [{ name: "Status", property: "status" }, { name: "SLA", property: "sla" }, { name: "OK time", property: "okTime" }, { name: "Problem time", property: "problemTime" }, { name: "Down time", property: "downtimeTime" }];
|
||||
this.itserviceList = [{ name: "test" }];
|
||||
this.updateITServiceList();
|
||||
_.defaults(target, { slaProperty: { name: "SLA", property: "sla" } });
|
||||
this.suggestITServices();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -158,7 +160,8 @@ System.register(['app/plugins/sdk', 'angular', 'lodash', './constants', './utils
|
||||
_createClass(ZabbixQueryController, [{
|
||||
key: 'initFilters',
|
||||
value: function initFilters() {
|
||||
var itemtype = this.editorModes[this.target.mode].value;
|
||||
var itemtype = _.find(this.editorModes, { 'mode': this.target.mode });
|
||||
itemtype = itemtype ? itemtype.value : null;
|
||||
return Promise.all([this.suggestGroups(), this.suggestHosts(), this.suggestApps(), this.suggestItems(itemtype)]);
|
||||
}
|
||||
}, {
|
||||
@@ -177,6 +180,13 @@ System.register(['app/plugins/sdk', 'angular', 'lodash', './constants', './utils
|
||||
|
||||
return metrics;
|
||||
}
|
||||
}, {
|
||||
key: 'getTemplateVariables',
|
||||
value: function getTemplateVariables() {
|
||||
return _.map(this.templateSrv.variables, function (variable) {
|
||||
return '$' + variable.name;
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'suggestGroups',
|
||||
value: function suggestGroups() {
|
||||
@@ -230,6 +240,16 @@ System.register(['app/plugins/sdk', 'angular', 'lodash', './constants', './utils
|
||||
return items;
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'suggestITServices',
|
||||
value: function suggestITServices() {
|
||||
var _this6 = this;
|
||||
|
||||
return this.zabbix.getITService().then(function (itservices) {
|
||||
_this6.metric.itServiceList = itservices;
|
||||
return itservices;
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'isRegex',
|
||||
value: function isRegex(str) {
|
||||
@@ -259,11 +279,11 @@ System.register(['app/plugins/sdk', 'angular', 'lodash', './constants', './utils
|
||||
}, {
|
||||
key: 'isContainsVariables',
|
||||
value: function isContainsVariables() {
|
||||
var _this6 = this;
|
||||
var _this7 = this;
|
||||
|
||||
return _.some(['group', 'host', 'application'], function (field) {
|
||||
if (_this6.target[field] && _this6.target[field].filter) {
|
||||
return utils.isTemplateVariable(_this6.target[field].filter, _this6.templateSrv.variables);
|
||||
if (_this7.target[field] && _this7.target[field].filter) {
|
||||
return utils.isTemplateVariable(_this7.target[field].filter, _this7.templateSrv.variables);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -356,24 +376,7 @@ System.register(['app/plugins/sdk', 'angular', 'lodash', './constants', './utils
|
||||
value: function switchEditorMode(mode) {
|
||||
this.target.mode = mode;
|
||||
this.init();
|
||||
}
|
||||
}, {
|
||||
key: 'updateITServiceList',
|
||||
value: function updateITServiceList() {
|
||||
var _this7 = this;
|
||||
|
||||
this.zabbix.getITService().then(function (iteservices) {
|
||||
_this7.itserviceList = [];
|
||||
_this7.itserviceList = _this7.itserviceList.concat(iteservices);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'selectITService',
|
||||
value: function selectITService() {
|
||||
if (!_.isEqual(this.oldTarget, this.target) && _.isEmpty(this.target.errors)) {
|
||||
this.oldTarget = angular.copy(this.target);
|
||||
this.panelCtrl.refresh();
|
||||
}
|
||||
this.targetChanged();
|
||||
}
|
||||
}]);
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -15,7 +15,10 @@ describe('ZabbixDatasource', () => {
|
||||
password: 'zabbix',
|
||||
trends: true,
|
||||
trendsFrom: '14d',
|
||||
trendsRange: '7d'
|
||||
trendsRange: '7d',
|
||||
dbConnection: {
|
||||
enabled: false
|
||||
}
|
||||
}
|
||||
};
|
||||
ctx.templateSrv = {};
|
||||
|
||||
50
dist/datasource-zabbix/specs/utils_specs.js
vendored
50
dist/datasource-zabbix/specs/utils_specs.js
vendored
@@ -88,4 +88,54 @@ describe('Utils', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('splitTemplateQuery()', () => {
|
||||
|
||||
// Backward compatibility
|
||||
it('should properly split query in old format', (done) => {
|
||||
let test_cases = [
|
||||
{
|
||||
query: `/alu/./tw-(nyc|que|brx|dwt|brk)-sta_(\w|\d)*-alu-[0-9{2}/`,
|
||||
expected: ['/alu/', '/tw-(nyc|que|brx|dwt|brk)-sta_(\w|\d)*-alu-[0-9{2}/']
|
||||
},
|
||||
{
|
||||
query: `a.b.c.d`,
|
||||
expected: ['a', 'b', 'c', 'd']
|
||||
}
|
||||
];
|
||||
|
||||
_.each(test_cases, test_case => {
|
||||
let splitQuery = utils.splitTemplateQuery(test_case.query);
|
||||
expect(splitQuery).to.eql(test_case.expected);
|
||||
});
|
||||
done();
|
||||
});
|
||||
|
||||
it('should properly split query', (done) => {
|
||||
let test_cases = [
|
||||
{
|
||||
query: `{alu}{/tw-(nyc|que|brx|dwt|brk)-sta_(\w|\d)*-alu-[0-9]*/}`,
|
||||
expected: ['alu', '/tw-(nyc|que|brx|dwt|brk)-sta_(\w|\d)*-alu-[0-9]*/']
|
||||
},
|
||||
{
|
||||
query: `{alu}{/tw-(nyc|que|brx|dwt|brk)-sta_(\w|\d)*-alu-[0-9]{2}/}`,
|
||||
expected: ['alu', '/tw-(nyc|que|brx|dwt|brk)-sta_(\w|\d)*-alu-[0-9]{2}/']
|
||||
},
|
||||
{
|
||||
query: `{a}{b}{c}{d}`,
|
||||
expected: ['a', 'b', 'c', 'd']
|
||||
},
|
||||
{
|
||||
query: `{a}{b.c.d}`,
|
||||
expected: ['a', 'b.c.d']
|
||||
}
|
||||
];
|
||||
|
||||
_.each(test_cases, test_case => {
|
||||
let splitQuery = utils.splitTemplateQuery(test_case.query);
|
||||
expect(splitQuery).to.eql(test_case.expected);
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
19
dist/datasource-zabbix/utils.js
vendored
19
dist/datasource-zabbix/utils.js
vendored
@@ -28,6 +28,16 @@ System.register(['lodash', 'moment'], function (_export, _context) {
|
||||
|
||||
_export('expandItemName', expandItemName);
|
||||
|
||||
function expandItems(items) {
|
||||
_.forEach(items, function (item) {
|
||||
item.item = item.name;
|
||||
item.name = expandItemName(item.item, item.key_);
|
||||
return item;
|
||||
});
|
||||
return items;
|
||||
}
|
||||
_export('expandItems', expandItems);
|
||||
|
||||
function splitKeyParams(paramStr) {
|
||||
var params = [];
|
||||
var quoted = false;
|
||||
@@ -56,7 +66,9 @@ System.register(['lodash', 'moment'], function (_export, _context) {
|
||||
|
||||
params.push(param);
|
||||
return params;
|
||||
}function containsMacro(itemName) {
|
||||
}
|
||||
|
||||
function containsMacro(itemName) {
|
||||
return MACRO_PATTERN.test(itemName);
|
||||
}
|
||||
|
||||
@@ -99,7 +111,7 @@ System.register(['lodash', 'moment'], function (_export, _context) {
|
||||
* {group}{host.com} -> [group, host.com]
|
||||
*/
|
||||
function splitTemplateQuery(query) {
|
||||
var splitPattern = /{[^{}]*}/g;
|
||||
var splitPattern = /\{[^\{\}]*\}|\{\/.*\/\}/g;
|
||||
var split = void 0;
|
||||
|
||||
if (isContainsBraces(query)) {
|
||||
@@ -117,7 +129,8 @@ System.register(['lodash', 'moment'], function (_export, _context) {
|
||||
_export('splitTemplateQuery', splitTemplateQuery);
|
||||
|
||||
function isContainsBraces(query) {
|
||||
return query.includes('{') && query.includes('}');
|
||||
var bracesPattern = /^\{.+\}$/;
|
||||
return bracesPattern.test(query);
|
||||
}
|
||||
|
||||
// Pattern for testing regex
|
||||
|
||||
2
dist/datasource-zabbix/utils.js.map
vendored
2
dist/datasource-zabbix/utils.js.map
vendored
File diff suppressed because one or more lines are too long
36
dist/datasource-zabbix/zabbix.js
vendored
36
dist/datasource-zabbix/zabbix.js
vendored
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
System.register(['angular', 'lodash', './utils', './zabbixAPI.service.js', './zabbixCachingProxy.service.js'], function (_export, _context) {
|
||||
System.register(['angular', 'lodash', './utils', './zabbixAPI.service.js', './zabbixCachingProxy.service.js', './zabbixDBConnector'], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var angular, _, utils, _createClass;
|
||||
@@ -27,25 +27,44 @@ System.register(['angular', 'lodash', './utils', './zabbixAPI.service.js', './za
|
||||
// Each Zabbix data source instance should initialize its own API instance.
|
||||
|
||||
/** @ngInject */
|
||||
function ZabbixFactory(zabbixAPIService, ZabbixCachingProxy) {
|
||||
function ZabbixFactory(zabbixAPIService, ZabbixCachingProxy, ZabbixDBConnector) {
|
||||
var Zabbix = function () {
|
||||
function Zabbix(url, username, password, basicAuth, withCredentials, cacheTTL) {
|
||||
function Zabbix(url, options) {
|
||||
_classCallCheck(this, Zabbix);
|
||||
|
||||
var username = options.username,
|
||||
password = options.password,
|
||||
basicAuth = options.basicAuth,
|
||||
withCredentials = options.withCredentials,
|
||||
cacheTTL = options.cacheTTL,
|
||||
enableDirectDBConnection = options.enableDirectDBConnection,
|
||||
sqlDatasourceId = options.sqlDatasourceId;
|
||||
|
||||
|
||||
// Initialize Zabbix API
|
||||
var ZabbixAPI = zabbixAPIService;
|
||||
this.zabbixAPI = new ZabbixAPI(url, username, password, basicAuth, withCredentials);
|
||||
|
||||
if (enableDirectDBConnection) {
|
||||
this.dbConnector = new ZabbixDBConnector(sqlDatasourceId);
|
||||
}
|
||||
|
||||
// Initialize caching proxy for requests
|
||||
var cacheOptions = {
|
||||
enabled: true,
|
||||
ttl: cacheTTL
|
||||
};
|
||||
this.cachingProxy = new ZabbixCachingProxy(this.zabbixAPI, cacheOptions);
|
||||
this.cachingProxy = new ZabbixCachingProxy(this.zabbixAPI, this.dbConnector, cacheOptions);
|
||||
|
||||
// Proxy methods
|
||||
this.getHistory = this.cachingProxy.getHistory.bind(this.cachingProxy);
|
||||
this.getMacros = this.cachingProxy.getMacros.bind(this.cachingProxy);
|
||||
this.getItemsByIDs = this.cachingProxy.getItemsByIDs.bind(this.cachingProxy);
|
||||
|
||||
if (enableDirectDBConnection) {
|
||||
this.getHistoryDB = this.cachingProxy.getHistoryDB.bind(this.cachingProxy);
|
||||
this.getTrendsDB = this.cachingProxy.getTrendsDB.bind(this.cachingProxy);
|
||||
}
|
||||
|
||||
this.getTrend = this.zabbixAPI.getTrend.bind(this.zabbixAPI);
|
||||
this.getEvents = this.zabbixAPI.getEvents.bind(this.zabbixAPI);
|
||||
@@ -168,6 +187,13 @@ System.register(['angular', 'lodash', './utils', './zabbixAPI.service.js', './za
|
||||
return filterByQuery(items, itemFilter);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'getITServices',
|
||||
value: function getITServices(itServiceFilter) {
|
||||
return this.cachingProxy.getITServices().then(function (itServices) {
|
||||
return findByFilter(itServices, itServiceFilter);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'getTriggers',
|
||||
value: function getTriggers(groupFilter, hostFilter, appFilter, options) {
|
||||
@@ -274,7 +300,7 @@ System.register(['angular', 'lodash', './utils', './zabbixAPI.service.js', './za
|
||||
_ = _lodash.default;
|
||||
}, function (_utils) {
|
||||
utils = _utils;
|
||||
}, function (_zabbixAPIServiceJs) {}, function (_zabbixCachingProxyServiceJs) {}],
|
||||
}, function (_zabbixAPIServiceJs) {}, function (_zabbixCachingProxyServiceJs) {}, function (_zabbixDBConnector) {}],
|
||||
execute: function () {
|
||||
_createClass = function () {
|
||||
function defineProperties(target, props) {
|
||||
|
||||
2
dist/datasource-zabbix/zabbix.js.map
vendored
2
dist/datasource-zabbix/zabbix.js.map
vendored
File diff suppressed because one or more lines are too long
21
dist/datasource-zabbix/zabbixAPI.service.js
vendored
21
dist/datasource-zabbix/zabbixAPI.service.js
vendored
@@ -166,16 +166,19 @@ System.register(['angular', 'lodash', './utils', './zabbixAPICore.service'], fun
|
||||
params.filter.value_type = [1, 2, 4];
|
||||
}
|
||||
|
||||
return this.request('item.get', params).then(expandItems);
|
||||
return this.request('item.get', params).then(utils.expandItems);
|
||||
}
|
||||
}, {
|
||||
key: 'getItemsByIDs',
|
||||
value: function getItemsByIDs(itemids) {
|
||||
var params = {
|
||||
itemids: itemids,
|
||||
output: ['name', 'key_', 'value_type', 'hostid', 'status', 'state'],
|
||||
webitems: true,
|
||||
selectHosts: ['hostid', 'name']
|
||||
};
|
||||
|
||||
function expandItems(items) {
|
||||
_.forEach(items, function (item) {
|
||||
item.item = item.name;
|
||||
item.name = utils.expandItemName(item.item, item.key_);
|
||||
return item;
|
||||
});
|
||||
return items;
|
||||
}
|
||||
return this.request('item.get', params).then(utils.expandItems);
|
||||
}
|
||||
}, {
|
||||
key: 'getMacros',
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -29,10 +29,11 @@ System.register(['angular', 'lodash'], function (_export, _context) {
|
||||
/** @ngInject */
|
||||
function ZabbixCachingProxyFactory() {
|
||||
var ZabbixCachingProxy = function () {
|
||||
function ZabbixCachingProxy(zabbixAPI, cacheOptions) {
|
||||
function ZabbixCachingProxy(zabbixAPI, zabbixDBConnector, cacheOptions) {
|
||||
_classCallCheck(this, ZabbixCachingProxy);
|
||||
|
||||
this.zabbixAPI = zabbixAPI;
|
||||
this.dbConnector = zabbixDBConnector;
|
||||
this.cacheEnabled = cacheOptions.enabled;
|
||||
this.ttl = cacheOptions.ttl || 600000; // 10 minutes by default
|
||||
|
||||
@@ -45,7 +46,8 @@ System.register(['angular', 'lodash'], function (_export, _context) {
|
||||
history: {},
|
||||
trends: {},
|
||||
macros: {},
|
||||
globalMacros: {}
|
||||
globalMacros: {},
|
||||
itServices: {}
|
||||
};
|
||||
|
||||
this.historyPromises = {};
|
||||
@@ -53,6 +55,11 @@ System.register(['angular', 'lodash'], function (_export, _context) {
|
||||
// Don't run duplicated history requests
|
||||
this.getHistory = callAPIRequestOnce(_.bind(this.zabbixAPI.getHistory, this.zabbixAPI), this.historyPromises, getHistoryRequestHash);
|
||||
|
||||
if (this.dbConnector) {
|
||||
this.getHistoryDB = callAPIRequestOnce(_.bind(this.dbConnector.getHistory, this.dbConnector), this.historyPromises, getDBQueryHash);
|
||||
this.getTrendsDB = callAPIRequestOnce(_.bind(this.dbConnector.getTrends, this.dbConnector), this.historyPromises, getDBQueryHash);
|
||||
}
|
||||
|
||||
// Don't run duplicated requests
|
||||
this.groupPromises = {};
|
||||
this.getGroupsOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getGroups, this.zabbixAPI), this.groupPromises, getRequestHash);
|
||||
@@ -66,6 +73,12 @@ System.register(['angular', 'lodash'], function (_export, _context) {
|
||||
this.itemPromises = {};
|
||||
this.getItemsOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getItems, this.zabbixAPI), this.itemPromises, getRequestHash);
|
||||
|
||||
this.itemByIdPromises = {};
|
||||
this.getItemsByIdOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getItemsByIDs, this.zabbixAPI), this.itemPromises, getRequestHash);
|
||||
|
||||
this.itServicesPromises = {};
|
||||
this.getITServicesOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getITService, this.zabbixAPI), this.itServicesPromises, getRequestHash);
|
||||
|
||||
this.macroPromises = {};
|
||||
this.getMacrosOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getMacros, this.zabbixAPI), this.macroPromises, getRequestHash);
|
||||
|
||||
@@ -120,6 +133,17 @@ System.register(['angular', 'lodash'], function (_export, _context) {
|
||||
var params = [hostids, appids, itemtype];
|
||||
return this.proxyRequest(this.getItemsOnce, params, this.cache.items);
|
||||
}
|
||||
}, {
|
||||
key: 'getItemsByIDs',
|
||||
value: function getItemsByIDs(itemids) {
|
||||
var params = [itemids];
|
||||
return this.proxyRequest(this.getItemsByIdOnce, params, this.cache.items);
|
||||
}
|
||||
}, {
|
||||
key: 'getITServices',
|
||||
value: function getITServices() {
|
||||
return this.proxyRequest(this.getITServicesOnce, [], this.cache.itServices);
|
||||
}
|
||||
}, {
|
||||
key: 'getMacros',
|
||||
value: function getMacros(hostids) {
|
||||
@@ -209,6 +233,14 @@ System.register(['angular', 'lodash'], function (_export, _context) {
|
||||
return stamp.getHash();
|
||||
}
|
||||
|
||||
function getDBQueryHash(args) {
|
||||
var itemids = _.map(args[0], 'itemid');
|
||||
var consolidateBy = args[3].consolidateBy;
|
||||
var intervalMs = args[3].intervalMs;
|
||||
var stamp = itemids.join() + args[1] + args[2] + consolidateBy + intervalMs;
|
||||
return stamp.getHash();
|
||||
}
|
||||
|
||||
return {
|
||||
setters: [function (_angular) {
|
||||
angular = _angular.default;
|
||||
|
||||
File diff suppressed because one or more lines are too long
233
dist/datasource-zabbix/zabbixDBConnector.js
vendored
Normal file
233
dist/datasource-zabbix/zabbixDBConnector.js
vendored
Normal file
@@ -0,0 +1,233 @@
|
||||
'use strict';
|
||||
|
||||
System.register(['angular', 'lodash'], function (_export, _context) {
|
||||
"use strict";
|
||||
|
||||
var angular, _, _createClass, DEFAULT_QUERY_LIMIT, HISTORY_TO_TABLE_MAP, TREND_TO_TABLE_MAP, consolidateByFunc, consolidateByTrendColumns;
|
||||
|
||||
function _classCallCheck(instance, Constructor) {
|
||||
if (!(instance instanceof Constructor)) {
|
||||
throw new TypeError("Cannot call a class as a function");
|
||||
}
|
||||
}
|
||||
|
||||
/** @ngInject */
|
||||
function ZabbixDBConnectorFactory(datasourceSrv, backendSrv) {
|
||||
var ZabbixDBConnector = function () {
|
||||
function ZabbixDBConnector(sqlDataSourceId) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
|
||||
_classCallCheck(this, ZabbixDBConnector);
|
||||
|
||||
var limit = options.limit;
|
||||
|
||||
|
||||
this.sqlDataSourceId = sqlDataSourceId;
|
||||
this.limit = limit || DEFAULT_QUERY_LIMIT;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
var ds = _.find(datasourceSrv.getAll(), { 'id': datasourceId });
|
||||
if (ds) {
|
||||
return datasourceSrv.loadDatasource(ds.name).then(function (ds) {
|
||||
console.log('SQL data source loaded', ds);
|
||||
});
|
||||
} else {
|
||||
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) {
|
||||
var _this = this;
|
||||
|
||||
var intervalMs = options.intervalMs,
|
||||
consolidateBy = options.consolidateBy;
|
||||
|
||||
var intervalSec = Math.ceil(intervalMs / 1000);
|
||||
|
||||
consolidateBy = consolidateBy || 'avg';
|
||||
var aggFunction = consolidateByFunc[consolidateBy];
|
||||
|
||||
// Group items by value type and perform request for each value type
|
||||
var grouped_items = _.groupBy(items, 'value_type');
|
||||
var promises = _.map(grouped_items, function (items, value_type) {
|
||||
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 ';
|
||||
|
||||
query = compactSQLQuery(query);
|
||||
return _this.invokeSQLQuery(query);
|
||||
});
|
||||
|
||||
return Promise.all(promises).then(function (results) {
|
||||
return _.flatten(results);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'getTrends',
|
||||
value: function getTrends(items, timeFrom, timeTill, options) {
|
||||
var _this2 = this;
|
||||
|
||||
var intervalMs = options.intervalMs,
|
||||
consolidateBy = options.consolidateBy;
|
||||
|
||||
var intervalSec = Math.ceil(intervalMs / 1000);
|
||||
|
||||
consolidateBy = consolidateBy || 'avg';
|
||||
var aggFunction = consolidateByFunc[consolidateBy];
|
||||
|
||||
// Group items by value type and perform request for each value type
|
||||
var grouped_items = _.groupBy(items, 'value_type');
|
||||
var promises = _.map(grouped_items, function (items, value_type) {
|
||||
var itemids = _.map(items, 'itemid').join(', ');
|
||||
var table = TREND_TO_TABLE_MAP[value_type];
|
||||
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 ';
|
||||
|
||||
query = compactSQLQuery(query);
|
||||
return _this2.invokeSQLQuery(query);
|
||||
});
|
||||
|
||||
return Promise.all(promises).then(function (results) {
|
||||
return _.flatten(results);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'handleGrafanaTSResponse',
|
||||
value: function handleGrafanaTSResponse(history, items) {
|
||||
var addHostName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
||||
|
||||
return convertGrafanaTSResponse(history, items, addHostName);
|
||||
}
|
||||
}, {
|
||||
key: 'invokeSQLQuery',
|
||||
value: function invokeSQLQuery(query) {
|
||||
var queryDef = {
|
||||
refId: 'A',
|
||||
format: 'time_series',
|
||||
datasourceId: this.sqlDataSourceId,
|
||||
rawSql: query,
|
||||
maxDataPoints: this.limit
|
||||
};
|
||||
|
||||
return backendSrv.datasourceRequest({
|
||||
url: '/api/tsdb/query',
|
||||
method: 'POST',
|
||||
data: {
|
||||
queries: [queryDef]
|
||||
}
|
||||
}).then(function (response) {
|
||||
var results = response.data.results;
|
||||
if (results['A']) {
|
||||
return results['A'].series;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
||||
return ZabbixDBConnector;
|
||||
}();
|
||||
|
||||
return ZabbixDBConnector;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function convertGrafanaTSResponse(time_series, items, addHostName) {
|
||||
var hosts = _.uniqBy(_.flatten(_.map(items, 'hosts')), 'hostid'); //uniqBy is needed to deduplicate
|
||||
var grafanaSeries = _.map(time_series, function (series) {
|
||||
var itemid = series.name;
|
||||
var datapoints = series.points;
|
||||
var item = _.find(items, { 'itemid': itemid });
|
||||
var alias = item.name;
|
||||
if (_.keys(hosts).length > 1 && addHostName) {
|
||||
//only when actual multi hosts selected
|
||||
var host = _.find(hosts, { 'hostid': item.hostid });
|
||||
alias = host.name + ": " + alias;
|
||||
}
|
||||
return {
|
||||
target: alias,
|
||||
datapoints: datapoints
|
||||
};
|
||||
});
|
||||
|
||||
return _.sortBy(grafanaSeries, 'target');
|
||||
}
|
||||
|
||||
function compactSQLQuery(query) {
|
||||
return query.replace(/\s+/g, ' ');
|
||||
}
|
||||
return {
|
||||
setters: [function (_angular) {
|
||||
angular = _angular.default;
|
||||
}, 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;
|
||||
};
|
||||
}();
|
||||
|
||||
DEFAULT_QUERY_LIMIT = 10000;
|
||||
HISTORY_TO_TABLE_MAP = {
|
||||
'0': 'history',
|
||||
'1': 'history_str',
|
||||
'2': 'history_log',
|
||||
'3': 'history_uint',
|
||||
'4': 'history_text'
|
||||
};
|
||||
TREND_TO_TABLE_MAP = {
|
||||
'0': 'trends',
|
||||
'3': 'trends_uint'
|
||||
};
|
||||
consolidateByFunc = {
|
||||
'avg': 'AVG',
|
||||
'min': 'MIN',
|
||||
'max': 'MAX',
|
||||
'sum': 'SUM',
|
||||
'count': 'COUNT'
|
||||
};
|
||||
consolidateByTrendColumns = {
|
||||
'avg': 'value_avg',
|
||||
'min': 'value_min',
|
||||
'max': 'value_max'
|
||||
};
|
||||
angular.module('grafana.services').factory('ZabbixDBConnector', ZabbixDBConnectorFactory);
|
||||
}
|
||||
};
|
||||
});
|
||||
//# sourceMappingURL=zabbixDBConnector.js.map
|
||||
1
dist/datasource-zabbix/zabbixDBConnector.js.map
vendored
Normal file
1
dist/datasource-zabbix/zabbixDBConnector.js.map
vendored
Normal file
File diff suppressed because one or more lines are too long
4
dist/panel-triggers/editor.html
vendored
4
dist/panel-triggers/editor.html
vendored
@@ -55,6 +55,10 @@
|
||||
placeholder="trigger name"
|
||||
class="gf-form-input"
|
||||
ng-style="editor.panel.triggers.trigger.style"
|
||||
ng-class="{
|
||||
'zbx-variable': editor.isVariable(editor.panel.triggers.trigger.filter),
|
||||
'zbx-regex': editor.isRegex(editor.panel.triggers.trigger.filter)
|
||||
}"
|
||||
empty-to-null>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
10
dist/panel-triggers/module.js
vendored
10
dist/panel-triggers/module.js
vendored
@@ -206,6 +206,7 @@ System.register(['lodash', 'jquery', 'moment', 'app/plugins/sdk', '../datasource
|
||||
return this.datasourceSrv.get(this.panel.datasource).then(function (datasource) {
|
||||
var zabbix = datasource.zabbix;
|
||||
_this3.zabbix = zabbix;
|
||||
_this3.datasource = datasource;
|
||||
var showEvents = _this3.panel.showEvents.value;
|
||||
var triggerFilter = _this3.panel.triggers;
|
||||
var hideHostsInMaintenance = _this3.panel.hideHostsInMaintenance;
|
||||
@@ -219,10 +220,10 @@ System.register(['lodash', 'jquery', 'moment', 'app/plugins/sdk', '../datasource
|
||||
showTriggers: showEvents,
|
||||
hideHostsInMaintenance: hideHostsInMaintenance
|
||||
};
|
||||
var getTriggers = zabbix.getTriggers(groupFilter, hostFilter, appFilter, triggersOptions);
|
||||
return getTriggers.then(function (triggers) {
|
||||
return _.map(triggers, _this3.formatTrigger.bind(_this3));
|
||||
});
|
||||
|
||||
return zabbix.getTriggers(groupFilter, hostFilter, appFilter, triggersOptions);
|
||||
}).then(function (triggers) {
|
||||
return _.map(triggers, _this3.formatTrigger.bind(_this3));
|
||||
});
|
||||
}
|
||||
}, {
|
||||
@@ -272,6 +273,7 @@ System.register(['lodash', 'jquery', 'moment', 'app/plugins/sdk', '../datasource
|
||||
|
||||
// Filter triggers by description
|
||||
var triggerFilter = this.panel.triggers.trigger.filter;
|
||||
triggerFilter = this.datasource.replaceTemplateVars(triggerFilter);
|
||||
if (triggerFilter) {
|
||||
triggerList = _filterTriggers(triggerList, triggerFilter);
|
||||
}
|
||||
|
||||
2
dist/panel-triggers/module.js.map
vendored
2
dist/panel-triggers/module.js.map
vendored
File diff suppressed because one or more lines are too long
4
dist/plugin.json
vendored
4
dist/plugin.json
vendored
@@ -26,8 +26,8 @@
|
||||
{"name": "Metric Editor", "path": "img/screenshot-metric_editor.png"},
|
||||
{"name": "Triggers", "path": "img/screenshot-triggers.png"}
|
||||
],
|
||||
"version": "3.4.0",
|
||||
"updated": "2017-05-17"
|
||||
"version": "3.5.1",
|
||||
"updated": "2017-07-10"
|
||||
},
|
||||
|
||||
"includes": [
|
||||
|
||||
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';
|
||||
3
dist/test/datasource-zabbix/constants.js
vendored
3
dist/test/datasource-zabbix/constants.js
vendored
@@ -5,8 +5,9 @@ Object.defineProperty(exports, "__esModule", {
|
||||
});
|
||||
// Editor modes
|
||||
var MODE_METRICS = exports.MODE_METRICS = 0;
|
||||
var MODE_TEXT = exports.MODE_TEXT = 2;
|
||||
var MODE_ITSERVICE = exports.MODE_ITSERVICE = 1;
|
||||
var MODE_TEXT = exports.MODE_TEXT = 2;
|
||||
var MODE_ITEMID = exports.MODE_ITEMID = 3;
|
||||
|
||||
// Triggers severity
|
||||
var SEV_NOT_CLASSIFIED = exports.SEV_NOT_CLASSIFIED = 0;
|
||||
|
||||
253
dist/test/datasource-zabbix/datasource.js
vendored
253
dist/test/datasource-zabbix/datasource.js
vendored
@@ -64,6 +64,9 @@ var ZabbixAPIDatasource = function () {
|
||||
this.dashboardSrv = dashboardSrv;
|
||||
this.zabbixAlertingSrv = zabbixAlertingSrv;
|
||||
|
||||
// Use custom format for template variables
|
||||
this.replaceTemplateVars = _lodash2.default.partial(replaceTemplateVars, this.templateSrv);
|
||||
|
||||
// General data source settings
|
||||
this.name = instanceSettings.name;
|
||||
this.url = instanceSettings.url;
|
||||
@@ -88,10 +91,21 @@ var ZabbixAPIDatasource = function () {
|
||||
this.addThresholds = instanceSettings.jsonData.addThresholds;
|
||||
this.alertingMinSeverity = instanceSettings.jsonData.alertingMinSeverity || c.SEV_WARNING;
|
||||
|
||||
this.zabbix = new Zabbix(this.url, this.username, this.password, this.basicAuth, this.withCredentials, this.cacheTTL);
|
||||
// Direct DB Connection options
|
||||
this.enableDirectDBConnection = instanceSettings.jsonData.dbConnection.enable;
|
||||
this.sqlDatasourceId = instanceSettings.jsonData.dbConnection.datasourceId;
|
||||
|
||||
// Use custom format for template variables
|
||||
this.replaceTemplateVars = _lodash2.default.partial(replaceTemplateVars, this.templateSrv);
|
||||
var zabbixOptions = {
|
||||
username: this.username,
|
||||
password: this.password,
|
||||
basicAuth: this.basicAuth,
|
||||
withCredentials: this.withCredentials,
|
||||
cacheTTL: this.cacheTTL,
|
||||
enableDirectDBConnection: this.enableDirectDBConnection,
|
||||
sqlDatasourceId: this.sqlDatasourceId
|
||||
};
|
||||
|
||||
this.zabbix = new Zabbix(this.url, zabbixOptions);
|
||||
}
|
||||
|
||||
////////////////////////
|
||||
@@ -126,6 +140,11 @@ var ZabbixAPIDatasource = function () {
|
||||
|
||||
// Create request for each target
|
||||
var promises = _lodash2.default.map(options.targets, function (t) {
|
||||
// Don't request undefined and hidden targets
|
||||
if (t.hide) {
|
||||
return [];
|
||||
}
|
||||
|
||||
var timeFrom = Math.ceil(dateMath.parse(options.range.from) / 1000);
|
||||
var timeTo = Math.ceil(dateMath.parse(options.range.to) / 1000);
|
||||
|
||||
@@ -149,7 +168,7 @@ var ZabbixAPIDatasource = function () {
|
||||
var useTrends = _this.isUseTrends(timeRange);
|
||||
|
||||
// Metrics or Text query mode
|
||||
if (target.mode !== c.MODE_ITSERVICE) {
|
||||
if (target.mode === c.MODE_METRICS || target.mode === c.MODE_TEXT || target.mode === c.MODE_ITEMID) {
|
||||
// Migrate old targets
|
||||
target = migrations.migrate(target);
|
||||
|
||||
@@ -162,20 +181,13 @@ var ZabbixAPIDatasource = function () {
|
||||
return _this.queryNumericData(target, timeRange, useTrends, options);
|
||||
} else if (target.mode === c.MODE_TEXT) {
|
||||
return _this.queryTextData(target, timeRange);
|
||||
} else if (target.mode === c.MODE_ITEMID) {
|
||||
return _this.queryItemIdData(target, timeRange, useTrends, options);
|
||||
}
|
||||
} else if (target.mode === c.MODE_ITSERVICE) {
|
||||
// IT services mode
|
||||
return _this.queryITServiceData(target, timeRange, options);
|
||||
}
|
||||
|
||||
// IT services mode
|
||||
else if (target.mode === c.MODE_ITSERVICE) {
|
||||
// Don't show undefined and hidden targets
|
||||
if (target.hide || !target.itservice || !target.slaProperty) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return _this.zabbix.getSLA(target.itservice.serviceid, timeRange).then(function (slaObject) {
|
||||
return _responseHandler2.default.handleSLAResponse(target.itservice, target.slaProperty, slaObject);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Data for panel (all targets)
|
||||
@@ -183,24 +195,48 @@ var ZabbixAPIDatasource = function () {
|
||||
return { data: data };
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Query target data for Metrics mode
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'queryNumericData',
|
||||
value: function queryNumericData(target, timeRange, useTrends, options) {
|
||||
var _this2 = this;
|
||||
|
||||
var _timeRange = _slicedToArray(timeRange, 2),
|
||||
timeFrom = _timeRange[0],
|
||||
timeTo = _timeRange[1];
|
||||
|
||||
var getItemOptions = {
|
||||
itemtype: 'num'
|
||||
};
|
||||
return this.zabbix.getItemsFromTarget(target, getItemOptions).then(function (items) {
|
||||
var getHistoryPromise = void 0;
|
||||
return _this2.queryNumericDataForItems(items, target, timeRange, useTrends, options);
|
||||
});
|
||||
}
|
||||
|
||||
if (useTrends) {
|
||||
var valueType = _this2.getTrendValueType(target);
|
||||
getHistoryPromise = _this2.zabbix.getTrend(items, timeFrom, timeTo).then(function (history) {
|
||||
/**
|
||||
* Query history for numeric items
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'queryNumericDataForItems',
|
||||
value: function queryNumericDataForItems(items, target, timeRange, useTrends, options) {
|
||||
var _this3 = this;
|
||||
|
||||
var _timeRange = _slicedToArray(timeRange, 2),
|
||||
timeFrom = _timeRange[0],
|
||||
timeTo = _timeRange[1];
|
||||
|
||||
var getHistoryPromise = void 0;
|
||||
options.consolidateBy = getConsolidateBy(target);
|
||||
|
||||
if (useTrends) {
|
||||
if (this.enableDirectDBConnection) {
|
||||
getHistoryPromise = this.zabbix.getTrendsDB(items, timeFrom, timeTo, options).then(function (history) {
|
||||
return _this3.zabbix.dbConnector.handleGrafanaTSResponse(history, items);
|
||||
});
|
||||
} else {
|
||||
var valueType = this.getTrendValueType(target);
|
||||
getHistoryPromise = this.zabbix.getTrend(items, timeFrom, timeTo).then(function (history) {
|
||||
return _responseHandler2.default.handleTrends(history, items, valueType);
|
||||
}).then(function (timeseries) {
|
||||
// Sort trend data, issue #202
|
||||
@@ -209,19 +245,24 @@ var ZabbixAPIDatasource = function () {
|
||||
return point[c.DATAPOINT_TS];
|
||||
});
|
||||
});
|
||||
|
||||
return timeseries;
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// Use history
|
||||
if (this.enableDirectDBConnection) {
|
||||
getHistoryPromise = this.zabbix.getHistoryDB(items, timeFrom, timeTo, options).then(function (history) {
|
||||
return _this3.zabbix.dbConnector.handleGrafanaTSResponse(history, items);
|
||||
});
|
||||
} else {
|
||||
// Use history
|
||||
getHistoryPromise = _this2.zabbix.getHistory(items, timeFrom, timeTo).then(function (history) {
|
||||
getHistoryPromise = this.zabbix.getHistory(items, timeFrom, timeTo).then(function (history) {
|
||||
return _responseHandler2.default.handleHistory(history, items);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return getHistoryPromise;
|
||||
}).then(function (timeseries) {
|
||||
return _this2.applyDataProcessingFunctions(timeseries, target);
|
||||
return getHistoryPromise.then(function (timeseries) {
|
||||
return _this3.applyDataProcessingFunctions(timeseries, target);
|
||||
}).then(function (timeseries) {
|
||||
return downsampleSeries(timeseries, options);
|
||||
}).catch(function (error) {
|
||||
@@ -297,10 +338,15 @@ var ZabbixAPIDatasource = function () {
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Query target data for Text mode
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'queryTextData',
|
||||
value: function queryTextData(target, timeRange) {
|
||||
var _this3 = this;
|
||||
var _this4 = this;
|
||||
|
||||
var _timeRange2 = _slicedToArray(timeRange, 2),
|
||||
timeFrom = _timeRange2[0],
|
||||
@@ -311,7 +357,7 @@ var ZabbixAPIDatasource = function () {
|
||||
};
|
||||
return this.zabbix.getItemsFromTarget(target, options).then(function (items) {
|
||||
if (items.length) {
|
||||
return _this3.zabbix.getHistory(items, timeFrom, timeTo).then(function (history) {
|
||||
return _this4.zabbix.getHistory(items, timeFrom, timeTo).then(function (history) {
|
||||
return _responseHandler2.default.handleText(history, items, target);
|
||||
});
|
||||
} else {
|
||||
@@ -320,6 +366,74 @@ var ZabbixAPIDatasource = function () {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Query target data for Item ID mode
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'queryItemIdData',
|
||||
value: function queryItemIdData(target, timeRange, useTrends, options) {
|
||||
var _this5 = this;
|
||||
|
||||
var itemids = target.itemids;
|
||||
itemids = this.templateSrv.replace(itemids, options.scopedVars, zabbixItemIdsTemplateFormat);
|
||||
itemids = _lodash2.default.map(itemids.split(','), function (itemid) {
|
||||
return itemid.trim();
|
||||
});
|
||||
|
||||
if (!itemids) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return this.zabbix.getItemsByIDs(itemids).then(function (items) {
|
||||
return _this5.queryNumericDataForItems(items, target, timeRange, useTrends, options);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Query target data for IT Services mode
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'queryITServiceData',
|
||||
value: function queryITServiceData(target, timeRange, options) {
|
||||
var _this6 = this;
|
||||
|
||||
// Don't show undefined and hidden targets
|
||||
if (target.hide || !target.itservice && !target.itServiceFilter || !target.slaProperty) {
|
||||
return [];
|
||||
}
|
||||
|
||||
var itServiceIds = [];
|
||||
var itServices = [];
|
||||
var itServiceFilter = void 0;
|
||||
var isOldVersion = target.itservice && !target.itServiceFilter;
|
||||
|
||||
if (isOldVersion) {
|
||||
// Backward compatibility
|
||||
itServiceFilter = '/.*/';
|
||||
} else {
|
||||
itServiceFilter = this.replaceTemplateVars(target.itServiceFilter, options.scopedVars);
|
||||
}
|
||||
|
||||
return this.zabbix.getITServices(itServiceFilter).then(function (itservices) {
|
||||
itServices = itservices;
|
||||
if (isOldVersion) {
|
||||
itServices = _lodash2.default.filter(itServices, { 'serviceid': target.itservice.serviceid });
|
||||
}
|
||||
|
||||
itServiceIds = _lodash2.default.map(itServices, 'serviceid');
|
||||
return itServiceIds;
|
||||
}).then(function (serviceids) {
|
||||
return _this6.zabbix.getSLA(serviceids, timeRange);
|
||||
}).then(function (slaResponse) {
|
||||
return _lodash2.default.map(itServiceIds, function (serviceid) {
|
||||
var itservice = _lodash2.default.find(itServices, { 'serviceid': serviceid });
|
||||
return _responseHandler2.default.handleSLAResponse(itservice, target.slaProperty, slaResponse);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Test connection to Zabbix API
|
||||
* @return {object} Connection status and Zabbix API version
|
||||
@@ -328,12 +442,18 @@ var ZabbixAPIDatasource = function () {
|
||||
}, {
|
||||
key: 'testDatasource',
|
||||
value: function testDatasource() {
|
||||
var _this4 = this;
|
||||
var _this7 = this;
|
||||
|
||||
var zabbixVersion = void 0;
|
||||
return this.zabbix.getVersion().then(function (version) {
|
||||
zabbixVersion = version;
|
||||
return _this4.zabbix.login();
|
||||
return _this7.zabbix.login();
|
||||
}).then(function () {
|
||||
if (_this7.enableDirectDBConnection) {
|
||||
return _this7.zabbix.dbConnector.testSQLDataSource();
|
||||
} else {
|
||||
return Promise.resolve();
|
||||
}
|
||||
}).then(function () {
|
||||
return {
|
||||
status: "success",
|
||||
@@ -347,6 +467,12 @@ var ZabbixAPIDatasource = function () {
|
||||
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",
|
||||
@@ -372,14 +498,14 @@ var ZabbixAPIDatasource = function () {
|
||||
}, {
|
||||
key: 'metricFindQuery',
|
||||
value: function metricFindQuery(query) {
|
||||
var _this5 = this;
|
||||
var _this8 = this;
|
||||
|
||||
var result = void 0;
|
||||
var parts = [];
|
||||
|
||||
// Split query. Query structure: group.host.app.item
|
||||
_lodash2.default.each(utils.splitTemplateQuery(query), function (part) {
|
||||
part = _this5.replaceTemplateVars(part, {});
|
||||
part = _this8.replaceTemplateVars(part, {});
|
||||
|
||||
// Replace wildcard to regex
|
||||
if (part === '*') {
|
||||
@@ -421,7 +547,7 @@ var ZabbixAPIDatasource = function () {
|
||||
}, {
|
||||
key: 'annotationQuery',
|
||||
value: function annotationQuery(options) {
|
||||
var _this6 = this;
|
||||
var _this9 = this;
|
||||
|
||||
var timeFrom = Math.ceil(dateMath.parse(options.rangeRaw.from) / 1000);
|
||||
var timeTo = Math.ceil(dateMath.parse(options.rangeRaw.to) / 1000);
|
||||
@@ -439,13 +565,14 @@ var ZabbixAPIDatasource = function () {
|
||||
return getTriggers.then(function (triggers) {
|
||||
|
||||
// Filter triggers by description
|
||||
if (utils.isRegex(annotation.trigger)) {
|
||||
var triggerName = _this9.replaceTemplateVars(annotation.trigger, {});
|
||||
if (utils.isRegex(triggerName)) {
|
||||
triggers = _lodash2.default.filter(triggers, function (trigger) {
|
||||
return utils.buildRegex(annotation.trigger).test(trigger.description);
|
||||
return utils.buildRegex(triggerName).test(trigger.description);
|
||||
});
|
||||
} else if (annotation.trigger) {
|
||||
} else if (triggerName) {
|
||||
triggers = _lodash2.default.filter(triggers, function (trigger) {
|
||||
return trigger.description === annotation.trigger;
|
||||
return trigger.description === triggerName;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -455,7 +582,7 @@ var ZabbixAPIDatasource = function () {
|
||||
});
|
||||
|
||||
var objectids = _lodash2.default.map(triggers, 'triggerid');
|
||||
return _this6.zabbix.getEvents(objectids, timeFrom, timeTo, showOkEvents).then(function (events) {
|
||||
return _this9.zabbix.getEvents(objectids, timeFrom, timeTo, showOkEvents).then(function (events) {
|
||||
var indexedTriggers = _lodash2.default.keyBy(triggers, 'triggerid');
|
||||
|
||||
// Hide acknowledged events if option enabled
|
||||
@@ -496,21 +623,23 @@ var ZabbixAPIDatasource = function () {
|
||||
}, {
|
||||
key: 'alertQuery',
|
||||
value: function alertQuery(options) {
|
||||
var _this7 = this;
|
||||
var _this10 = this;
|
||||
|
||||
var enabled_targets = filterEnabledTargets(options.targets);
|
||||
var getPanelItems = _lodash2.default.map(enabled_targets, function (target) {
|
||||
return _this7.zabbix.getItemsFromTarget(target, { itemtype: 'num' });
|
||||
var getPanelItems = _lodash2.default.map(enabled_targets, function (t) {
|
||||
var target = _lodash2.default.cloneDeep(t);
|
||||
_this10.replaceTargetVariables(target, options);
|
||||
return _this10.zabbix.getItemsFromTarget(target, { itemtype: 'num' });
|
||||
});
|
||||
|
||||
return Promise.all(getPanelItems).then(function (results) {
|
||||
var items = _lodash2.default.flatten(results);
|
||||
var itemids = _lodash2.default.map(items, 'itemid');
|
||||
|
||||
return _this7.zabbix.getAlerts(itemids);
|
||||
return _this10.zabbix.getAlerts(itemids);
|
||||
}).then(function (triggers) {
|
||||
triggers = _lodash2.default.filter(triggers, function (trigger) {
|
||||
return trigger.priority >= _this7.alertingMinSeverity;
|
||||
return trigger.priority >= _this10.alertingMinSeverity;
|
||||
});
|
||||
|
||||
if (!triggers || triggers.length === 0) {
|
||||
@@ -541,12 +670,12 @@ var ZabbixAPIDatasource = function () {
|
||||
}, {
|
||||
key: 'replaceTargetVariables',
|
||||
value: function replaceTargetVariables(target, options) {
|
||||
var _this8 = this;
|
||||
var _this11 = this;
|
||||
|
||||
var parts = ['group', 'host', 'application', 'item'];
|
||||
_lodash2.default.forEach(parts, function (p) {
|
||||
if (target[p] && target[p].filter) {
|
||||
target[p].filter = _this8.replaceTemplateVars(target[p].filter, options.scopedVars);
|
||||
target[p].filter = _this11.replaceTemplateVars(target[p].filter, options.scopedVars);
|
||||
}
|
||||
});
|
||||
target.textFilter = this.replaceTemplateVars(target.textFilter, options.scopedVars);
|
||||
@@ -554,9 +683,9 @@ var ZabbixAPIDatasource = function () {
|
||||
_lodash2.default.forEach(target.functions, function (func) {
|
||||
func.params = _lodash2.default.map(func.params, function (param) {
|
||||
if (typeof param === 'number') {
|
||||
return +_this8.templateSrv.replace(param.toString(), options.scopedVars);
|
||||
return +_this11.templateSrv.replace(param.toString(), options.scopedVars);
|
||||
} else {
|
||||
return _this8.templateSrv.replace(param, options.scopedVars);
|
||||
return _this11.templateSrv.replace(param, options.scopedVars);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -590,10 +719,23 @@ function bindFunctionDefs(functionDefs, category) {
|
||||
});
|
||||
}
|
||||
|
||||
function getConsolidateBy(target) {
|
||||
var consolidateBy = 'avg';
|
||||
var funcDef = _lodash2.default.find(target.functions, function (func) {
|
||||
return func.def.name === 'consolidateBy';
|
||||
});
|
||||
if (funcDef && funcDef.params && funcDef.params.length) {
|
||||
consolidateBy = funcDef.params[0];
|
||||
}
|
||||
return consolidateBy;
|
||||
}
|
||||
|
||||
function downsampleSeries(timeseries_data, options) {
|
||||
var defaultAgg = _dataProcessor2.default.aggregationFunctions['avg'];
|
||||
var consolidateByFunc = _dataProcessor2.default.aggregationFunctions[options.consolidateBy] || defaultAgg;
|
||||
return _lodash2.default.map(timeseries_data, function (timeseries) {
|
||||
if (timeseries.datapoints.length > options.maxDataPoints) {
|
||||
timeseries.datapoints = _dataProcessor2.default.groupBy(options.interval, _dataProcessor2.default.AVERAGE, timeseries.datapoints);
|
||||
timeseries.datapoints = _dataProcessor2.default.groupBy(options.interval, consolidateByFunc, timeseries.datapoints);
|
||||
}
|
||||
return timeseries;
|
||||
});
|
||||
@@ -625,6 +767,13 @@ function zabbixTemplateFormat(value) {
|
||||
return '(' + escapedValues.join('|') + ')';
|
||||
}
|
||||
|
||||
function zabbixItemIdsTemplateFormat(value) {
|
||||
if (typeof value === 'string') {
|
||||
return value;
|
||||
}
|
||||
return value.join(',');
|
||||
}
|
||||
|
||||
/**
|
||||
* If template variables are used in request, replace it using regex format
|
||||
* and wrap with '/' for proper multi-value work. Example:
|
||||
|
||||
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 _config = require('./config.controller');
|
||||
|
||||
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() {
|
||||
_classCallCheck(this, ZabbixQueryOptionsController);
|
||||
};
|
||||
@@ -30,7 +26,7 @@ var ZabbixAnnotationsQueryController = function ZabbixAnnotationsQueryController
|
||||
ZabbixAnnotationsQueryController.templateUrl = 'datasource-zabbix/partials/annotations.editor.html';
|
||||
|
||||
exports.Datasource = _datasource.ZabbixAPIDatasource;
|
||||
exports.ConfigCtrl = ZabbixConfigController;
|
||||
exports.ConfigCtrl = _config.ZabbixDSConfigController;
|
||||
exports.QueryCtrl = _query.ZabbixQueryController;
|
||||
exports.QueryOptionsCtrl = ZabbixQueryOptionsController;
|
||||
exports.AnnotationsQueryCtrl = ZabbixAnnotationsQueryController;
|
||||
|
||||
101
dist/test/datasource-zabbix/query.controller.js
vendored
101
dist/test/datasource-zabbix/query.controller.js
vendored
@@ -9,10 +9,6 @@ var _createClass = function () { function defineProperties(target, props) { for
|
||||
|
||||
var _sdk = require('app/plugins/sdk');
|
||||
|
||||
var _angular = require('angular');
|
||||
|
||||
var _angular2 = _interopRequireDefault(_angular);
|
||||
|
||||
var _lodash = require('lodash');
|
||||
|
||||
var _lodash2 = _interopRequireDefault(_lodash);
|
||||
@@ -64,17 +60,24 @@ var ZabbixQueryController = exports.ZabbixQueryController = function (_QueryCtrl
|
||||
_this.replaceTemplateVars = _this.datasource.replaceTemplateVars;
|
||||
_this.templateSrv = templateSrv;
|
||||
|
||||
_this.editorModes = {
|
||||
0: { value: 'num', text: 'Metrics', mode: c.MODE_METRICS },
|
||||
1: { value: 'itservice', text: 'IT Services', mode: c.MODE_ITSERVICE },
|
||||
2: { value: 'text', text: 'Text', mode: c.MODE_TEXT }
|
||||
_this.editorModes = [{ value: 'num', text: 'Metrics', mode: c.MODE_METRICS }, { value: 'text', text: 'Text', mode: c.MODE_TEXT }, { value: 'itservice', text: 'IT Services', mode: c.MODE_ITSERVICE }, { value: 'itemid', text: 'Item ID', mode: c.MODE_ITEMID }];
|
||||
|
||||
_this.$scope.editorMode = {
|
||||
METRICS: c.MODE_METRICS,
|
||||
TEXT: c.MODE_TEXT,
|
||||
ITSERVICE: c.MODE_ITSERVICE,
|
||||
ITEMID: c.MODE_ITEMID
|
||||
};
|
||||
|
||||
_this.slaPropertyList = [{ name: "Status", property: "status" }, { name: "SLA", property: "sla" }, { name: "OK time", property: "okTime" }, { name: "Problem time", property: "problemTime" }, { name: "Down time", property: "downtimeTime" }];
|
||||
|
||||
// Map functions for bs-typeahead
|
||||
_this.getGroupNames = _lodash2.default.bind(_this.getMetricNames, _this, 'groupList');
|
||||
_this.getHostNames = _lodash2.default.bind(_this.getMetricNames, _this, 'hostList', true);
|
||||
_this.getApplicationNames = _lodash2.default.bind(_this.getMetricNames, _this, 'appList');
|
||||
_this.getItemNames = _lodash2.default.bind(_this.getMetricNames, _this, 'itemList');
|
||||
_this.getITServices = _lodash2.default.bind(_this.getMetricNames, _this, 'itServiceList');
|
||||
_this.getVariables = _lodash2.default.bind(_this.getTemplateVariables, _this);
|
||||
|
||||
// Update metric suggestion when template variable was changed
|
||||
$rootScope.$on('template-variable-value-updated', function () {
|
||||
@@ -101,14 +104,14 @@ var ZabbixQueryController = exports.ZabbixQueryController = function (_QueryCtrl
|
||||
|
||||
// Load default values
|
||||
var targetDefaults = {
|
||||
mode: c.MODE_METRICS,
|
||||
group: { filter: "" },
|
||||
host: { filter: "" },
|
||||
application: { filter: "" },
|
||||
item: { filter: "" },
|
||||
functions: [],
|
||||
options: {
|
||||
showDisabledItems: false
|
||||
'mode': c.MODE_METRICS,
|
||||
'group': { 'filter': "" },
|
||||
'host': { 'filter': "" },
|
||||
'application': { 'filter': "" },
|
||||
'item': { 'filter': "" },
|
||||
'functions': [],
|
||||
'options': {
|
||||
'showDisabledItems': false
|
||||
}
|
||||
};
|
||||
_lodash2.default.defaults(target, targetDefaults);
|
||||
@@ -120,13 +123,10 @@ var ZabbixQueryController = exports.ZabbixQueryController = function (_QueryCtrl
|
||||
|
||||
if (target.mode === c.MODE_METRICS || target.mode === c.MODE_TEXT) {
|
||||
|
||||
this.downsampleFunctionList = [{ name: "avg", value: "avg" }, { name: "min", value: "min" }, { name: "max", value: "max" }, { name: "sum", value: "sum" }, { name: "count", value: "count" }];
|
||||
|
||||
this.initFilters();
|
||||
} else if (target.mode === c.MODE_ITSERVICE) {
|
||||
this.slaPropertyList = [{ name: "Status", property: "status" }, { name: "SLA", property: "sla" }, { name: "OK time", property: "okTime" }, { name: "Problem time", property: "problemTime" }, { name: "Down time", property: "downtimeTime" }];
|
||||
this.itserviceList = [{ name: "test" }];
|
||||
this.updateITServiceList();
|
||||
_lodash2.default.defaults(target, { slaProperty: { name: "SLA", property: "sla" } });
|
||||
this.suggestITServices();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -137,7 +137,8 @@ var ZabbixQueryController = exports.ZabbixQueryController = function (_QueryCtrl
|
||||
_createClass(ZabbixQueryController, [{
|
||||
key: 'initFilters',
|
||||
value: function initFilters() {
|
||||
var itemtype = this.editorModes[this.target.mode].value;
|
||||
var itemtype = _lodash2.default.find(this.editorModes, { 'mode': this.target.mode });
|
||||
itemtype = itemtype ? itemtype.value : null;
|
||||
return Promise.all([this.suggestGroups(), this.suggestHosts(), this.suggestApps(), this.suggestItems(itemtype)]);
|
||||
}
|
||||
|
||||
@@ -159,6 +160,13 @@ var ZabbixQueryController = exports.ZabbixQueryController = function (_QueryCtrl
|
||||
|
||||
return metrics;
|
||||
}
|
||||
}, {
|
||||
key: 'getTemplateVariables',
|
||||
value: function getTemplateVariables() {
|
||||
return _lodash2.default.map(this.templateSrv.variables, function (variable) {
|
||||
return '$' + variable.name;
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'suggestGroups',
|
||||
value: function suggestGroups() {
|
||||
@@ -212,6 +220,16 @@ var ZabbixQueryController = exports.ZabbixQueryController = function (_QueryCtrl
|
||||
return items;
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'suggestITServices',
|
||||
value: function suggestITServices() {
|
||||
var _this6 = this;
|
||||
|
||||
return this.zabbix.getITService().then(function (itservices) {
|
||||
_this6.metric.itServiceList = itservices;
|
||||
return itservices;
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'isRegex',
|
||||
value: function isRegex(str) {
|
||||
@@ -246,11 +264,11 @@ var ZabbixQueryController = exports.ZabbixQueryController = function (_QueryCtrl
|
||||
}, {
|
||||
key: 'isContainsVariables',
|
||||
value: function isContainsVariables() {
|
||||
var _this6 = this;
|
||||
var _this7 = this;
|
||||
|
||||
return _lodash2.default.some(['group', 'host', 'application'], function (field) {
|
||||
if (_this6.target[field] && _this6.target[field].filter) {
|
||||
return utils.isTemplateVariable(_this6.target[field].filter, _this6.templateSrv.variables);
|
||||
if (_this7.target[field] && _this7.target[field].filter) {
|
||||
return utils.isTemplateVariable(_this7.target[field].filter, _this7.templateSrv.variables);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
@@ -352,38 +370,7 @@ var ZabbixQueryController = exports.ZabbixQueryController = function (_QueryCtrl
|
||||
value: function switchEditorMode(mode) {
|
||||
this.target.mode = mode;
|
||||
this.init();
|
||||
}
|
||||
|
||||
/////////////////
|
||||
// IT Services //
|
||||
/////////////////
|
||||
|
||||
/**
|
||||
* Update list of IT services
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'updateITServiceList',
|
||||
value: function updateITServiceList() {
|
||||
var _this7 = this;
|
||||
|
||||
this.zabbix.getITService().then(function (iteservices) {
|
||||
_this7.itserviceList = [];
|
||||
_this7.itserviceList = _this7.itserviceList.concat(iteservices);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Call when IT service is selected.
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: 'selectITService',
|
||||
value: function selectITService() {
|
||||
if (!_lodash2.default.isEqual(this.oldTarget, this.target) && _lodash2.default.isEmpty(this.target.errors)) {
|
||||
this.oldTarget = _angular2.default.copy(this.target);
|
||||
this.panelCtrl.refresh();
|
||||
}
|
||||
this.targetChanged();
|
||||
}
|
||||
}]);
|
||||
|
||||
|
||||
@@ -29,7 +29,10 @@ describe('ZabbixDatasource', function () {
|
||||
password: 'zabbix',
|
||||
trends: true,
|
||||
trendsFrom: '14d',
|
||||
trendsRange: '7d'
|
||||
trendsRange: '7d',
|
||||
dbConnection: {
|
||||
enabled: false
|
||||
}
|
||||
}
|
||||
};
|
||||
ctx.templateSrv = {};
|
||||
|
||||
42
dist/test/datasource-zabbix/specs/utils_specs.js
vendored
42
dist/test/datasource-zabbix/specs/utils_specs.js
vendored
@@ -86,4 +86,46 @@ describe('Utils', function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('splitTemplateQuery()', function () {
|
||||
|
||||
// Backward compatibility
|
||||
it('should properly split query in old format', function (done) {
|
||||
var test_cases = [{
|
||||
query: '/alu/./tw-(nyc|que|brx|dwt|brk)-sta_(w|d)*-alu-[0-9{2}/',
|
||||
expected: ['/alu/', '/tw-(nyc|que|brx|dwt|brk)-sta_(\w|\d)*-alu-[0-9{2}/']
|
||||
}, {
|
||||
query: 'a.b.c.d',
|
||||
expected: ['a', 'b', 'c', 'd']
|
||||
}];
|
||||
|
||||
_lodash2.default.each(test_cases, function (test_case) {
|
||||
var splitQuery = utils.splitTemplateQuery(test_case.query);
|
||||
expect(splitQuery).to.eql(test_case.expected);
|
||||
});
|
||||
done();
|
||||
});
|
||||
|
||||
it('should properly split query', function (done) {
|
||||
var test_cases = [{
|
||||
query: '{alu}{/tw-(nyc|que|brx|dwt|brk)-sta_(w|d)*-alu-[0-9]*/}',
|
||||
expected: ['alu', '/tw-(nyc|que|brx|dwt|brk)-sta_(\w|\d)*-alu-[0-9]*/']
|
||||
}, {
|
||||
query: '{alu}{/tw-(nyc|que|brx|dwt|brk)-sta_(w|d)*-alu-[0-9]{2}/}',
|
||||
expected: ['alu', '/tw-(nyc|que|brx|dwt|brk)-sta_(\w|\d)*-alu-[0-9]{2}/']
|
||||
}, {
|
||||
query: '{a}{b}{c}{d}',
|
||||
expected: ['a', 'b', 'c', 'd']
|
||||
}, {
|
||||
query: '{a}{b.c.d}',
|
||||
expected: ['a', 'b.c.d']
|
||||
}];
|
||||
|
||||
_lodash2.default.each(test_cases, function (test_case) {
|
||||
var splitQuery = utils.splitTemplateQuery(test_case.query);
|
||||
expect(splitQuery).to.eql(test_case.expected);
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
15
dist/test/datasource-zabbix/utils.js
vendored
15
dist/test/datasource-zabbix/utils.js
vendored
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
||||
});
|
||||
exports.regexPattern = undefined;
|
||||
exports.expandItemName = expandItemName;
|
||||
exports.expandItems = expandItems;
|
||||
exports.containsMacro = containsMacro;
|
||||
exports.replaceMacro = replaceMacro;
|
||||
exports.splitTemplateQuery = splitTemplateQuery;
|
||||
@@ -49,6 +50,15 @@ function expandItemName(name, key) {
|
||||
return name;
|
||||
}
|
||||
|
||||
function expandItems(items) {
|
||||
_lodash2.default.forEach(items, function (item) {
|
||||
item.item = item.name;
|
||||
item.name = expandItemName(item.item, item.key_);
|
||||
return item;
|
||||
});
|
||||
return items;
|
||||
}
|
||||
|
||||
function splitKeyParams(paramStr) {
|
||||
var params = [];
|
||||
var quoted = false;
|
||||
@@ -120,7 +130,7 @@ function escapeMacro(macro) {
|
||||
* {group}{host.com} -> [group, host.com]
|
||||
*/
|
||||
function splitTemplateQuery(query) {
|
||||
var splitPattern = /{[^{}]*}/g;
|
||||
var splitPattern = /\{[^\{\}]*\}|\{\/.*\/\}/g;
|
||||
var split = void 0;
|
||||
|
||||
if (isContainsBraces(query)) {
|
||||
@@ -136,7 +146,8 @@ function splitTemplateQuery(query) {
|
||||
}
|
||||
|
||||
function isContainsBraces(query) {
|
||||
return query.includes('{') && query.includes('}');
|
||||
var bracesPattern = /^\{.+\}$/;
|
||||
return bracesPattern.test(query);
|
||||
}
|
||||
|
||||
// Pattern for testing regex
|
||||
|
||||
34
dist/test/datasource-zabbix/zabbix.js
vendored
34
dist/test/datasource-zabbix/zabbix.js
vendored
@@ -18,6 +18,8 @@ require('./zabbixAPI.service.js');
|
||||
|
||||
require('./zabbixCachingProxy.service.js');
|
||||
|
||||
require('./zabbixDBConnector');
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
@@ -30,25 +32,44 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
||||
// Each Zabbix data source instance should initialize its own API instance.
|
||||
|
||||
/** @ngInject */
|
||||
function ZabbixFactory(zabbixAPIService, ZabbixCachingProxy) {
|
||||
function ZabbixFactory(zabbixAPIService, ZabbixCachingProxy, ZabbixDBConnector) {
|
||||
var Zabbix = function () {
|
||||
function Zabbix(url, username, password, basicAuth, withCredentials, cacheTTL) {
|
||||
function Zabbix(url, options) {
|
||||
_classCallCheck(this, Zabbix);
|
||||
|
||||
var username = options.username,
|
||||
password = options.password,
|
||||
basicAuth = options.basicAuth,
|
||||
withCredentials = options.withCredentials,
|
||||
cacheTTL = options.cacheTTL,
|
||||
enableDirectDBConnection = options.enableDirectDBConnection,
|
||||
sqlDatasourceId = options.sqlDatasourceId;
|
||||
|
||||
// Initialize Zabbix API
|
||||
|
||||
var ZabbixAPI = zabbixAPIService;
|
||||
this.zabbixAPI = new ZabbixAPI(url, username, password, basicAuth, withCredentials);
|
||||
|
||||
if (enableDirectDBConnection) {
|
||||
this.dbConnector = new ZabbixDBConnector(sqlDatasourceId);
|
||||
}
|
||||
|
||||
// Initialize caching proxy for requests
|
||||
var cacheOptions = {
|
||||
enabled: true,
|
||||
ttl: cacheTTL
|
||||
};
|
||||
this.cachingProxy = new ZabbixCachingProxy(this.zabbixAPI, cacheOptions);
|
||||
this.cachingProxy = new ZabbixCachingProxy(this.zabbixAPI, this.dbConnector, cacheOptions);
|
||||
|
||||
// Proxy methods
|
||||
this.getHistory = this.cachingProxy.getHistory.bind(this.cachingProxy);
|
||||
this.getMacros = this.cachingProxy.getMacros.bind(this.cachingProxy);
|
||||
this.getItemsByIDs = this.cachingProxy.getItemsByIDs.bind(this.cachingProxy);
|
||||
|
||||
if (enableDirectDBConnection) {
|
||||
this.getHistoryDB = this.cachingProxy.getHistoryDB.bind(this.cachingProxy);
|
||||
this.getTrendsDB = this.cachingProxy.getTrendsDB.bind(this.cachingProxy);
|
||||
}
|
||||
|
||||
this.getTrend = this.zabbixAPI.getTrend.bind(this.zabbixAPI);
|
||||
this.getEvents = this.zabbixAPI.getEvents.bind(this.zabbixAPI);
|
||||
@@ -181,6 +202,13 @@ function ZabbixFactory(zabbixAPIService, ZabbixCachingProxy) {
|
||||
return filterByQuery(items, itemFilter);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'getITServices',
|
||||
value: function getITServices(itServiceFilter) {
|
||||
return this.cachingProxy.getITServices().then(function (itServices) {
|
||||
return findByFilter(itServices, itServiceFilter);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Build query - convert target filters to array of Zabbix items
|
||||
|
||||
21
dist/test/datasource-zabbix/zabbixAPI.service.js
vendored
21
dist/test/datasource-zabbix/zabbixAPI.service.js
vendored
@@ -217,16 +217,19 @@ function ZabbixAPIServiceFactory(alertSrv, zabbixAPICoreService) {
|
||||
params.filter.value_type = [1, 2, 4];
|
||||
}
|
||||
|
||||
return this.request('item.get', params).then(expandItems);
|
||||
return this.request('item.get', params).then(utils.expandItems);
|
||||
}
|
||||
}, {
|
||||
key: 'getItemsByIDs',
|
||||
value: function getItemsByIDs(itemids) {
|
||||
var params = {
|
||||
itemids: itemids,
|
||||
output: ['name', 'key_', 'value_type', 'hostid', 'status', 'state'],
|
||||
webitems: true,
|
||||
selectHosts: ['hostid', 'name']
|
||||
};
|
||||
|
||||
function expandItems(items) {
|
||||
_lodash2.default.forEach(items, function (item) {
|
||||
item.item = item.name;
|
||||
item.name = utils.expandItemName(item.item, item.key_);
|
||||
return item;
|
||||
});
|
||||
return items;
|
||||
}
|
||||
return this.request('item.get', params).then(utils.expandItems);
|
||||
}
|
||||
}, {
|
||||
key: 'getMacros',
|
||||
|
||||
@@ -22,10 +22,11 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
|
||||
/** @ngInject */
|
||||
function ZabbixCachingProxyFactory() {
|
||||
var ZabbixCachingProxy = function () {
|
||||
function ZabbixCachingProxy(zabbixAPI, cacheOptions) {
|
||||
function ZabbixCachingProxy(zabbixAPI, zabbixDBConnector, cacheOptions) {
|
||||
_classCallCheck(this, ZabbixCachingProxy);
|
||||
|
||||
this.zabbixAPI = zabbixAPI;
|
||||
this.dbConnector = zabbixDBConnector;
|
||||
this.cacheEnabled = cacheOptions.enabled;
|
||||
this.ttl = cacheOptions.ttl || 600000; // 10 minutes by default
|
||||
|
||||
@@ -38,7 +39,8 @@ function ZabbixCachingProxyFactory() {
|
||||
history: {},
|
||||
trends: {},
|
||||
macros: {},
|
||||
globalMacros: {}
|
||||
globalMacros: {},
|
||||
itServices: {}
|
||||
};
|
||||
|
||||
this.historyPromises = {};
|
||||
@@ -46,6 +48,11 @@ function ZabbixCachingProxyFactory() {
|
||||
// Don't run duplicated history requests
|
||||
this.getHistory = callAPIRequestOnce(_lodash2.default.bind(this.zabbixAPI.getHistory, this.zabbixAPI), this.historyPromises, getHistoryRequestHash);
|
||||
|
||||
if (this.dbConnector) {
|
||||
this.getHistoryDB = callAPIRequestOnce(_lodash2.default.bind(this.dbConnector.getHistory, this.dbConnector), this.historyPromises, getDBQueryHash);
|
||||
this.getTrendsDB = callAPIRequestOnce(_lodash2.default.bind(this.dbConnector.getTrends, this.dbConnector), this.historyPromises, getDBQueryHash);
|
||||
}
|
||||
|
||||
// Don't run duplicated requests
|
||||
this.groupPromises = {};
|
||||
this.getGroupsOnce = callAPIRequestOnce(_lodash2.default.bind(this.zabbixAPI.getGroups, this.zabbixAPI), this.groupPromises, getRequestHash);
|
||||
@@ -59,6 +66,12 @@ function ZabbixCachingProxyFactory() {
|
||||
this.itemPromises = {};
|
||||
this.getItemsOnce = callAPIRequestOnce(_lodash2.default.bind(this.zabbixAPI.getItems, this.zabbixAPI), this.itemPromises, getRequestHash);
|
||||
|
||||
this.itemByIdPromises = {};
|
||||
this.getItemsByIdOnce = callAPIRequestOnce(_lodash2.default.bind(this.zabbixAPI.getItemsByIDs, this.zabbixAPI), this.itemPromises, getRequestHash);
|
||||
|
||||
this.itServicesPromises = {};
|
||||
this.getITServicesOnce = callAPIRequestOnce(_lodash2.default.bind(this.zabbixAPI.getITService, this.zabbixAPI), this.itServicesPromises, getRequestHash);
|
||||
|
||||
this.macroPromises = {};
|
||||
this.getMacrosOnce = callAPIRequestOnce(_lodash2.default.bind(this.zabbixAPI.getMacros, this.zabbixAPI), this.macroPromises, getRequestHash);
|
||||
|
||||
@@ -119,6 +132,17 @@ function ZabbixCachingProxyFactory() {
|
||||
var params = [hostids, appids, itemtype];
|
||||
return this.proxyRequest(this.getItemsOnce, params, this.cache.items);
|
||||
}
|
||||
}, {
|
||||
key: 'getItemsByIDs',
|
||||
value: function getItemsByIDs(itemids) {
|
||||
var params = [itemids];
|
||||
return this.proxyRequest(this.getItemsByIdOnce, params, this.cache.items);
|
||||
}
|
||||
}, {
|
||||
key: 'getITServices',
|
||||
value: function getITServices() {
|
||||
return this.proxyRequest(this.getITServicesOnce, [], this.cache.itServices);
|
||||
}
|
||||
}, {
|
||||
key: 'getMacros',
|
||||
value: function getMacros(hostids) {
|
||||
@@ -210,6 +234,14 @@ function getHistoryRequestHash(args) {
|
||||
return stamp.getHash();
|
||||
}
|
||||
|
||||
function getDBQueryHash(args) {
|
||||
var itemids = _lodash2.default.map(args[0], 'itemid');
|
||||
var consolidateBy = args[3].consolidateBy;
|
||||
var intervalMs = args[3].intervalMs;
|
||||
var stamp = itemids.join() + args[1] + args[2] + consolidateBy + intervalMs;
|
||||
return stamp.getHash();
|
||||
}
|
||||
|
||||
String.prototype.getHash = function () {
|
||||
var hash = 0,
|
||||
i,
|
||||
|
||||
217
dist/test/datasource-zabbix/zabbixDBConnector.js
vendored
Normal file
217
dist/test/datasource-zabbix/zabbixDBConnector.js
vendored
Normal file
@@ -0,0 +1,217 @@
|
||||
'use strict';
|
||||
|
||||
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 _angular = require('angular');
|
||||
|
||||
var _angular2 = _interopRequireDefault(_angular);
|
||||
|
||||
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 DEFAULT_QUERY_LIMIT = 10000;
|
||||
var HISTORY_TO_TABLE_MAP = {
|
||||
'0': 'history',
|
||||
'1': 'history_str',
|
||||
'2': 'history_log',
|
||||
'3': 'history_uint',
|
||||
'4': 'history_text'
|
||||
};
|
||||
|
||||
var TREND_TO_TABLE_MAP = {
|
||||
'0': 'trends',
|
||||
'3': 'trends_uint'
|
||||
};
|
||||
|
||||
var consolidateByFunc = {
|
||||
'avg': 'AVG',
|
||||
'min': 'MIN',
|
||||
'max': 'MAX',
|
||||
'sum': 'SUM',
|
||||
'count': 'COUNT'
|
||||
};
|
||||
|
||||
var consolidateByTrendColumns = {
|
||||
'avg': 'value_avg',
|
||||
'min': 'value_min',
|
||||
'max': 'value_max'
|
||||
};
|
||||
|
||||
/** @ngInject */
|
||||
function ZabbixDBConnectorFactory(datasourceSrv, backendSrv) {
|
||||
var ZabbixDBConnector = function () {
|
||||
function ZabbixDBConnector(sqlDataSourceId) {
|
||||
var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
|
||||
_classCallCheck(this, ZabbixDBConnector);
|
||||
|
||||
var limit = options.limit;
|
||||
|
||||
|
||||
this.sqlDataSourceId = sqlDataSourceId;
|
||||
this.limit = limit || DEFAULT_QUERY_LIMIT;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
var ds = _lodash2.default.find(datasourceSrv.getAll(), { 'id': datasourceId });
|
||||
if (ds) {
|
||||
return datasourceSrv.loadDatasource(ds.name).then(function (ds) {
|
||||
console.log('SQL data source loaded', ds);
|
||||
});
|
||||
} else {
|
||||
return Promise.reject('SQL Data Source with ID ' + datasourceId + ' not found');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to invoke test query for one of Zabbix database tables.
|
||||
*/
|
||||
|
||||
}, {
|
||||
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) {
|
||||
var _this = this;
|
||||
|
||||
var intervalMs = options.intervalMs,
|
||||
consolidateBy = options.consolidateBy;
|
||||
|
||||
var intervalSec = Math.ceil(intervalMs / 1000);
|
||||
|
||||
consolidateBy = consolidateBy || 'avg';
|
||||
var aggFunction = consolidateByFunc[consolidateBy];
|
||||
|
||||
// Group items by value type and perform request for each value type
|
||||
var grouped_items = _lodash2.default.groupBy(items, 'value_type');
|
||||
var promises = _lodash2.default.map(grouped_items, function (items, value_type) {
|
||||
var itemids = _lodash2.default.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 ';
|
||||
|
||||
query = compactSQLQuery(query);
|
||||
return _this.invokeSQLQuery(query);
|
||||
});
|
||||
|
||||
return Promise.all(promises).then(function (results) {
|
||||
return _lodash2.default.flatten(results);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'getTrends',
|
||||
value: function getTrends(items, timeFrom, timeTill, options) {
|
||||
var _this2 = this;
|
||||
|
||||
var intervalMs = options.intervalMs,
|
||||
consolidateBy = options.consolidateBy;
|
||||
|
||||
var intervalSec = Math.ceil(intervalMs / 1000);
|
||||
|
||||
consolidateBy = consolidateBy || 'avg';
|
||||
var aggFunction = consolidateByFunc[consolidateBy];
|
||||
|
||||
// Group items by value type and perform request for each value type
|
||||
var grouped_items = _lodash2.default.groupBy(items, 'value_type');
|
||||
var promises = _lodash2.default.map(grouped_items, function (items, value_type) {
|
||||
var itemids = _lodash2.default.map(items, 'itemid').join(', ');
|
||||
var table = TREND_TO_TABLE_MAP[value_type];
|
||||
var valueColumn = _lodash2.default.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 ';
|
||||
|
||||
query = compactSQLQuery(query);
|
||||
return _this2.invokeSQLQuery(query);
|
||||
});
|
||||
|
||||
return Promise.all(promises).then(function (results) {
|
||||
return _lodash2.default.flatten(results);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: 'handleGrafanaTSResponse',
|
||||
value: function handleGrafanaTSResponse(history, items) {
|
||||
var addHostName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
||||
|
||||
return convertGrafanaTSResponse(history, items, addHostName);
|
||||
}
|
||||
}, {
|
||||
key: 'invokeSQLQuery',
|
||||
value: function invokeSQLQuery(query) {
|
||||
var queryDef = {
|
||||
refId: 'A',
|
||||
format: 'time_series',
|
||||
datasourceId: this.sqlDataSourceId,
|
||||
rawSql: query,
|
||||
maxDataPoints: this.limit
|
||||
};
|
||||
|
||||
return backendSrv.datasourceRequest({
|
||||
url: '/api/tsdb/query',
|
||||
method: 'POST',
|
||||
data: {
|
||||
queries: [queryDef]
|
||||
}
|
||||
}).then(function (response) {
|
||||
var results = response.data.results;
|
||||
if (results['A']) {
|
||||
return results['A'].series;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
||||
return ZabbixDBConnector;
|
||||
}();
|
||||
|
||||
return ZabbixDBConnector;
|
||||
}
|
||||
|
||||
_angular2.default.module('grafana.services').factory('ZabbixDBConnector', ZabbixDBConnectorFactory);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function convertGrafanaTSResponse(time_series, items, addHostName) {
|
||||
var hosts = _lodash2.default.uniqBy(_lodash2.default.flatten(_lodash2.default.map(items, 'hosts')), 'hostid'); //uniqBy is needed to deduplicate
|
||||
var grafanaSeries = _lodash2.default.map(time_series, function (series) {
|
||||
var itemid = series.name;
|
||||
var datapoints = series.points;
|
||||
var item = _lodash2.default.find(items, { 'itemid': itemid });
|
||||
var alias = item.name;
|
||||
if (_lodash2.default.keys(hosts).length > 1 && addHostName) {
|
||||
//only when actual multi hosts selected
|
||||
var host = _lodash2.default.find(hosts, { 'hostid': item.hostid });
|
||||
alias = host.name + ": " + alias;
|
||||
}
|
||||
return {
|
||||
target: alias,
|
||||
datapoints: datapoints
|
||||
};
|
||||
});
|
||||
|
||||
return _lodash2.default.sortBy(grafanaSeries, 'target');
|
||||
}
|
||||
|
||||
function compactSQLQuery(query) {
|
||||
return query.replace(/\s+/g, ' ');
|
||||
}
|
||||
10
dist/test/panel-triggers/module.js
vendored
10
dist/test/panel-triggers/module.js
vendored
@@ -165,6 +165,7 @@ var TriggerPanelCtrl = function (_PanelCtrl) {
|
||||
return this.datasourceSrv.get(this.panel.datasource).then(function (datasource) {
|
||||
var zabbix = datasource.zabbix;
|
||||
_this3.zabbix = zabbix;
|
||||
_this3.datasource = datasource;
|
||||
var showEvents = _this3.panel.showEvents.value;
|
||||
var triggerFilter = _this3.panel.triggers;
|
||||
var hideHostsInMaintenance = _this3.panel.hideHostsInMaintenance;
|
||||
@@ -178,10 +179,10 @@ var TriggerPanelCtrl = function (_PanelCtrl) {
|
||||
showTriggers: showEvents,
|
||||
hideHostsInMaintenance: hideHostsInMaintenance
|
||||
};
|
||||
var getTriggers = zabbix.getTriggers(groupFilter, hostFilter, appFilter, triggersOptions);
|
||||
return getTriggers.then(function (triggers) {
|
||||
return _lodash2.default.map(triggers, _this3.formatTrigger.bind(_this3));
|
||||
});
|
||||
|
||||
return zabbix.getTriggers(groupFilter, hostFilter, appFilter, triggersOptions);
|
||||
}).then(function (triggers) {
|
||||
return _lodash2.default.map(triggers, _this3.formatTrigger.bind(_this3));
|
||||
});
|
||||
}
|
||||
}, {
|
||||
@@ -231,6 +232,7 @@ var TriggerPanelCtrl = function (_PanelCtrl) {
|
||||
|
||||
// Filter triggers by description
|
||||
var triggerFilter = this.panel.triggers.trigger.filter;
|
||||
triggerFilter = this.datasource.replaceTemplateVars(triggerFilter);
|
||||
if (triggerFilter) {
|
||||
triggerList = _filterTriggers(triggerList, triggerFilter);
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ pages:
|
||||
- Installation:
|
||||
- 'Installation': 'installation/index.md'
|
||||
- 'Configuration': 'installation/configuration.md'
|
||||
- 'SQL Data Source Configuration': 'installation/configuration-sql.md'
|
||||
- 'Upgrade': 'installation/upgrade.md'
|
||||
- 'Troubleshooting': 'installation/troubleshooting.md'
|
||||
- User Guides:
|
||||
@@ -28,5 +29,6 @@ pages:
|
||||
- 'Triggers Panel': 'reference/panel-triggers.md'
|
||||
- 'Functions': 'reference/functions.md'
|
||||
- 'Alerting': 'reference/alerting.md'
|
||||
- 'Direct DB Connection': 'reference/direct-db-connection.md'
|
||||
# - Tutorials:
|
||||
# - 'Building Host Dashboard': 'tutorials/host_dashboard.md'
|
||||
|
||||
@@ -6,6 +6,12 @@ page_description: Grafana-Zabbix Feature Highlights.
|
||||
Grafana in couple with Grafana-Zabbix plugin allows to create great dashboards. There is some
|
||||
features:
|
||||
|
||||
- Rich graphing with Grafana
|
||||
- Template variables allow to create reusable dashboards
|
||||
|
||||
- Rich graphing features
|
||||
- Create interactive and reusable dashboards with [template variables](http://docs.grafana-zabbix.org/guides/templating/)
|
||||
- Show events on graphs with [Annotations](http://docs.grafana.org/reference/annotations/)
|
||||
- Select multiple metrics [by using Regex](http://docs.grafana-zabbix.org/guides/gettingstarted/#multiple-items-on-one-graph)
|
||||
- Display active problems with Triggers panel
|
||||
- Transform and shape your data with [metric processing functions](http://docs.grafana-zabbix.org/reference/functions/) (Avg, Median, Min, Max, Multiply, Summarize, Time shift, Alias)
|
||||
- Find problems faster with [Alerting](http://docs.grafana-zabbix.org/reference/alerting/) feature
|
||||
- Mix metrics from multiple data sources in the same dashboard or even graph
|
||||
- Discover and share [dashboards](https://grafana.com/dashboards) in the official library
|
||||
|
||||
1
docs/sources/img/.gitattributes
vendored
1
docs/sources/img/.gitattributes
vendored
@@ -1,3 +1,4 @@
|
||||
*.png filter=lfs diff=lfs merge=lfs -text
|
||||
*.jpg filter=lfs diff=lfs merge=lfs -text
|
||||
*.psd filter=lfs diff=lfs merge=lfs -text
|
||||
*.svg filter=lfs diff=lfs merge=lfs -text
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:6b58742637f58519a5fab038db0c15b5525d1d330fe5e4a1de954b72f4f1cc3e
|
||||
size 225446
|
||||
oid sha256:367b5fa51e9d05eb87afedd4ef6ed8ea1ce0e095f94bfdc58ebe6744fbaca71c
|
||||
size 131343
|
||||
|
||||
3
docs/sources/img/installation-mysql_ds_config.png
Normal file
3
docs/sources/img/installation-mysql_ds_config.png
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:0bac25f3d28c74f1f309476120bc67275e15f420e3343f0ff9668ead3a1e6170
|
||||
size 227988
|
||||
3
docs/sources/img/reference-direct-db-connection.svg
Normal file
3
docs/sources/img/reference-direct-db-connection.svg
Normal file
@@ -0,0 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:f0b942ebdeec31f98ae800c78223fb96ec077e8396e2f33a71e29d4d6d096661
|
||||
size 200108
|
||||
22
docs/sources/installation/configuration-sql.md
Normal file
22
docs/sources/installation/configuration-sql.md
Normal file
@@ -0,0 +1,22 @@
|
||||
# SQL Data Source Configuration
|
||||
|
||||
In order to use _Direct DB Connection_ feature you should configure SQL data source first.
|
||||
|
||||

|
||||
|
||||
Select _MySQL_ data source type and provide your database host address and port (3306 is default for MySQL). Fill
|
||||
database name (usually, `zabbix`) and specify credentials.
|
||||
|
||||
## Security notes
|
||||
|
||||
As you can see in _User Permission_ note, Grafana doesn't restrict any queries to the database. So you should be careful
|
||||
and create a special user with limited access to Zabbix database. Grafana-Zabbix plugin uses only `SELECT` queries to
|
||||
`history`, `history_uint`, `trends` and `trends_uint` tables. So it's reasonable to grant only SELECT privileges to
|
||||
these tables for grafana user. But if you want to use this MySQL data source for querying another data, you can
|
||||
grant SELECT privileges to entire zabbix database.
|
||||
|
||||
Also, all queries are invoked by grafana-server, so you can restrict connection to only grafana host.
|
||||
|
||||
```sql
|
||||
GRANT SELECT ON zabbix.* TO 'grafana'@'grafana-host' identified by 'password';
|
||||
```
|
||||
@@ -52,7 +52,23 @@ Direct access is still supported because in some cases it may be useful to acces
|
||||
- **Cache TTL**: plugin caches some api requests for increasing performance. Set this
|
||||
value to desired cache lifetime (this option affect data like items list).
|
||||
|
||||
### Direct DB Connection
|
||||
|
||||
Direct DB Connection allows plugin to use existing SQL data source for querying history data directly from Zabbix
|
||||
database. This way usually faster than pulling data from Zabbix API, especially on the wide time ranges, and reduces
|
||||
amount of data transfered.
|
||||
|
||||
Read [how to configure](/installation/configuration-sql) SQL data source in Grafana.
|
||||
|
||||
- **Enable**: enable Direct DB Connection.
|
||||
- **SQL Data Source**: Select SQL Data Source for Zabbix database.
|
||||
|
||||
#### Supported databases
|
||||
|
||||
Now only **MySQL** is supported by Grafana.
|
||||
|
||||
### Alerting
|
||||
|
||||
- **Enable alerting**: enable limited alerting support.
|
||||
- **Add thresholds**: get thresholds info from zabbix triggers and add it to graphs.
|
||||
For example, if you have trigger `{Zabbix server:system.cpu.util[,iowait].avg(5m)}>20`, threshold will be set to 20.
|
||||
@@ -65,10 +81,12 @@ or password, wrong api url.
|
||||

|
||||
|
||||
## Import example dashboards
|
||||
|
||||
You can import dashboard examples from _Dashboards_ tab in plugin config.
|
||||

|
||||
|
||||
## Note about Zabbix 2.2 or less
|
||||
|
||||
Zabbix API (api_jsonrpc.php) before zabbix 2.4 don't allow cross-domain requests (CORS). And you
|
||||
can get HTTP error 412 (Precondition Failed).
|
||||
To fix it add this code to api_jsonrpc.php immediately after the copyright:
|
||||
@@ -83,17 +101,20 @@ if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
|
||||
return;
|
||||
}
|
||||
```
|
||||
|
||||
before
|
||||
|
||||
```php
|
||||
require_once dirname(__FILE__).'/include/func.inc.php';
|
||||
require_once dirname(__FILE__).'/include/classes/core/CHttpRequest.php';
|
||||
```
|
||||
|
||||
[Full fix listing](https://gist.github.com/alexanderzobnin/f2348f318d7a93466a0c).
|
||||
For more details see zabbix issues [ZBXNEXT-1377](https://support.zabbix.com/browse/ZBXNEXT-1377)
|
||||
and [ZBX-8459](https://support.zabbix.com/browse/ZBX-8459).
|
||||
|
||||
## Note about Browser Cache
|
||||
|
||||
After updating plugin, clear browser cache and reload application page. See details
|
||||
for [Chrome](https://support.google.com/chrome/answer/95582),
|
||||
[Firefox](https://support.mozilla.org/en-US/kb/how-clear-firefox-cache). You need to clear cache
|
||||
|
||||
51
docs/sources/reference/direct-db-connection.md
Normal file
51
docs/sources/reference/direct-db-connection.md
Normal file
@@ -0,0 +1,51 @@
|
||||
# Direct DB Connection
|
||||
|
||||
Since version 4.3 Grafana has MySQL data source, Grafana-Zabbix plugin can use it for querying data directly from
|
||||
Zabbix database.
|
||||
|
||||
One of the most hard queries for Zabbix API is history queries. For long time intervals `history.get`
|
||||
returns huge amount of data. In order to display it, plugin should adjust time series resolution
|
||||
by using [consolidateBy](/reference/functions/#consolidateby) function. Ultimately, Grafana displays this reduced
|
||||
time series, but that data should be loaded and processed on the client side first. Direct DB Connection solves this
|
||||
two problems by moving consolidation to the server side. Thus, client get ready-to-use dataset which has much smaller
|
||||
size. Data loads faster and client doesn't spend time for data processing.
|
||||
|
||||
Also, many users point better performance of direct database queries versus API calls. This caused by several reasons,
|
||||
such as additional PHP layer and additional SQL queries (user permissions checks).
|
||||
|
||||
## Data Flow
|
||||
|
||||
This chart illustrates how plugin uses both Zabbix API and MySQL data source for querying different types
|
||||
of data from Zabbix. MySQL data source is used only for pulling history and trend data instead of `history.get`
|
||||
and `trend.get` API calls.
|
||||
|
||||
[](../img/reference-direct-db-connection.svg)
|
||||
|
||||
## Query structure
|
||||
|
||||
Grafana-Zabbix uses queries like this for getting history:
|
||||
|
||||
```sql
|
||||
SELECT itemid AS metric, clock AS time_sec, {aggFunc}(value) as value
|
||||
FROM {historyTable}
|
||||
WHERE itemid IN ({itemids})
|
||||
AND clock > {timeFrom} AND clock < {timeTill}
|
||||
GROUP BY time_sec DIV {intervalSec}, metric
|
||||
```
|
||||
|
||||
where `{aggFunc}` is one of `[AVG, MIN, MAX, SUM, COUNT]` aggregation function, `{historyTable}` is a history table,
|
||||
`{intervalSec}` - consolidation interval in seconds.
|
||||
|
||||
When getting trends, plugin additionally queries particular value column (`value_avg`, `value_min` or `value_max`)
|
||||
depends on `consolidateBy` function value:
|
||||
|
||||
```sql
|
||||
SELECT itemid AS metric, clock AS time_sec, {aggFunc}({valueColumn}) as value
|
||||
FROM {trendsTable}
|
||||
WHERE itemid IN ({itemids})
|
||||
AND clock > {timeFrom} AND clock < {timeTill}
|
||||
GROUP BY time_sec DIV {intervalSec}, metric
|
||||
```
|
||||
|
||||
As you can see, plugin uses aggregation by given time interval. This interval is provided by Grafana and depends on the
|
||||
panel with in pixels. Thus, Grafana always gets data in necessary resolution.
|
||||
@@ -197,3 +197,14 @@ replaceAlias(/.*CPU (.*) time/, $1) -> system
|
||||
backend01: CPU system time
|
||||
replaceAlias(/(.*): CPU (.*) time/, $1 - $2) -> backend01 - system
|
||||
```
|
||||
|
||||
## Special
|
||||
|
||||
### consolidateBy
|
||||
```
|
||||
consolidateBy(consolidationFunc)
|
||||
```
|
||||
|
||||
When a graph is drawn where width of the graph size in pixels is smaller than the number of datapoints to be graphed, plugin consolidates the values to to prevent line overlap. The consolidateBy() function changes the consolidation function from the default of average to one of `sum`, `min`, `max` or `count`.
|
||||
|
||||
Valid function names are `sum`, `avg`, `min`, `max` and `count`.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "grafana-zabbix",
|
||||
"private": false,
|
||||
"version": "3.2.0",
|
||||
"version": "3.5.1",
|
||||
"description": "Zabbix plugin for Grafana",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
|
||||
@@ -1,28 +1,22 @@
|
||||
## Zabbix plugin for Grafana
|
||||
# Zabbix plugin for Grafana
|
||||
|
||||
[](https://github.com/alexanderzobnin/grafana-zabbix/releases)
|
||||
[](https://github.com/alexanderzobnin/grafana-zabbix/blob/master/CHANGELOG.md)
|
||||
[](http://docs.grafana-zabbix.org)
|
||||
[](https://github.com/alexanderzobnin/grafana-zabbix/blob/master/LICENSE)
|
||||
|
||||
Zabbix plugin allows to show different type of data from [Zabbix](http://www.zabbix.com/)
|
||||
monitoring system.
|
||||
Visualize your Zabbix metrics with the leading open source software for time series analytics.
|
||||
|
||||
### Live Demo
|
||||
|
||||
Check out the [live demo](http://play.grafana-zabbix.org/) with dashboard examples.
|
||||
See all features overview and dashboards examples at Grafana-Zabbix [Live demo](http://play.grafana-zabbix.org) site.
|
||||
|
||||
### Features
|
||||
|
||||
#### Flexible metric editor
|
||||
* Regex-based metric filtering
|
||||
* Client-side data processing functions
|
||||
* Template variables support
|
||||
|
||||
#### Templated dashboards support
|
||||
Group, host, application or item names can be replaced with a template variable. This allows you to create generic dashboards that can quickly be changed to show stats for a specific cluster, server or application.
|
||||
|
||||
#### Annotations support
|
||||
* Display zabbix events on graphs
|
||||
* Show acknowledges for problems
|
||||
|
||||
#### Triggers panel
|
||||
Panel for showing Zabbix triggers (like Last 20 issues) with some customizable features.
|
||||
- Select multiple metrics [by using Regex](http://docs.grafana-zabbix.org/guides/gettingstarted/#multiple-items-on-one-graph)
|
||||
- Create interactive and reusable dashboards with [template variables](http://docs.grafana-zabbix.org/guides/templating/)
|
||||
- Show events on graphs with [Annotations](http://docs.grafana.org/reference/annotations/)
|
||||
- Display active problems with Triggers panel
|
||||
- Transform and shape your data with [metric processing functions](http://docs.grafana-zabbix.org/reference/functions/) (Avg, Median, Min, Max, Multiply, Summarize, Time shift, Alias)
|
||||
- Find problems faster with [Alerting](http://docs.grafana-zabbix.org/reference/alerting/) feature
|
||||
- Mix metrics from multiple data sources in the same dashboard or even graph
|
||||
- Discover and share [dashboards](https://grafana.com/dashboards) in the official library
|
||||
|
||||
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';
|
||||
@@ -1,7 +1,8 @@
|
||||
// Editor modes
|
||||
export const MODE_METRICS = 0;
|
||||
export const MODE_TEXT = 2;
|
||||
export const MODE_ITSERVICE = 1;
|
||||
export const MODE_TEXT = 2;
|
||||
export const MODE_ITEMID = 3;
|
||||
|
||||
// Triggers severity
|
||||
export const SEV_NOT_CLASSIFIED = 0;
|
||||
|
||||
@@ -19,6 +19,9 @@ class ZabbixAPIDatasource {
|
||||
this.dashboardSrv = dashboardSrv;
|
||||
this.zabbixAlertingSrv = zabbixAlertingSrv;
|
||||
|
||||
// Use custom format for template variables
|
||||
this.replaceTemplateVars = _.partial(replaceTemplateVars, this.templateSrv);
|
||||
|
||||
// General data source settings
|
||||
this.name = instanceSettings.name;
|
||||
this.url = instanceSettings.url;
|
||||
@@ -43,10 +46,21 @@ class ZabbixAPIDatasource {
|
||||
this.addThresholds = instanceSettings.jsonData.addThresholds;
|
||||
this.alertingMinSeverity = instanceSettings.jsonData.alertingMinSeverity || c.SEV_WARNING;
|
||||
|
||||
this.zabbix = new Zabbix(this.url, this.username, this.password, this.basicAuth, this.withCredentials, this.cacheTTL);
|
||||
// Direct DB Connection options
|
||||
this.enableDirectDBConnection = instanceSettings.jsonData.dbConnection.enable;
|
||||
this.sqlDatasourceId = instanceSettings.jsonData.dbConnection.datasourceId;
|
||||
|
||||
// Use custom format for template variables
|
||||
this.replaceTemplateVars = _.partial(replaceTemplateVars, this.templateSrv);
|
||||
let zabbixOptions = {
|
||||
username: this.username,
|
||||
password: this.password,
|
||||
basicAuth: this.basicAuth,
|
||||
withCredentials: this.withCredentials,
|
||||
cacheTTL: this.cacheTTL,
|
||||
enableDirectDBConnection: this.enableDirectDBConnection,
|
||||
sqlDatasourceId: this.sqlDatasourceId
|
||||
};
|
||||
|
||||
this.zabbix = new Zabbix(this.url, zabbixOptions);
|
||||
}
|
||||
|
||||
////////////////////////
|
||||
@@ -75,6 +89,11 @@ class ZabbixAPIDatasource {
|
||||
|
||||
// Create request for each target
|
||||
let promises = _.map(options.targets, t => {
|
||||
// Don't request undefined and hidden targets
|
||||
if (t.hide) {
|
||||
return [];
|
||||
}
|
||||
|
||||
let timeFrom = Math.ceil(dateMath.parse(options.range.from) / 1000);
|
||||
let timeTo = Math.ceil(dateMath.parse(options.range.to) / 1000);
|
||||
|
||||
@@ -94,7 +113,7 @@ class ZabbixAPIDatasource {
|
||||
let useTrends = this.isUseTrends(timeRange);
|
||||
|
||||
// Metrics or Text query mode
|
||||
if (target.mode !== c.MODE_ITSERVICE) {
|
||||
if (target.mode === c.MODE_METRICS || target.mode === c.MODE_TEXT || target.mode === c.MODE_ITEMID) {
|
||||
// Migrate old targets
|
||||
target = migrations.migrate(target);
|
||||
|
||||
@@ -107,20 +126,12 @@ class ZabbixAPIDatasource {
|
||||
return this.queryNumericData(target, timeRange, useTrends, options);
|
||||
} else if (target.mode === c.MODE_TEXT) {
|
||||
return this.queryTextData(target, timeRange);
|
||||
} else if (target.mode === c.MODE_ITEMID) {
|
||||
return this.queryItemIdData(target, timeRange, useTrends, options);
|
||||
}
|
||||
}
|
||||
|
||||
// IT services mode
|
||||
else if (target.mode === c.MODE_ITSERVICE) {
|
||||
// Don't show undefined and hidden targets
|
||||
if (target.hide || !target.itservice || !target.slaProperty) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return this.zabbix.getSLA(target.itservice.serviceid, timeRange)
|
||||
.then(slaObject => {
|
||||
return responseHandler.handleSLAResponse(target.itservice, target.slaProperty, slaObject);
|
||||
});
|
||||
} else if (target.mode === c.MODE_ITSERVICE) {
|
||||
// IT services mode
|
||||
return this.queryITServiceData(target, timeRange, options);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -132,39 +143,55 @@ class ZabbixAPIDatasource {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Query target data for Metrics mode
|
||||
*/
|
||||
queryNumericData(target, timeRange, useTrends, options) {
|
||||
let [timeFrom, timeTo] = timeRange;
|
||||
let getItemOptions = {
|
||||
itemtype: 'num'
|
||||
};
|
||||
return this.zabbix.getItemsFromTarget(target, getItemOptions)
|
||||
.then(items => {
|
||||
let getHistoryPromise;
|
||||
return this.queryNumericDataForItems(items, target, timeRange, useTrends, options);
|
||||
});
|
||||
}
|
||||
|
||||
if (useTrends) {
|
||||
/**
|
||||
* Query history for numeric items
|
||||
*/
|
||||
queryNumericDataForItems(items, target, timeRange, useTrends, options) {
|
||||
let [timeFrom, timeTo] = timeRange;
|
||||
let getHistoryPromise;
|
||||
options.consolidateBy = getConsolidateBy(target);
|
||||
|
||||
if (useTrends) {
|
||||
if (this.enableDirectDBConnection) {
|
||||
getHistoryPromise = this.zabbix.getTrendsDB(items, timeFrom, timeTo, options)
|
||||
.then(history => this.zabbix.dbConnector.handleGrafanaTSResponse(history, items));
|
||||
} else {
|
||||
let valueType = this.getTrendValueType(target);
|
||||
getHistoryPromise = this.zabbix.getTrend(items, timeFrom, timeTo)
|
||||
.then(history => {
|
||||
return responseHandler.handleTrends(history, items, valueType);
|
||||
})
|
||||
.then(history => responseHandler.handleTrends(history, items, valueType))
|
||||
.then(timeseries => {
|
||||
// Sort trend data, issue #202
|
||||
_.forEach(timeseries, series => {
|
||||
series.datapoints = _.sortBy(series.datapoints, point => point[c.DATAPOINT_TS]);
|
||||
});
|
||||
|
||||
return timeseries;
|
||||
});
|
||||
} else {
|
||||
// Use history
|
||||
getHistoryPromise = this.zabbix.getHistory(items, timeFrom, timeTo)
|
||||
.then(history => {
|
||||
return responseHandler.handleHistory(history, items);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// Use history
|
||||
if (this.enableDirectDBConnection) {
|
||||
getHistoryPromise = this.zabbix.getHistoryDB(items, timeFrom, timeTo, options)
|
||||
.then(history => this.zabbix.dbConnector.handleGrafanaTSResponse(history, items));
|
||||
} else {
|
||||
getHistoryPromise = this.zabbix.getHistory(items, timeFrom, timeTo)
|
||||
.then(history => responseHandler.handleHistory(history, items));
|
||||
}
|
||||
}
|
||||
|
||||
return getHistoryPromise;
|
||||
})
|
||||
return getHistoryPromise
|
||||
.then(timeseries => this.applyDataProcessingFunctions(timeseries, target))
|
||||
.then(timeseries => downsampleSeries(timeseries, options))
|
||||
.catch(error => {
|
||||
@@ -238,6 +265,9 @@ class ZabbixAPIDatasource {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Query target data for Text mode
|
||||
*/
|
||||
queryTextData(target, timeRange) {
|
||||
let [timeFrom, timeTo] = timeRange;
|
||||
let options = {
|
||||
@@ -256,6 +286,66 @@ class ZabbixAPIDatasource {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Query target data for Item ID mode
|
||||
*/
|
||||
queryItemIdData(target, timeRange, useTrends, options) {
|
||||
let itemids = target.itemids;
|
||||
itemids = this.templateSrv.replace(itemids, options.scopedVars, zabbixItemIdsTemplateFormat);
|
||||
itemids = _.map(itemids.split(','), itemid => itemid.trim());
|
||||
|
||||
if (!itemids) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return this.zabbix.getItemsByIDs(itemids)
|
||||
.then(items => {
|
||||
return this.queryNumericDataForItems(items, target, timeRange, useTrends, options);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Query target data for IT Services mode
|
||||
*/
|
||||
queryITServiceData(target, timeRange, options) {
|
||||
// Don't show undefined and hidden targets
|
||||
if (target.hide || (!target.itservice && !target.itServiceFilter) || !target.slaProperty) {
|
||||
return [];
|
||||
}
|
||||
|
||||
let itServiceIds = [];
|
||||
let itServices = [];
|
||||
let itServiceFilter;
|
||||
let isOldVersion = target.itservice && !target.itServiceFilter;
|
||||
|
||||
if (isOldVersion) {
|
||||
// Backward compatibility
|
||||
itServiceFilter = '/.*/';
|
||||
} else {
|
||||
itServiceFilter = this.replaceTemplateVars(target.itServiceFilter, options.scopedVars);
|
||||
}
|
||||
|
||||
return this.zabbix.getITServices(itServiceFilter)
|
||||
.then(itservices => {
|
||||
itServices = itservices;
|
||||
if (isOldVersion) {
|
||||
itServices = _.filter(itServices, {'serviceid': target.itservice.serviceid});
|
||||
}
|
||||
|
||||
itServiceIds = _.map(itServices, 'serviceid');
|
||||
return itServiceIds;
|
||||
})
|
||||
.then(serviceids => {
|
||||
return this.zabbix.getSLA(serviceids, timeRange);
|
||||
})
|
||||
.then(slaResponse => {
|
||||
return _.map(itServiceIds, serviceid => {
|
||||
let itservice = _.find(itServices, {'serviceid': serviceid});
|
||||
return responseHandler.handleSLAResponse(itservice, target.slaProperty, slaResponse);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Test connection to Zabbix API
|
||||
* @return {object} Connection status and Zabbix API version
|
||||
@@ -267,6 +357,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",
|
||||
@@ -281,6 +378,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",
|
||||
@@ -367,13 +470,14 @@ class ZabbixAPIDatasource {
|
||||
return getTriggers.then(triggers => {
|
||||
|
||||
// Filter triggers by description
|
||||
if (utils.isRegex(annotation.trigger)) {
|
||||
let triggerName = this.replaceTemplateVars(annotation.trigger, {});
|
||||
if (utils.isRegex(triggerName)) {
|
||||
triggers = _.filter(triggers, trigger => {
|
||||
return utils.buildRegex(annotation.trigger).test(trigger.description);
|
||||
return utils.buildRegex(triggerName).test(trigger.description);
|
||||
});
|
||||
} else if (annotation.trigger) {
|
||||
} else if (triggerName) {
|
||||
triggers = _.filter(triggers, trigger => {
|
||||
return trigger.description === annotation.trigger;
|
||||
return trigger.description === triggerName;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -424,7 +528,9 @@ class ZabbixAPIDatasource {
|
||||
*/
|
||||
alertQuery(options) {
|
||||
let enabled_targets = filterEnabledTargets(options.targets);
|
||||
let getPanelItems = _.map(enabled_targets, target => {
|
||||
let getPanelItems = _.map(enabled_targets, t => {
|
||||
let target = _.cloneDeep(t);
|
||||
this.replaceTargetVariables(target, options);
|
||||
return this.zabbix.getItemsFromTarget(target, {itemtype: 'num'});
|
||||
});
|
||||
|
||||
@@ -508,11 +614,24 @@ function bindFunctionDefs(functionDefs, category) {
|
||||
});
|
||||
}
|
||||
|
||||
function getConsolidateBy(target) {
|
||||
let consolidateBy = 'avg';
|
||||
let funcDef = _.find(target.functions, func => {
|
||||
return func.def.name === 'consolidateBy';
|
||||
});
|
||||
if (funcDef && funcDef.params && funcDef.params.length) {
|
||||
consolidateBy = funcDef.params[0];
|
||||
}
|
||||
return consolidateBy;
|
||||
}
|
||||
|
||||
function downsampleSeries(timeseries_data, options) {
|
||||
let defaultAgg = dataProcessor.aggregationFunctions['avg'];
|
||||
let consolidateByFunc = dataProcessor.aggregationFunctions[options.consolidateBy] || defaultAgg;
|
||||
return _.map(timeseries_data, timeseries => {
|
||||
if (timeseries.datapoints.length > options.maxDataPoints) {
|
||||
timeseries.datapoints = dataProcessor
|
||||
.groupBy(options.interval, dataProcessor.AVERAGE, timeseries.datapoints);
|
||||
.groupBy(options.interval, consolidateByFunc, timeseries.datapoints);
|
||||
}
|
||||
return timeseries;
|
||||
});
|
||||
@@ -544,6 +663,13 @@ function zabbixTemplateFormat(value) {
|
||||
return '(' + escapedValues.join('|') + ')';
|
||||
}
|
||||
|
||||
function zabbixItemIdsTemplateFormat(value) {
|
||||
if (typeof value === 'string') {
|
||||
return value;
|
||||
}
|
||||
return value.join(',');
|
||||
}
|
||||
|
||||
/**
|
||||
* If template variables are used in request, replace it using regex format
|
||||
* and wrap with '/' for proper multi-value work. Example:
|
||||
|
||||
@@ -8,7 +8,8 @@ var categories = {
|
||||
Filter: [],
|
||||
Trends: [],
|
||||
Time: [],
|
||||
Alias: []
|
||||
Alias: [],
|
||||
Special: []
|
||||
};
|
||||
|
||||
function addFuncDef(funcDef) {
|
||||
@@ -222,6 +223,16 @@ addFuncDef({
|
||||
defaultParams: ['/(.*)/', '$1']
|
||||
});
|
||||
|
||||
// Special
|
||||
addFuncDef({
|
||||
name: 'consolidateBy',
|
||||
category: 'Special',
|
||||
params: [
|
||||
{ name: 'type', type: 'string', options: ['avg', 'min', 'max', 'sum', 'count'] }
|
||||
],
|
||||
defaultParams: ['avg'],
|
||||
});
|
||||
|
||||
_.each(categories, function(funcList, catName) {
|
||||
categories[catName] = _.sortBy(funcList, 'name');
|
||||
});
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import {ZabbixAPIDatasource} from './datasource';
|
||||
import {ZabbixQueryController} from './query.controller';
|
||||
|
||||
class ZabbixConfigController {}
|
||||
ZabbixConfigController.templateUrl = 'datasource-zabbix/partials/config.html';
|
||||
import {ZabbixDSConfigController} from './config.controller';
|
||||
|
||||
class ZabbixQueryOptionsController {}
|
||||
ZabbixQueryOptionsController.templateUrl = 'datasource-zabbix/partials/query.options.html';
|
||||
@@ -12,7 +10,7 @@ ZabbixAnnotationsQueryController.templateUrl = 'datasource-zabbix/partials/annot
|
||||
|
||||
export {
|
||||
ZabbixAPIDatasource as Datasource,
|
||||
ZabbixConfigController as ConfigCtrl,
|
||||
ZabbixDSConfigController as ConfigCtrl,
|
||||
ZabbixQueryController as QueryCtrl,
|
||||
ZabbixQueryOptionsController as QueryOptionsCtrl,
|
||||
ZabbixAnnotationsQueryController as AnnotationsQueryCtrl
|
||||
|
||||
@@ -76,24 +76,53 @@
|
||||
</div>
|
||||
|
||||
<div class="gf-form-group">
|
||||
<h3 class="page-heading">Alerting</h3>
|
||||
<gf-form-switch class="gf-form" label-class="width-9"
|
||||
label="Enable alerting"
|
||||
checked="ctrl.current.jsonData.alerting">
|
||||
<h3 class="page-heading">Direct DB Connection</h3>
|
||||
<gf-form-switch class="gf-form" label-class="width-12"
|
||||
label="Enable"
|
||||
checked="ctrl.current.jsonData.dbConnection.enable">
|
||||
</gf-form-switch>
|
||||
<gf-form-switch class="gf-form" label-class="width-9"
|
||||
label="Add thresholds"
|
||||
checked="ctrl.current.jsonData.addThresholds">
|
||||
</gf-form-switch>
|
||||
<div class="gf-form max-width-20">
|
||||
<span class="gf-form-label width-9">Min severity</span>
|
||||
<div ng-if="ctrl.current.jsonData.dbConnection.enable">
|
||||
<div class="gf-form max-width-20">
|
||||
<span class="gf-form-label width-12">
|
||||
SQL Data Source
|
||||
<info-popover mode="right-normal">
|
||||
Select SQL Data Source for Zabbix database.
|
||||
In order to use this feature you should <a href="/datasources/new" target="_blank">create</a> and
|
||||
configure it first. Zabbix plugin uses this data source for querying history data directly from database.
|
||||
This way usually faster than pulling data from Zabbix API, especially on the wide time ranges, and reduces
|
||||
amount of data transfered.
|
||||
</info-popover>
|
||||
</span>
|
||||
<div class="gf-form-select-wrapper max-width-16">
|
||||
<select class="gf-form-input" ng-model="ctrl.current.jsonData.alertingMinSeverity"
|
||||
ng-options="s.val as s.text for s in [
|
||||
{val: 0, text: 'Not classified'}, {val: 1, text:'Information'},
|
||||
{val: 2, text: 'Warning'}, {val: 3, text: 'Average'},
|
||||
{val: 4, text: 'High'}, {val: 5, text: 'Disaster'}]">
|
||||
<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">
|
||||
<h3 class="page-heading">Alerting</h3>
|
||||
<gf-form-switch class="gf-form" label-class="width-12"
|
||||
label="Enable alerting"
|
||||
checked="ctrl.current.jsonData.alerting">
|
||||
</gf-form-switch>
|
||||
<div ng-if="ctrl.current.jsonData.alerting">
|
||||
<gf-form-switch class="gf-form" label-class="width-12"
|
||||
label="Add thresholds"
|
||||
checked="ctrl.current.jsonData.addThresholds">
|
||||
</gf-form-switch>
|
||||
<div class="gf-form max-width-20">
|
||||
<span class="gf-form-label width-12">Min severity</span>
|
||||
<div class="gf-form-select-wrapper max-width-16">
|
||||
<select class="gf-form-input" ng-model="ctrl.current.jsonData.alertingMinSeverity"
|
||||
ng-options="s.val as s.text for s in [
|
||||
{val: 0, text: 'Not classified'}, {val: 1, text:'Information'},
|
||||
{val: 2, text: 'Warning'}, {val: 3, text: 'Average'},
|
||||
{val: 4, text: 'High'}, {val: 5, text: 'Disaster'}]">
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<select class="gf-form-input"
|
||||
ng-change="ctrl.switchEditorMode(ctrl.target.mode)"
|
||||
ng-model="ctrl.target.mode"
|
||||
ng-options="v.mode as v.text for (k, v) in ctrl.editorModes">
|
||||
ng-options="m.mode as m.text for m in ctrl.editorModes">
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
@@ -17,27 +17,29 @@
|
||||
</div>
|
||||
|
||||
<!-- IT Service editor -->
|
||||
<div class="gf-form-inline" ng-show="ctrl.target.mode == 1">
|
||||
<div class="gf-form-inline" ng-show="ctrl.target.mode == editorMode.ITSERVICE">
|
||||
<div class="gf-form max-width-20">
|
||||
<label class="gf-form-label query-keyword width-7">IT Service</label>
|
||||
<div class="gf-form-select-wrapper max-width-20">
|
||||
<select class="gf-form-input"
|
||||
ng-change="ctrl.selectITService()"
|
||||
ng-model="ctrl.target.itservice"
|
||||
bs-tooltip="ctrl.target.itservice.name.length > 25 ? ctrl.target.itservice.name : ''"
|
||||
ng-options="itservice.name for itservice in ctrl.itserviceList track by itservice.name">
|
||||
<option value="">-- Select IT service --</option>
|
||||
</select>
|
||||
</div>
|
||||
<input type="text"
|
||||
ng-model="ctrl.target.itServiceFilter"
|
||||
bs-typeahead="ctrl.getITServices"
|
||||
ng-blur="ctrl.onTargetBlur()"
|
||||
data-min-length=0
|
||||
data-items=100
|
||||
class="gf-form-input"
|
||||
ng-class="{
|
||||
'zbx-variable': ctrl.isVariable(ctrl.target.itServiceFilter),
|
||||
'zbx-regex': ctrl.isRegex(ctrl.target.itServiceFilter)
|
||||
}">
|
||||
</input>
|
||||
</div>
|
||||
<div class="gf-form">
|
||||
<label class="gf-form-label query-keyword">IT service property</label>
|
||||
<label class="gf-form-label query-keyword">Property</label>
|
||||
<div class="gf-form-select-wrapper">
|
||||
<select class="gf-form-input"
|
||||
ng-change="ctrl.selectITService()"
|
||||
ng-model="ctrl.target.slaProperty"
|
||||
ng-options="slaProperty.name for slaProperty in ctrl.slaPropertyList track by slaProperty.name">
|
||||
<option value="">-- Property --</option>
|
||||
ng-change="ctrl.onTargetBlur()"
|
||||
ng-model="ctrl.target.slaProperty"
|
||||
ng-options="slaProperty.name for slaProperty in ctrl.slaPropertyList track by slaProperty.name">
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
@@ -46,7 +48,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="gf-form-inline" ng-hide="ctrl.target.mode == 1">
|
||||
<div class="gf-form-inline" ng-show="ctrl.target.mode == editorMode.METRICS || ctrl.target.mode == editorMode.TEXT">
|
||||
<!-- Select Group -->
|
||||
<div class="gf-form max-width-20">
|
||||
<label class="gf-form-label query-keyword width-7">Group</label>
|
||||
@@ -83,7 +85,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="gf-form-inline" ng-hide="ctrl.target.mode == 1">
|
||||
<div class="gf-form-inline" ng-show="ctrl.target.mode == editorMode.METRICS || ctrl.target.mode == editorMode.TEXT">
|
||||
<!-- Select Application -->
|
||||
<div class="gf-form max-width-20">
|
||||
<label class="gf-form-label query-keyword width-7">Application</label>
|
||||
@@ -129,7 +131,7 @@
|
||||
<!-- Query options -->
|
||||
<div class="gf-form-group" ng-if="ctrl.showQueryOptions">
|
||||
<div class="gf-form offset-width-7">
|
||||
<gf-form-switch class="gf-form" ng-hide="ctrl.target.mode == 2"
|
||||
<gf-form-switch class="gf-form"
|
||||
label="Show disabled items"
|
||||
checked="ctrl.target.options.showDisabledItems"
|
||||
on-change="ctrl.onQueryOptionChange()">
|
||||
@@ -137,8 +139,30 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Item IDs editor mode -->
|
||||
<div class="gf-form-inline" ng-show="ctrl.target.mode == editorMode.ITEMID">
|
||||
<div class="gf-form max-width-20">
|
||||
<label class="gf-form-label query-keyword width-7">Item IDs</label>
|
||||
<input type="text"
|
||||
ng-model="ctrl.target.itemids"
|
||||
bs-typeahead="ctrl.getVariables"
|
||||
ng-blur="ctrl.onTargetBlur()"
|
||||
data-min-length=0
|
||||
data-items=100
|
||||
class="gf-form-input"
|
||||
ng-class="{
|
||||
'zbx-variable': ctrl.isVariable(ctrl.target.itServiceFilter),
|
||||
'zbx-regex': ctrl.isRegex(ctrl.target.itServiceFilter)
|
||||
}">
|
||||
</input>
|
||||
</div>
|
||||
<div class="gf-form gf-form--grow">
|
||||
<div class="gf-form-label gf-form-label--grow"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Metric processing functions -->
|
||||
<div class="gf-form-inline" ng-hide="ctrl.target.mode">
|
||||
<div class="gf-form-inline" ng-show="ctrl.target.mode == editorMode.METRICS || ctrl.target.mode == editorMode.ITEMID">
|
||||
<div class="gf-form">
|
||||
<label class="gf-form-label query-keyword width-7">Functions</label>
|
||||
<div ng-repeat="func in ctrl.target.functions" class="gf-form-label query-part" metric-function-editor></div>
|
||||
@@ -151,7 +175,7 @@
|
||||
</div>
|
||||
|
||||
<!-- Text mode options -->
|
||||
<div class="gf-form-inline" ng-show="ctrl.target.mode == 2">
|
||||
<div class="gf-form-inline" ng-show="ctrl.target.mode == editorMode.TEXT">
|
||||
<!-- Text metric regex -->
|
||||
<div class="gf-form max-width-20">
|
||||
<label class="gf-form-label query-keyword width-7">Text filter</label>
|
||||
@@ -165,6 +189,8 @@
|
||||
|
||||
<gf-form-switch class="gf-form" label="Use capture groups" checked="ctrl.target.useCaptureGroups" on-change="ctrl.onTargetBlur()">
|
||||
</gf-form-switch>
|
||||
<div class="gf-form gf-form--grow">
|
||||
<div class="gf-form-label gf-form-label--grow"></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</query-editor-row>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import {QueryCtrl} from 'app/plugins/sdk';
|
||||
import angular from 'angular';
|
||||
import _ from 'lodash';
|
||||
import * as c from './constants';
|
||||
import * as utils from './utils';
|
||||
@@ -22,17 +21,35 @@ export class ZabbixQueryController extends QueryCtrl {
|
||||
this.replaceTemplateVars = this.datasource.replaceTemplateVars;
|
||||
this.templateSrv = templateSrv;
|
||||
|
||||
this.editorModes = {
|
||||
0: {value: 'num', text: 'Metrics', mode: c.MODE_METRICS},
|
||||
1: {value: 'itservice', text: 'IT Services', mode: c.MODE_ITSERVICE},
|
||||
2: {value: 'text', text: 'Text', mode: c.MODE_TEXT}
|
||||
this.editorModes = [
|
||||
{value: 'num', text: 'Metrics', mode: c.MODE_METRICS},
|
||||
{value: 'text', text: 'Text', mode: c.MODE_TEXT},
|
||||
{value: 'itservice', text: 'IT Services', mode: c.MODE_ITSERVICE},
|
||||
{value: 'itemid', text: 'Item ID', mode: c.MODE_ITEMID}
|
||||
];
|
||||
|
||||
this.$scope.editorMode = {
|
||||
METRICS: c.MODE_METRICS,
|
||||
TEXT: c.MODE_TEXT,
|
||||
ITSERVICE: c.MODE_ITSERVICE,
|
||||
ITEMID: c.MODE_ITEMID
|
||||
};
|
||||
|
||||
this.slaPropertyList = [
|
||||
{name: "Status", property: "status"},
|
||||
{name: "SLA", property: "sla"},
|
||||
{name: "OK time", property: "okTime"},
|
||||
{name: "Problem time", property: "problemTime"},
|
||||
{name: "Down time", property: "downtimeTime"}
|
||||
];
|
||||
|
||||
// Map functions for bs-typeahead
|
||||
this.getGroupNames = _.bind(this.getMetricNames, this, 'groupList');
|
||||
this.getHostNames = _.bind(this.getMetricNames, this, 'hostList', true);
|
||||
this.getApplicationNames = _.bind(this.getMetricNames, this, 'appList');
|
||||
this.getItemNames = _.bind(this.getMetricNames, this, 'itemList');
|
||||
this.getITServices = _.bind(this.getMetricNames, this, 'itServiceList');
|
||||
this.getVariables = _.bind(this.getTemplateVariables, this);
|
||||
|
||||
// Update metric suggestion when template variable was changed
|
||||
$rootScope.$on('template-variable-value-updated', () => this.onVariableChange());
|
||||
@@ -57,14 +74,14 @@ export class ZabbixQueryController extends QueryCtrl {
|
||||
|
||||
// Load default values
|
||||
var targetDefaults = {
|
||||
mode: c.MODE_METRICS,
|
||||
group: { filter: "" },
|
||||
host: { filter: "" },
|
||||
application: { filter: "" },
|
||||
item: { filter: "" },
|
||||
functions: [],
|
||||
options: {
|
||||
showDisabledItems: false
|
||||
'mode': c.MODE_METRICS,
|
||||
'group': { 'filter': "" },
|
||||
'host': { 'filter': "" },
|
||||
'application': { 'filter': "" },
|
||||
'item': { 'filter': "" },
|
||||
'functions': [],
|
||||
'options': {
|
||||
'showDisabledItems': false
|
||||
}
|
||||
};
|
||||
_.defaults(target, targetDefaults);
|
||||
@@ -77,26 +94,11 @@ export class ZabbixQueryController extends QueryCtrl {
|
||||
if (target.mode === c.MODE_METRICS ||
|
||||
target.mode === c.MODE_TEXT) {
|
||||
|
||||
this.downsampleFunctionList = [
|
||||
{name: "avg", value: "avg"},
|
||||
{name: "min", value: "min"},
|
||||
{name: "max", value: "max"},
|
||||
{name: "sum", value: "sum"},
|
||||
{name: "count", value: "count"}
|
||||
];
|
||||
|
||||
this.initFilters();
|
||||
}
|
||||
else if (target.mode === c.MODE_ITSERVICE) {
|
||||
this.slaPropertyList = [
|
||||
{name: "Status", property: "status"},
|
||||
{name: "SLA", property: "sla"},
|
||||
{name: "OK time", property: "okTime"},
|
||||
{name: "Problem time", property: "problemTime"},
|
||||
{name: "Down time", property: "downtimeTime"}
|
||||
];
|
||||
this.itserviceList = [{name: "test"}];
|
||||
this.updateITServiceList();
|
||||
_.defaults(target, {slaProperty: {name: "SLA", property: "sla"}});
|
||||
this.suggestITServices();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -104,7 +106,8 @@ export class ZabbixQueryController extends QueryCtrl {
|
||||
}
|
||||
|
||||
initFilters() {
|
||||
let itemtype = this.editorModes[this.target.mode].value;
|
||||
let itemtype = _.find(this.editorModes, {'mode': this.target.mode});
|
||||
itemtype = itemtype ? itemtype.value : null;
|
||||
return Promise.all([
|
||||
this.suggestGroups(),
|
||||
this.suggestHosts(),
|
||||
@@ -129,6 +132,12 @@ export class ZabbixQueryController extends QueryCtrl {
|
||||
return metrics;
|
||||
}
|
||||
|
||||
getTemplateVariables() {
|
||||
return _.map(this.templateSrv.variables, variable => {
|
||||
return '$' + variable.name;
|
||||
});
|
||||
}
|
||||
|
||||
suggestGroups() {
|
||||
return this.zabbix.getAllGroups()
|
||||
.then(groups => {
|
||||
@@ -173,6 +182,14 @@ export class ZabbixQueryController extends QueryCtrl {
|
||||
});
|
||||
}
|
||||
|
||||
suggestITServices() {
|
||||
return this.zabbix.getITService()
|
||||
.then(itservices => {
|
||||
this.metric.itServiceList = itservices;
|
||||
return itservices;
|
||||
});
|
||||
}
|
||||
|
||||
isRegex(str) {
|
||||
return utils.isRegex(str);
|
||||
}
|
||||
@@ -292,30 +309,7 @@ export class ZabbixQueryController extends QueryCtrl {
|
||||
switchEditorMode(mode) {
|
||||
this.target.mode = mode;
|
||||
this.init();
|
||||
}
|
||||
|
||||
/////////////////
|
||||
// IT Services //
|
||||
/////////////////
|
||||
|
||||
/**
|
||||
* Update list of IT services
|
||||
*/
|
||||
updateITServiceList() {
|
||||
this.zabbix.getITService().then((iteservices) => {
|
||||
this.itserviceList = [];
|
||||
this.itserviceList = this.itserviceList.concat(iteservices);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Call when IT service is selected.
|
||||
*/
|
||||
selectITService() {
|
||||
if (!_.isEqual(this.oldTarget, this.target) && _.isEmpty(this.target.errors)) {
|
||||
this.oldTarget = angular.copy(this.target);
|
||||
this.panelCtrl.refresh();
|
||||
}
|
||||
this.targetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,10 @@ describe('ZabbixDatasource', () => {
|
||||
password: 'zabbix',
|
||||
trends: true,
|
||||
trendsFrom: '14d',
|
||||
trendsRange: '7d'
|
||||
trendsRange: '7d',
|
||||
dbConnection: {
|
||||
enabled: false
|
||||
}
|
||||
}
|
||||
};
|
||||
ctx.templateSrv = {};
|
||||
|
||||
@@ -88,4 +88,54 @@ describe('Utils', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
describe('splitTemplateQuery()', () => {
|
||||
|
||||
// Backward compatibility
|
||||
it('should properly split query in old format', (done) => {
|
||||
let test_cases = [
|
||||
{
|
||||
query: `/alu/./tw-(nyc|que|brx|dwt|brk)-sta_(\w|\d)*-alu-[0-9{2}/`,
|
||||
expected: ['/alu/', '/tw-(nyc|que|brx|dwt|brk)-sta_(\w|\d)*-alu-[0-9{2}/']
|
||||
},
|
||||
{
|
||||
query: `a.b.c.d`,
|
||||
expected: ['a', 'b', 'c', 'd']
|
||||
}
|
||||
];
|
||||
|
||||
_.each(test_cases, test_case => {
|
||||
let splitQuery = utils.splitTemplateQuery(test_case.query);
|
||||
expect(splitQuery).to.eql(test_case.expected);
|
||||
});
|
||||
done();
|
||||
});
|
||||
|
||||
it('should properly split query', (done) => {
|
||||
let test_cases = [
|
||||
{
|
||||
query: `{alu}{/tw-(nyc|que|brx|dwt|brk)-sta_(\w|\d)*-alu-[0-9]*/}`,
|
||||
expected: ['alu', '/tw-(nyc|que|brx|dwt|brk)-sta_(\w|\d)*-alu-[0-9]*/']
|
||||
},
|
||||
{
|
||||
query: `{alu}{/tw-(nyc|que|brx|dwt|brk)-sta_(\w|\d)*-alu-[0-9]{2}/}`,
|
||||
expected: ['alu', '/tw-(nyc|que|brx|dwt|brk)-sta_(\w|\d)*-alu-[0-9]{2}/']
|
||||
},
|
||||
{
|
||||
query: `{a}{b}{c}{d}`,
|
||||
expected: ['a', 'b', 'c', 'd']
|
||||
},
|
||||
{
|
||||
query: `{a}{b.c.d}`,
|
||||
expected: ['a', 'b.c.d']
|
||||
}
|
||||
];
|
||||
|
||||
_.each(test_cases, test_case => {
|
||||
let splitQuery = utils.splitTemplateQuery(test_case.query);
|
||||
expect(splitQuery).to.eql(test_case.expected);
|
||||
});
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -22,6 +22,15 @@ export function expandItemName(name, key) {
|
||||
return name;
|
||||
}
|
||||
|
||||
export function expandItems(items) {
|
||||
_.forEach(items, item => {
|
||||
item.item = item.name;
|
||||
item.name = expandItemName(item.item, item.key_);
|
||||
return item;
|
||||
});
|
||||
return items;
|
||||
}
|
||||
|
||||
function splitKeyParams(paramStr) {
|
||||
let params = [];
|
||||
let quoted = false;
|
||||
@@ -93,7 +102,7 @@ function escapeMacro(macro) {
|
||||
* {group}{host.com} -> [group, host.com]
|
||||
*/
|
||||
export function splitTemplateQuery(query) {
|
||||
let splitPattern = /{[^{}]*}/g;
|
||||
let splitPattern = /\{[^\{\}]*\}|\{\/.*\/\}/g;
|
||||
let split;
|
||||
|
||||
if (isContainsBraces(query)) {
|
||||
@@ -109,7 +118,8 @@ export function splitTemplateQuery(query) {
|
||||
}
|
||||
|
||||
function isContainsBraces(query) {
|
||||
return query.includes('{') && query.includes('}');
|
||||
let bracesPattern = /^\{.+\}$/;
|
||||
return bracesPattern.test(query);
|
||||
}
|
||||
|
||||
// Pattern for testing regex
|
||||
|
||||
@@ -3,30 +3,45 @@ import _ from 'lodash';
|
||||
import * as utils from './utils';
|
||||
import './zabbixAPI.service.js';
|
||||
import './zabbixCachingProxy.service.js';
|
||||
import './zabbixDBConnector';
|
||||
|
||||
// Use factory() instead service() for multiple data sources support.
|
||||
// Each Zabbix data source instance should initialize its own API instance.
|
||||
|
||||
/** @ngInject */
|
||||
function ZabbixFactory(zabbixAPIService, ZabbixCachingProxy) {
|
||||
function ZabbixFactory(zabbixAPIService, ZabbixCachingProxy, ZabbixDBConnector) {
|
||||
|
||||
class Zabbix {
|
||||
constructor(url, username, password, basicAuth, withCredentials, cacheTTL) {
|
||||
constructor(url, options) {
|
||||
let {
|
||||
username, password, basicAuth, withCredentials, cacheTTL,
|
||||
enableDirectDBConnection, sqlDatasourceId
|
||||
} = options;
|
||||
|
||||
// Initialize Zabbix API
|
||||
var ZabbixAPI = zabbixAPIService;
|
||||
this.zabbixAPI = new ZabbixAPI(url, username, password, basicAuth, withCredentials);
|
||||
|
||||
if (enableDirectDBConnection) {
|
||||
this.dbConnector = new ZabbixDBConnector(sqlDatasourceId);
|
||||
}
|
||||
|
||||
// Initialize caching proxy for requests
|
||||
let cacheOptions = {
|
||||
enabled: true,
|
||||
ttl: cacheTTL
|
||||
};
|
||||
this.cachingProxy = new ZabbixCachingProxy(this.zabbixAPI, cacheOptions);
|
||||
this.cachingProxy = new ZabbixCachingProxy(this.zabbixAPI, this.dbConnector, cacheOptions);
|
||||
|
||||
// Proxy methods
|
||||
this.getHistory = this.cachingProxy.getHistory.bind(this.cachingProxy);
|
||||
this.getMacros = this.cachingProxy.getMacros.bind(this.cachingProxy);
|
||||
this.getItemsByIDs = this.cachingProxy.getItemsByIDs.bind(this.cachingProxy);
|
||||
|
||||
if (enableDirectDBConnection) {
|
||||
this.getHistoryDB = this.cachingProxy.getHistoryDB.bind(this.cachingProxy);
|
||||
this.getTrendsDB = this.cachingProxy.getTrendsDB.bind(this.cachingProxy);
|
||||
}
|
||||
|
||||
this.getTrend = this.zabbixAPI.getTrend.bind(this.zabbixAPI);
|
||||
this.getEvents = this.zabbixAPI.getEvents.bind(this.zabbixAPI);
|
||||
@@ -134,6 +149,11 @@ function ZabbixFactory(zabbixAPIService, ZabbixCachingProxy) {
|
||||
.then(items => filterByQuery(items, itemFilter));
|
||||
}
|
||||
|
||||
getITServices(itServiceFilter) {
|
||||
return this.cachingProxy.getITServices()
|
||||
.then(itServices => findByFilter(itServices, itServiceFilter));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build query - convert target filters to array of Zabbix items
|
||||
*/
|
||||
|
||||
@@ -165,10 +165,7 @@ function ZabbixAPIServiceFactory(alertSrv, zabbixAPICoreService) {
|
||||
sortfield: 'name',
|
||||
webitems: true,
|
||||
filter: {},
|
||||
selectHosts: [
|
||||
'hostid',
|
||||
'name'
|
||||
]
|
||||
selectHosts: ['hostid', 'name']
|
||||
};
|
||||
if (hostids) {
|
||||
params.hostids = hostids;
|
||||
@@ -186,16 +183,25 @@ function ZabbixAPIServiceFactory(alertSrv, zabbixAPICoreService) {
|
||||
}
|
||||
|
||||
return this.request('item.get', params)
|
||||
.then(expandItems);
|
||||
.then(utils.expandItems);
|
||||
}
|
||||
|
||||
function expandItems(items) {
|
||||
_.forEach(items, item => {
|
||||
item.item = item.name;
|
||||
item.name = utils.expandItemName(item.item, item.key_);
|
||||
return item;
|
||||
});
|
||||
return items;
|
||||
}
|
||||
getItemsByIDs(itemids) {
|
||||
var params = {
|
||||
itemids: itemids,
|
||||
output: [
|
||||
'name', 'key_',
|
||||
'value_type',
|
||||
'hostid',
|
||||
'status',
|
||||
'state'
|
||||
],
|
||||
webitems: true,
|
||||
selectHosts: ['hostid', 'name']
|
||||
};
|
||||
|
||||
return this.request('item.get', params)
|
||||
.then(utils.expandItems);
|
||||
}
|
||||
|
||||
getMacros(hostids) {
|
||||
|
||||
@@ -8,8 +8,9 @@ import _ from 'lodash';
|
||||
function ZabbixCachingProxyFactory() {
|
||||
|
||||
class ZabbixCachingProxy {
|
||||
constructor(zabbixAPI, cacheOptions) {
|
||||
constructor(zabbixAPI, zabbixDBConnector, cacheOptions) {
|
||||
this.zabbixAPI = zabbixAPI;
|
||||
this.dbConnector = zabbixDBConnector;
|
||||
this.cacheEnabled = cacheOptions.enabled;
|
||||
this.ttl = cacheOptions.ttl || 600000; // 10 minutes by default
|
||||
|
||||
@@ -22,7 +23,8 @@ function ZabbixCachingProxyFactory() {
|
||||
history: {},
|
||||
trends: {},
|
||||
macros: {},
|
||||
globalMacros: {}
|
||||
globalMacros: {},
|
||||
itServices: {}
|
||||
};
|
||||
|
||||
this.historyPromises = {};
|
||||
@@ -31,6 +33,13 @@ function ZabbixCachingProxyFactory() {
|
||||
this.getHistory = callAPIRequestOnce(_.bind(this.zabbixAPI.getHistory, this.zabbixAPI),
|
||||
this.historyPromises, getHistoryRequestHash);
|
||||
|
||||
if (this.dbConnector) {
|
||||
this.getHistoryDB = callAPIRequestOnce(_.bind(this.dbConnector.getHistory, this.dbConnector),
|
||||
this.historyPromises, getDBQueryHash);
|
||||
this.getTrendsDB = callAPIRequestOnce(_.bind(this.dbConnector.getTrends, this.dbConnector),
|
||||
this.historyPromises, getDBQueryHash);
|
||||
}
|
||||
|
||||
// Don't run duplicated requests
|
||||
this.groupPromises = {};
|
||||
this.getGroupsOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getGroups, this.zabbixAPI),
|
||||
@@ -48,6 +57,14 @@ function ZabbixCachingProxyFactory() {
|
||||
this.getItemsOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getItems, this.zabbixAPI),
|
||||
this.itemPromises, getRequestHash);
|
||||
|
||||
this.itemByIdPromises = {};
|
||||
this.getItemsByIdOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getItemsByIDs, this.zabbixAPI),
|
||||
this.itemPromises, getRequestHash);
|
||||
|
||||
this.itServicesPromises = {};
|
||||
this.getITServicesOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getITService, this.zabbixAPI),
|
||||
this.itServicesPromises, getRequestHash);
|
||||
|
||||
this.macroPromises = {};
|
||||
this.getMacrosOnce = callAPIRequestOnce(_.bind(this.zabbixAPI.getMacros, this.zabbixAPI),
|
||||
this.macroPromises, getRequestHash);
|
||||
@@ -103,6 +120,15 @@ function ZabbixCachingProxyFactory() {
|
||||
return this.proxyRequest(this.getItemsOnce, params, this.cache.items);
|
||||
}
|
||||
|
||||
getItemsByIDs(itemids) {
|
||||
let params = [itemids];
|
||||
return this.proxyRequest(this.getItemsByIdOnce, params, this.cache.items);
|
||||
}
|
||||
|
||||
getITServices() {
|
||||
return this.proxyRequest(this.getITServicesOnce, [], this.cache.itServices);
|
||||
}
|
||||
|
||||
getMacros(hostids) {
|
||||
// Merge global macros and host macros
|
||||
let promises = [
|
||||
@@ -195,6 +221,14 @@ function getHistoryRequestHash(args) {
|
||||
return stamp.getHash();
|
||||
}
|
||||
|
||||
function getDBQueryHash(args) {
|
||||
let itemids = _.map(args[0], 'itemid');
|
||||
let consolidateBy = args[3].consolidateBy;
|
||||
let intervalMs = args[3].intervalMs;
|
||||
let stamp = itemids.join() + args[1] + args[2] + consolidateBy + intervalMs;
|
||||
return stamp.getHash();
|
||||
}
|
||||
|
||||
String.prototype.getHash = function() {
|
||||
var hash = 0, i, chr, len;
|
||||
if (this.length !== 0) {
|
||||
|
||||
192
src/datasource-zabbix/zabbixDBConnector.js
Normal file
192
src/datasource-zabbix/zabbixDBConnector.js
Normal file
@@ -0,0 +1,192 @@
|
||||
import angular from 'angular';
|
||||
import _ from 'lodash';
|
||||
|
||||
const DEFAULT_QUERY_LIMIT = 10000;
|
||||
const HISTORY_TO_TABLE_MAP = {
|
||||
'0': 'history',
|
||||
'1': 'history_str',
|
||||
'2': 'history_log',
|
||||
'3': 'history_uint',
|
||||
'4': 'history_text'
|
||||
};
|
||||
|
||||
const TREND_TO_TABLE_MAP = {
|
||||
'0': 'trends',
|
||||
'3': 'trends_uint'
|
||||
};
|
||||
|
||||
const consolidateByFunc = {
|
||||
'avg': 'AVG',
|
||||
'min': 'MIN',
|
||||
'max': 'MAX',
|
||||
'sum': 'SUM',
|
||||
'count': 'COUNT'
|
||||
};
|
||||
|
||||
const consolidateByTrendColumns = {
|
||||
'avg': 'value_avg',
|
||||
'min': 'value_min',
|
||||
'max': 'value_max'
|
||||
};
|
||||
|
||||
/** @ngInject */
|
||||
function ZabbixDBConnectorFactory(datasourceSrv, backendSrv) {
|
||||
|
||||
class ZabbixDBConnector {
|
||||
|
||||
constructor(sqlDataSourceId, options = {}) {
|
||||
let {limit} = options;
|
||||
|
||||
this.sqlDataSourceId = sqlDataSourceId;
|
||||
this.limit = limit || DEFAULT_QUERY_LIMIT;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
return datasourceSrv.loadDatasource(ds.name)
|
||||
.then(ds => {
|
||||
console.log('SQL data source loaded', ds);
|
||||
});
|
||||
} else {
|
||||
return Promise.reject(`SQL Data Source with ID ${datasourceId} not found`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
||||
consolidateBy = consolidateBy || 'avg';
|
||||
let aggFunction = consolidateByFunc[consolidateBy];
|
||||
|
||||
// Group items by value type and perform request for each value type
|
||||
let grouped_items = _.groupBy(items, 'value_type');
|
||||
let promises = _.map(grouped_items, (items, value_type) => {
|
||||
let itemids = _.map(items, 'itemid').join(', ');
|
||||
let table = HISTORY_TO_TABLE_MAP[value_type];
|
||||
|
||||
let query = `
|
||||
SELECT itemid AS metric, clock AS time_sec, ${aggFunction}(value) AS value
|
||||
FROM ${table}
|
||||
WHERE itemid IN (${itemids})
|
||||
AND clock > ${timeFrom} AND clock < ${timeTill}
|
||||
GROUP BY time_sec DIV ${intervalSec}, metric
|
||||
`;
|
||||
|
||||
query = compactSQLQuery(query);
|
||||
return this.invokeSQLQuery(query);
|
||||
});
|
||||
|
||||
return Promise.all(promises).then(results => {
|
||||
return _.flatten(results);
|
||||
});
|
||||
}
|
||||
|
||||
getTrends(items, timeFrom, timeTill, options) {
|
||||
let {intervalMs, consolidateBy} = options;
|
||||
let intervalSec = Math.ceil(intervalMs / 1000);
|
||||
|
||||
consolidateBy = consolidateBy || 'avg';
|
||||
let aggFunction = consolidateByFunc[consolidateBy];
|
||||
|
||||
// Group items by value type and perform request for each value type
|
||||
let grouped_items = _.groupBy(items, 'value_type');
|
||||
let promises = _.map(grouped_items, (items, value_type) => {
|
||||
let itemids = _.map(items, 'itemid').join(', ');
|
||||
let table = TREND_TO_TABLE_MAP[value_type];
|
||||
let valueColumn = _.includes(['avg', 'min', 'max'], consolidateBy) ? consolidateBy : 'avg';
|
||||
valueColumn = consolidateByTrendColumns[valueColumn];
|
||||
|
||||
let query = `
|
||||
SELECT itemid AS metric, clock AS time_sec, ${aggFunction}(${valueColumn}) AS value
|
||||
FROM ${table}
|
||||
WHERE itemid IN (${itemids})
|
||||
AND clock > ${timeFrom} AND clock < ${timeTill}
|
||||
GROUP BY time_sec DIV ${intervalSec}, metric
|
||||
`;
|
||||
|
||||
query = compactSQLQuery(query);
|
||||
return this.invokeSQLQuery(query);
|
||||
});
|
||||
|
||||
return Promise.all(promises).then(results => {
|
||||
return _.flatten(results);
|
||||
});
|
||||
}
|
||||
|
||||
handleGrafanaTSResponse(history, items, addHostName = true) {
|
||||
return convertGrafanaTSResponse(history, items, addHostName);
|
||||
}
|
||||
|
||||
invokeSQLQuery(query) {
|
||||
let queryDef = {
|
||||
refId: 'A',
|
||||
format: 'time_series',
|
||||
datasourceId: this.sqlDataSourceId,
|
||||
rawSql: query,
|
||||
maxDataPoints: this.limit
|
||||
};
|
||||
|
||||
return backendSrv.datasourceRequest({
|
||||
url: '/api/tsdb/query',
|
||||
method: 'POST',
|
||||
data: {
|
||||
queries: [queryDef],
|
||||
}
|
||||
})
|
||||
.then(response => {
|
||||
let results = response.data.results;
|
||||
if (results['A']) {
|
||||
return results['A'].series;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return ZabbixDBConnector;
|
||||
}
|
||||
|
||||
angular
|
||||
.module('grafana.services')
|
||||
.factory('ZabbixDBConnector', ZabbixDBConnectorFactory);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
function convertGrafanaTSResponse(time_series, items, addHostName) {
|
||||
var hosts = _.uniqBy(_.flatten(_.map(items, 'hosts')), 'hostid'); //uniqBy is needed to deduplicate
|
||||
let grafanaSeries = _.map(time_series, series => {
|
||||
let itemid = series.name;
|
||||
let datapoints = series.points;
|
||||
var item = _.find(items, {'itemid': itemid});
|
||||
var alias = item.name;
|
||||
if (_.keys(hosts).length > 1 && addHostName) { //only when actual multi hosts selected
|
||||
var host = _.find(hosts, {'hostid': item.hostid});
|
||||
alias = host.name + ": " + alias;
|
||||
}
|
||||
return {
|
||||
target: alias,
|
||||
datapoints: datapoints
|
||||
};
|
||||
});
|
||||
|
||||
return _.sortBy(grafanaSeries, 'target');
|
||||
}
|
||||
|
||||
function compactSQLQuery(query) {
|
||||
return query.replace(/\s+/g, ' ');
|
||||
}
|
||||
@@ -55,6 +55,10 @@
|
||||
placeholder="trigger name"
|
||||
class="gf-form-input"
|
||||
ng-style="editor.panel.triggers.trigger.style"
|
||||
ng-class="{
|
||||
'zbx-variable': editor.isVariable(editor.panel.triggers.trigger.filter),
|
||||
'zbx-regex': editor.isRegex(editor.panel.triggers.trigger.filter)
|
||||
}"
|
||||
empty-to-null>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -130,6 +130,7 @@ class TriggerPanelCtrl extends PanelCtrl {
|
||||
.then(datasource => {
|
||||
var zabbix = datasource.zabbix;
|
||||
this.zabbix = zabbix;
|
||||
this.datasource = datasource;
|
||||
var showEvents = this.panel.showEvents.value;
|
||||
var triggerFilter = this.panel.triggers;
|
||||
var hideHostsInMaintenance = this.panel.hideHostsInMaintenance;
|
||||
@@ -143,10 +144,11 @@ class TriggerPanelCtrl extends PanelCtrl {
|
||||
showTriggers: showEvents,
|
||||
hideHostsInMaintenance: hideHostsInMaintenance
|
||||
};
|
||||
let getTriggers = zabbix.getTriggers(groupFilter, hostFilter, appFilter, triggersOptions);
|
||||
return getTriggers.then(triggers => {
|
||||
return _.map(triggers, this.formatTrigger.bind(this));
|
||||
});
|
||||
|
||||
return zabbix.getTriggers(groupFilter, hostFilter, appFilter, triggersOptions);
|
||||
})
|
||||
.then(triggers => {
|
||||
return _.map(triggers, this.formatTrigger.bind(this));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -191,6 +193,7 @@ class TriggerPanelCtrl extends PanelCtrl {
|
||||
filterTriggers(triggerList) {
|
||||
// Filter triggers by description
|
||||
var triggerFilter = this.panel.triggers.trigger.filter;
|
||||
triggerFilter = this.datasource.replaceTemplateVars(triggerFilter);
|
||||
if (triggerFilter) {
|
||||
triggerList = filterTriggers(triggerList, triggerFilter);
|
||||
}
|
||||
|
||||
@@ -26,8 +26,8 @@
|
||||
{"name": "Metric Editor", "path": "img/screenshot-metric_editor.png"},
|
||||
{"name": "Triggers", "path": "img/screenshot-triggers.png"}
|
||||
],
|
||||
"version": "3.4.0",
|
||||
"updated": "2017-05-17"
|
||||
"version": "3.5.1",
|
||||
"updated": "2017-07-10"
|
||||
},
|
||||
|
||||
"includes": [
|
||||
|
||||
Reference in New Issue
Block a user