datasource.js.map 8.2 KB

1
  1. {"version":3,"sources":["../src/datasource.js"],"names":["_","GenericDatasource","instanceSettings","$q","backendSrv","templateSrv","type","url","name","q","withCredentials","headers","basicAuth","length","options","query","buildQueryParameters","targets","filter","t","hide","when","data","getAdhocFilters","adhocFilters","doRequest","method","then","response","status","message","title","replace","annotation","annotationQuery","range","datasource","enable","iconColor","rangeRaw","result","interpolated","target","mapToTextValue","map","d","i","text","value","isObject","datasourceRequest","scopedVars","refId","Promise","resolve","reject"],"mappings":";;;;;;;;;;;;;;;AAAOA,O;;;;;;;;;;;;;;;;;;;;;mCAEMC,iB;AAEX,mCAAYC,gBAAZ,EAA8BC,EAA9B,EAAkCC,UAAlC,EAA8CC,WAA9C,EAA2D;AAAA;;AACzD,eAAKC,IAAL,GAAYJ,iBAAiBI,IAA7B;AACA,eAAKC,GAAL,GAAWL,iBAAiBK,GAA5B;AACA,eAAKC,IAAL,GAAYN,iBAAiBM,IAA7B;AACA,eAAKC,CAAL,GAASN,EAAT;AACA,eAAKC,UAAL,GAAkBA,UAAlB;AACA,eAAKC,WAAL,GAAmBA,WAAnB;AACA,eAAKK,eAAL,GAAuBR,iBAAiBQ,eAAxC;AACA,eAAKC,OAAL,GAAe,EAAC,gBAAgB,kBAAjB,EAAf;AACA,cAAI,OAAOT,iBAAiBU,SAAxB,KAAsC,QAAtC,IAAkDV,iBAAiBU,SAAjB,CAA2BC,MAA3B,GAAoC,CAA1F,EAA6F;AAC3F,iBAAKF,OAAL,CAAa,eAAb,IAAgCT,iBAAiBU,SAAjD;AACD;AACF;;;;gCAEKE,O,EAAS;AACb,gBAAIC,QAAQ,KAAKC,oBAAL,CAA0BF,OAA1B,CAAZ;AACAC,kBAAME,OAAN,GAAgBF,MAAME,OAAN,CAAcC,MAAd,CAAqB;AAAA,qBAAK,CAACC,EAAEC,IAAR;AAAA,aAArB,CAAhB;;AAEA,gBAAIL,MAAME,OAAN,CAAcJ,MAAd,IAAwB,CAA5B,EAA+B;AAC7B,qB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,qBAAOyB,OAAOA,MAAP,KAAkB,eAAzB;AACD,aAFiB,CAAlB;;AAIA,gBAAIzB,UAAUjB,EAAE4C,GAAF,CAAM9B,QAAQG,OAAd,EAAuB,kBAAU;AAC7C,qBAAO;AACLyB,wBAAQ,MAAKrC,WAAL,CAAiB2B,OAAjB,CAAyBU,OAAOA,MAAhC,EAAwC5B,QAAQqC,UAAhD,EAA4D,OAA5D,CADH;AAELC,uBAAOV,OAAOU,KAFT;AAGLhC,sBAAMsB,OAAOtB,IAHR;AAILd,sBAAMoC,OAAOpC,IAAP,IAAe;AAJhB,eAAP;AAMD,aAPa,CAAd;;AASAQ,oBAAQG,OAAR,GAAkBA,OAAlB;;AAEA,mBAAOH,OAAP;AACD;;;qCAEUA,O,EAAS;AAAA;;AAClB,mBAAO,IAAIuC,OAAJ,CAAY,UAACC,OAAD,EAAUC,MAAV,EAAqB;AACtC,qBAAK9B,SAAL,CAAe;AACblB,qBAAK,OAAKA,GAAL,GAAW,WADH;AAEbmB,wBAAQ,MAFK;AAGbJ,sBAAMR;AAHO,eAAf,EAIGa,IAJH,CAIQ,kBAAU;AAChB,uBAAO2B,QAAQd,OAAOlB,IAAf,CAAP;AACD,eAND;AAOD,aARM,CAAP;AASD;;;uCAEYR,O,EAAS;AAAA;;AACpB,mBAAO,IAAIuC,OAAJ,CAAY,UAACC,OAAD,EAAUC,MAAV,EAAqB;AACtC,qBAAK9B,SAAL,CAAe;AACblB,qBAAK,OAAKA,GAAL,GAAW,aADH;AAEbmB,wBAAQ,MAFK;AAGbJ,sBAAMR;AAHO,eAAf,EAIGa,IAJH,CAIQ,kBAAU;AAChB,uBAAO2B,QAAQd,OAAOlB,IAAf,CAAP;AACD,eAND;AAOD,aARM,CAAP;AASD","file":"datasource.js","sourcesContent":["import _ from \"lodash\";\n\nexport class GenericDatasource {\n\n constructor(instanceSettings, $q, backendSrv, templateSrv) {\n this.type = instanceSettings.type;\n this.url = instanceSettings.url;\n this.name = instanceSettings.name;\n this.q = $q;\n this.backendSrv = backendSrv;\n this.templateSrv = templateSrv;\n this.withCredentials = instanceSettings.withCredentials;\n this.headers = {'Content-Type': 'application/json'};\n if (typeof instanceSettings.basicAuth === 'string' && instanceSettings.basicAuth.length > 0) {\n this.headers['Authorization'] = instanceSettings.basicAuth;\n }\n }\n\n query(options) {\n var query = this.buildQueryParameters(options);\n query.targets = query.targets.filter(t => !t.hide);\n\n if (query.targets.length <= 0) {\n return this.q.when({data: []});\n }\n\n if (this.templateSrv.getAdhocFilters) {\n query.adhocFilters = this.templateSrv.getAdhocFilters(this.name);\n } else {\n query.adhocFilters = [];\n }\n\n return this.doRequest({\n url: this.url + '/query',\n data: query,\n method: 'POST'\n });\n }\n\n testDatasource() {\n return this.doRequest({\n url: this.url + '/',\n method: 'GET',\n }).then(response => {\n if (response.status === 200) {\n return { status: \"success\", message: \"Data source is working\", title: \"Success\" };\n }\n });\n }\n\n annotationQuery(options) {\n var query = this.templateSrv.replace(options.annotation.query, {}, 'glob');\n var annotationQuery = {\n range: options.range,\n annotation: {\n name: options.annotation.name,\n datasource: options.annotation.datasource,\n enable: options.annotation.enable,\n iconColor: options.annotation.iconColor,\n query: query\n },\n rangeRaw: options.rangeRaw\n };\n\n return this.doRequest({\n url: this.url + '/annotations',\n method: 'POST',\n data: annotationQuery\n }).then(result => {\n return result.data;\n });\n }\n\n metricFindQuery(query) {\n var interpolated = {\n target: this.templateSrv.replace(query, null, 'regex')\n };\n\n return this.doRequest({\n url: this.url + '/search',\n data: interpolated,\n method: 'POST',\n }).then(this.mapToTextValue);\n }\n\n mapToTextValue(result) {\n return _.map(result.data, (d, i) => {\n if (d && d.text && d.value) {\n return { text: d.text, value: d.value };\n } else if (_.isObject(d)) {\n return { text: d, value: i};\n }\n return { text: d, value: d };\n });\n }\n\n doRequest(options) {\n options.withCredentials = this.withCredentials;\n options.headers = this.headers;\n\n return this.backendSrv.datasourceRequest(options);\n }\n\n buildQueryParameters(options) {\n //remove placeholder targets\n options.targets = _.filter(options.targets, target => {\n return target.target !== 'select metric';\n });\n\n var targets = _.map(options.targets, target => {\n return {\n target: this.templateSrv.replace(target.target, options.scopedVars, 'regex'),\n refId: target.refId,\n hide: target.hide,\n type: target.type || 'timeserie'\n };\n });\n\n options.targets = targets;\n\n return options;\n }\n\n getTagKeys(options) {\n return new Promise((resolve, reject) => {\n this.doRequest({\n url: this.url + '/tag-keys',\n method: 'POST',\n data: options\n }).then(result => {\n return resolve(result.data);\n });\n });\n }\n\n getTagValues(options) {\n return new Promise((resolve, reject) => {\n this.doRequest({\n url: this.url + '/tag-values',\n method: 'POST',\n data: options\n }).then(result => {\n return resolve(result.data);\n });\n });\n }\n\n}\n"]}