config_ctrl.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. const defaultMaxConcurrentShardRequests = this.current.jsonData.esVersion >= 70 ? 5 : 256;
  10. this.current.jsonData.maxConcurrentShardRequests =
  11. this.current.jsonData.maxConcurrentShardRequests || defaultMaxConcurrentShardRequests;
  12. this.current.jsonData.logMessageField = this.current.jsonData.logMessageField || '';
  13. this.current.jsonData.logLevelField = this.current.jsonData.logLevelField || '';
  14. }
  15. indexPatternTypes = [
  16. { name: 'No pattern', value: undefined },
  17. { name: 'Hourly', value: 'Hourly', example: '[logstash-]YYYY.MM.DD.HH' },
  18. { name: 'Daily', value: 'Daily', example: '[logstash-]YYYY.MM.DD' },
  19. { name: 'Weekly', value: 'Weekly', example: '[logstash-]GGGG.WW' },
  20. { name: 'Monthly', value: 'Monthly', example: '[logstash-]YYYY.MM' },
  21. { name: 'Yearly', value: 'Yearly', example: '[logstash-]YYYY' },
  22. ];
  23. esVersions = [
  24. { name: '2.x', value: 2 },
  25. { name: '5.x', value: 5 },
  26. { name: '5.6+', value: 56 },
  27. { name: '6.0+', value: 60 },
  28. { name: '7.0+', value: 70 },
  29. ];
  30. indexPatternTypeChanged() {
  31. if (
  32. !this.current.database ||
  33. this.current.database.length === 0 ||
  34. this.current.database.startsWith('[logstash-]')
  35. ) {
  36. const def: any = _.find(this.indexPatternTypes, {
  37. value: this.current.jsonData.interval,
  38. });
  39. this.current.database = def.example || 'es-index-name';
  40. }
  41. }
  42. }