mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge pull request #11380 from WPH95/feature/add_es_alerting
elasticsearch: alerting support
This commit is contained in:
@@ -408,4 +408,65 @@ export class ElasticDatasource {
|
||||
getTagValues(options) {
|
||||
return this.getTerms({ field: options.key, query: '*' });
|
||||
}
|
||||
|
||||
targetContainsTemplate(target) {
|
||||
if (this.templateSrv.variableExists(target.query) || this.templateSrv.variableExists(target.alias)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (let bucketAgg of target.bucketAggs) {
|
||||
if (this.templateSrv.variableExists(bucketAgg.field) || this.objectContainsTemplate(bucketAgg.settings)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
for (let metric of target.metrics) {
|
||||
if (
|
||||
this.templateSrv.variableExists(metric.field) ||
|
||||
this.objectContainsTemplate(metric.settings) ||
|
||||
this.objectContainsTemplate(metric.meta)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private isPrimitive(obj) {
|
||||
if (obj === null || obj === undefined) {
|
||||
return true;
|
||||
}
|
||||
if (['string', 'number', 'boolean'].some(type => type === typeof true)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private objectContainsTemplate(obj) {
|
||||
if (!obj) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (let key of Object.keys(obj)) {
|
||||
if (this.isPrimitive(obj[key])) {
|
||||
if (this.templateSrv.variableExists(obj[key])) {
|
||||
return true;
|
||||
}
|
||||
} else if (Array.isArray(obj[key])) {
|
||||
for (let item of obj[key]) {
|
||||
if (this.objectContainsTemplate(item)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (this.objectContainsTemplate(obj[key])) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
"version": "5.0.0"
|
||||
},
|
||||
|
||||
"alerting": true,
|
||||
"annotations": true,
|
||||
"metrics": true,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user