Skip to content

Commit

Permalink
Merge pull request #37 from GlobalNOC/manual-query-vars
Browse files Browse the repository at this point in the history
adding template variable replacement for raw queries
  • Loading branch information
daldoyle authored Feb 9, 2018
2 parents 0f4e759 + 56e059c commit ec1f2b7
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -930,12 +930,23 @@ class GenericDatasource {
});
}

target.metricValueAliasMappings = {};

let start = Date.parse(options.range.from) / 1000;
let end = Date.parse(options.range.to) / 1000;
let duration = (end - start);

if (target.rawQuery) {
let query = t.templateSrv.replace(target.target, options.scopedVars);
let oldQ = query.substr(query.indexOf("{"), query.length);
let formatQ = oldQ.replace(/,/gi, " or ");
query = query.replace(oldQ, formatQ);

query = query.replace("$START", start.toString());
query = query.replace("$END", end.toString());
query = query.replace("$TIMESPAN", duration.toString());
query = this.templateSrv.replace(query, null, 'regex');

return resolve({
target: query,
targetAliases: target.metricValueAliasMappings,
Expand All @@ -947,18 +958,12 @@ class GenericDatasource {
});
}

target.metricValueAliasMappings = {};

let query = 'get ';

target.metric_array.forEach((metric) => {
query += `${metric}, `;
});

let start = Date.parse(options.range.from) / 1000;
let end = Date.parse(options.range.to) / 1000;
let duration = (end - start);

let functions = target.func.map((f) => {
let aggregation = TSDSQuery(f);
let template_variables = getVariableDetails();
Expand Down

0 comments on commit ec1f2b7

Please sign in to comment.