config_ctrl.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import _ from 'lodash';
  2. export class ElasticConfigCtrl {
  3. static templateUrl = 'public/app/plugins/datasource/elasticsearch/partials/config.html';
  4. current: any;
  5. /** @ngInject */
  6. constructor($scope) {
  7. this.current.jsonData.timeField = this.current.jsonData.timeField || '@timestamp';
  8. this.current.jsonData.esVersion = this.current.jsonData.esVersion || 5;
  9. this.current.jsonData.maxConcurrentShardRequests = this.current.jsonData.maxConcurrentShardRequests || 256;
  10. }
  11. indexPatternTypes = [
  12. { name: 'No pattern', value: undefined },
  13. { name: 'Hourly', value: 'Hourly', example: '[logstash-]YYYY.MM.DD.HH' },
  14. { name: 'Daily', value: 'Daily', example: '[logstash-]YYYY.MM.DD' },
  15. { name: 'Weekly', value: 'Weekly', example: '[logstash-]GGGG.WW' },
  16. { name: 'Monthly', value: 'Monthly', example: '[logstash-]YYYY.MM' },
  17. { name: 'Yearly', value: 'Yearly', example: '[logstash-]YYYY' },
  18. ];
  19. esVersions = [
  20. { name: '2.x', value: 2 },
  21. { name: '5.x', value: 5 },
  22. { name: '5.6+', value: 56 },
  23. { name: '6.0+', value: 60 },
  24. ];
  25. indexPatternTypeChanged() {
  26. if (
  27. !this.current.database ||
  28. this.current.database.length === 0 ||
  29. this.current.database.startsWith('[logstash-]')
  30. ) {
  31. const def = _.find(this.indexPatternTypes, {
  32. value: this.current.jsonData.interval,
  33. });
  34. this.current.database = def.example || 'es-index-name';
  35. }
  36. }
  37. }