config_ctrl.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import AzureLogAnalyticsDatasource from './azure_log_analytics/azure_log_analytics_datasource';
  2. import config from 'app/core/config';
  3. import { isVersionGtOrEq } from 'app/core/utils/version';
  4. export class AzureMonitorConfigCtrl {
  5. static templateUrl = 'public/app/plugins/datasource/grafana-azure-monitor-datasource/partials/config.html';
  6. current: any;
  7. azureLogAnalyticsDatasource: any;
  8. workspaces: any[];
  9. hasRequiredGrafanaVersion: boolean;
  10. /** @ngInject */
  11. constructor($scope, backendSrv, $q) {
  12. this.hasRequiredGrafanaVersion = this.hasMinVersion();
  13. this.current.jsonData.cloudName = this.current.jsonData.cloudName || 'azuremonitor';
  14. this.current.jsonData.azureLogAnalyticsSameAs = this.current.jsonData.azureLogAnalyticsSameAs || false;
  15. if (this.current.id) {
  16. this.current.url = '/api/datasources/proxy/' + this.current.id;
  17. this.azureLogAnalyticsDatasource = new AzureLogAnalyticsDatasource(this.current, backendSrv, null, $q);
  18. this.getWorkspaces();
  19. }
  20. }
  21. hasMinVersion(): boolean {
  22. return isVersionGtOrEq(config.buildInfo.version, '5.2');
  23. }
  24. showMinVersionWarning() {
  25. return !this.hasRequiredGrafanaVersion && this.current.secureJsonFields.logAnalyticsClientSecret;
  26. }
  27. getWorkspaces() {
  28. if (!this.azureLogAnalyticsDatasource.isConfigured()) {
  29. return;
  30. }
  31. return this.azureLogAnalyticsDatasource.getWorkspaces().then(workspaces => {
  32. this.workspaces = workspaces;
  33. if (this.workspaces.length > 0) {
  34. this.current.jsonData.logAnalyticsDefaultWorkspace =
  35. this.current.jsonData.logAnalyticsDefaultWorkspace || this.workspaces[0].value;
  36. }
  37. });
  38. }
  39. }