Commit 0d4b00df by bergquist

feat(alerting): add template validation for influxdb

closes #6230
parent 2e21613b
......@@ -231,7 +231,7 @@ export class AlertTabCtrl {
this.datasourceSrv.get(datasourceName).then(ds => {
if (!ds.meta.alerting) {
this.error = 'The datasource does not support alerting queries';
} else if (this.templateSrv.variableExists(foundTarget.target)) {
} else if (ds.targetContainsTemplate(foundTarget)) {
this.error = 'Template variables are not supported in alert queries';
} else {
this.error = '';
......
......@@ -126,6 +126,10 @@ export function GraphiteDatasource(instanceSettings, $q, backendSrv, templateSrv
}
};
this.targetContainsTemplate = function(target) {
return templateSrv.variableExists(target.target);
};
this.translateTime = function(date, roundUp) {
if (_.isString(date)) {
if (date === 'now') {
......
......@@ -139,6 +139,24 @@ export default class InfluxDatasource {
});
};
targetContainsTemplate(target) {
for (let group of target.groupBy) {
for (let param of group.params) {
if (this.templateSrv.variableExists(param)) {
return true;
}
}
}
for (let i in target.tags) {
if (this.templateSrv.variableExists(target.tags[i].value)) {
return true;
}
}
return false;
};
metricFindQuery(query) {
var interpolated = this.templateSrv.replace(query, null, 'regex');
......
......@@ -58,6 +58,10 @@ export function PrometheusDatasource(instanceSettings, $q, backendSrv, templateS
return escapedValues.join('|');
};
this.targetContainsTemplate = function(target) {
return templateSrv.variableExists(target.expr);
};
// Called once per panel (graph)
this.query = function(options) {
var self = this;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment