123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- 'use strict';
- System.register(['lodash'], function (_export, _context) {
- "use strict";
- var _, _createClass, GenericDatasource;
- 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;
- };
- }();
- _export('GenericDatasource', GenericDatasource = function () {
- function GenericDatasource(instanceSettings, $q, backendSrv, templateSrv) {
- _classCallCheck(this, GenericDatasource);
- this.type = instanceSettings.type;
- this.url = instanceSettings.url;
- this.name = instanceSettings.name;
- this.q = $q;
- this.backendSrv = backendSrv;
- this.templateSrv = templateSrv;
- this.withCredentials = instanceSettings.withCredentials;
- this.headers = { 'Content-Type': 'application/json' };
- if (typeof instanceSettings.basicAuth === 'string' && instanceSettings.basicAuth.length > 0) {
- this.headers['Authorization'] = instanceSettings.basicAuth;
- }
- }
- _createClass(GenericDatasource, [{
- key: 'query',
- value: function query(options) {
- var query = this.buildQueryParameters(options);
- query.targets = query.targets.filter(function (t) {
- return !t.hide;
- });
- if (query.targets.length <= 0) {
- return this.q.when({ data: [] });
- }
- if (this.templateSrv.getAdhocFilters) {
- query.adhocFilters = this.templateSrv.getAdhocFilters(this.name);
- } else {
- query.adhocFilters = [];
- }
- return this.doRequest({
- url: this.url + '/query',
- data: query,
- method: 'POST'
- });
- }
- }, {
- key: 'testDatasource',
- value: function testDatasource() {
- return this.doRequest({
- url: this.url + '/',
- method: 'GET'
- }).then(function (response) {
- if (response.status === 200) {
- return { status: "success", message: "Data source is working", title: "Success" };
- }
- });
- }
- }, {
- key: 'annotationQuery',
- value: function annotationQuery(options) {
- var query = this.templateSrv.replace(options.annotation.query, {}, 'glob');
- var annotationQuery = {
- range: options.range,
- annotation: {
- name: options.annotation.name,
- datasource: options.annotation.datasource,
- enable: options.annotation.enable,
- iconColor: options.annotation.iconColor,
- query: query
- },
- rangeRaw: options.rangeRaw
- };
- return this.doRequest({
- url: this.url + '/annotations',
- method: 'POST',
- data: annotationQuery
- }).then(function (result) {
- return result.data;
- });
- }
- }, {
- key: 'metricFindQuery',
- value: function metricFindQuery(query) {
- var interpolated = {
- target: this.templateSrv.replace(query, null, 'regex')
- };
- return this.doRequest({
- url: this.url + '/search',
- data: interpolated,
- method: 'POST'
- }).then(this.mapToTextValue);
- }
- }, {
- key: 'mapToTextValue',
- value: function mapToTextValue(result) {
- return _.map(result.data, function (d, i) {
- if (d && d.text && d.value) {
- return { text: d.text, value: d.value };
- } else if (_.isObject(d)) {
- return { text: d, value: i };
- }
- return { text: d, value: d };
- });
- }
- }, {
- key: 'doRequest',
- value: function doRequest(options) {
- options.withCredentials = this.withCredentials;
- options.headers = this.headers;
- return this.backendSrv.datasourceRequest(options);
- }
- }, {
- key: 'buildQueryParameters',
- value: function buildQueryParameters(options) {
- var _this = this;
- //remove placeholder targets
- options.targets = _.filter(options.targets, function (target) {
- return target.target !== 'select metric';
- });
- var targets = _.map(options.targets, function (target) {
- return {
- target: _this.templateSrv.replace(target.target, options.scopedVars, 'regex'),
- refId: target.refId,
- hide: target.hide,
- type: target.type || 'timeserie'
- };
- });
- options.targets = targets;
- return options;
- }
- }, {
- key: 'getTagKeys',
- value: function getTagKeys(options) {
- var _this2 = this;
- return new Promise(function (resolve, reject) {
- _this2.doRequest({
- url: _this2.url + '/tag-keys',
- method: 'POST',
- data: options
- }).then(function (result) {
- return resolve(result.data);
- });
- });
- }
- }, {
- key: 'getTagValues',
- value: function getTagValues(options) {
- var _this3 = this;
- return new Promise(function (resolve, reject) {
- _this3.doRequest({
- url: _this3.url + '/tag-values',
- method: 'POST',
- data: options
- }).then(function (result) {
- return resolve(result.data);
- });
- });
- }
- }]);
- return GenericDatasource;
- }());
- _export('GenericDatasource', GenericDatasource);
- }
- };
- });
- //# sourceMappingURL=datasource.js.map
|