The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/plugins/datasource/grafana-azure-monitor-datas.../annotations_query_ctrl.ts

78 lines
2.3 KiB

import { getTemplateSrv, TemplateSrv } from '@grafana/runtime';
export class AzureMonitorAnnotationsQueryCtrl {
static templateUrl = 'partials/annotations.editor.html';
datasource: any;
annotation: any;
workspaces: any[];
subscriptions: Array<{ text: string; value: string }>;
defaultQuery =
'<your table>\n| where $__timeFilter() \n| project TimeGenerated, Text=YourTitleColumn, Tags="tag1,tag2"';
constructor(private templateSrv: TemplateSrv = getTemplateSrv()) {
this.annotation.queryType = this.annotation.queryType || 'Azure Log Analytics';
this.annotation.rawQuery = this.annotation.rawQuery || this.defaultQuery;
this.initDropdowns();
}
async initDropdowns() {
await this.getSubscriptions();
await this.getWorkspaces();
}
async getSubscriptions() {
if (!this.datasource.azureMonitorDatasource.isConfigured()) {
return;
}
return this.datasource.azureMonitorDatasource.getSubscriptions().then((subs: any[]) => {
this.subscriptions = subs;
if (!this.annotation.subscription && this.annotation.queryType === 'Azure Log Analytics') {
this.annotation.subscription = this.datasource.azureLogAnalyticsDatasource.subscriptionId;
}
if (!this.annotation.subscription && this.subscriptions.length > 0) {
this.annotation.subscription = this.subscriptions[0].value;
}
});
}
async getWorkspaces(bustCache?: boolean) {
if (!bustCache && this.workspaces && this.workspaces.length > 0) {
return this.workspaces;
}
return this.datasource
.getAzureLogAnalyticsWorkspaces(this.annotation.subscription)
.then((list: any[]) => {
this.workspaces = list;
if (list.length > 0 && !this.annotation.workspace) {
this.annotation.workspace = list[0].value;
}
return this.workspaces;
})
.catch(() => {});
}
getAzureLogAnalyticsSchema = () => {
return this.getWorkspaces()
.then(() => {
return this.datasource.azureLogAnalyticsDatasource.getSchema(this.annotation.workspace);
})
.catch(() => {});
};
onSubscriptionChange = () => {
this.getWorkspaces(true);
};
onLogAnalyticsQueryChange = (nextQuery: string) => {
this.annotation.rawQuery = nextQuery;
};
get templateVariables() {
return this.templateSrv.getVariables().map((t: any) => '$' + t.name);
}
}