feat(alerting): add template validation for influxdb

closes #6230
This commit is contained in:
bergquist 2016-10-11 16:00:59 +02:00
parent 2e21613be7
commit 0d4b00df95
4 changed files with 27 additions and 1 deletions

View File

@ -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 = '';

View File

@ -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') {

View File

@ -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');

View File

@ -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;