logstash-core 5.6.16-java → 6.0.0.alpha1-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (156) hide show
  1. checksums.yaml +4 -4
  2. data/gemspec_jars.rb +4 -7
  3. data/lib/logstash-core/logstash-core.jar +0 -0
  4. data/lib/logstash-core/version.rb +4 -8
  5. data/lib/logstash-core_jars.rb +12 -26
  6. data/lib/logstash/agent.rb +261 -246
  7. data/lib/logstash/api/commands/default_metadata.rb +1 -1
  8. data/lib/logstash/api/commands/hot_threads_reporter.rb +5 -11
  9. data/lib/logstash/api/commands/node.rb +3 -2
  10. data/lib/logstash/api/commands/stats.rb +3 -2
  11. data/lib/logstash/bootstrap_check/bad_java.rb +16 -0
  12. data/lib/logstash/bootstrap_check/bad_ruby.rb +12 -0
  13. data/lib/logstash/bootstrap_check/default_config.rb +17 -0
  14. data/lib/logstash/compiler.rb +38 -0
  15. data/lib/logstash/compiler/lscl.rb +566 -0
  16. data/lib/logstash/compiler/lscl/lscl_grammar.rb +3503 -0
  17. data/lib/logstash/compiler/treetop_monkeypatches.rb +92 -0
  18. data/lib/logstash/config/config_ast.rb +4 -82
  19. data/lib/logstash/config/mixin.rb +73 -41
  20. data/lib/logstash/config/pipeline_config.rb +48 -0
  21. data/lib/logstash/config/source/base.rb +16 -0
  22. data/lib/logstash/config/source/local.rb +215 -0
  23. data/lib/logstash/config/source_loader.rb +125 -0
  24. data/lib/logstash/converge_result.rb +103 -0
  25. data/lib/logstash/environment.rb +6 -19
  26. data/lib/logstash/errors.rb +2 -0
  27. data/lib/logstash/execution_context.rb +4 -7
  28. data/lib/logstash/filter_delegator.rb +6 -9
  29. data/lib/logstash/inputs/base.rb +0 -2
  30. data/lib/logstash/instrument/collector.rb +5 -7
  31. data/lib/logstash/instrument/metric_store.rb +12 -12
  32. data/lib/logstash/instrument/metric_type/mean.rb +0 -5
  33. data/lib/logstash/instrument/namespaced_metric.rb +0 -4
  34. data/lib/logstash/instrument/namespaced_null_metric.rb +0 -4
  35. data/lib/logstash/instrument/null_metric.rb +0 -10
  36. data/lib/logstash/instrument/periodic_poller/cgroup.rb +85 -168
  37. data/lib/logstash/instrument/periodic_poller/jvm.rb +5 -5
  38. data/lib/logstash/instrument/periodic_poller/pq.rb +3 -7
  39. data/lib/logstash/instrument/periodic_pollers.rb +1 -3
  40. data/lib/logstash/instrument/wrapped_write_client.rb +24 -33
  41. data/lib/logstash/logging/logger.rb +15 -47
  42. data/lib/logstash/namespace.rb +0 -1
  43. data/lib/logstash/output_delegator.rb +5 -7
  44. data/lib/logstash/outputs/base.rb +0 -2
  45. data/lib/logstash/pipeline.rb +159 -87
  46. data/lib/logstash/pipeline_action.rb +13 -0
  47. data/lib/logstash/pipeline_action/base.rb +29 -0
  48. data/lib/logstash/pipeline_action/create.rb +47 -0
  49. data/lib/logstash/pipeline_action/reload.rb +48 -0
  50. data/lib/logstash/pipeline_action/stop.rb +23 -0
  51. data/lib/logstash/plugin.rb +0 -1
  52. data/lib/logstash/plugins/hooks_registry.rb +6 -0
  53. data/lib/logstash/plugins/registry.rb +0 -1
  54. data/lib/logstash/program.rb +14 -0
  55. data/lib/logstash/queue_factory.rb +5 -1
  56. data/lib/logstash/runner.rb +58 -80
  57. data/lib/logstash/settings.rb +3 -27
  58. data/lib/logstash/state_resolver.rb +41 -0
  59. data/lib/logstash/util/java_version.rb +6 -0
  60. data/lib/logstash/util/safe_uri.rb +12 -148
  61. data/lib/logstash/util/thread_dump.rb +4 -7
  62. data/lib/logstash/util/wrapped_acked_queue.rb +36 -39
  63. data/lib/logstash/util/wrapped_synchronous_queue.rb +29 -39
  64. data/lib/logstash/version.rb +10 -8
  65. data/locales/en.yml +3 -54
  66. data/logstash-core.gemspec +8 -35
  67. data/spec/{logstash/api/modules → api/lib/api}/logging_spec.rb +10 -1
  68. data/spec/{logstash/api/modules → api/lib/api}/node_plugins_spec.rb +2 -1
  69. data/spec/{logstash/api/modules → api/lib/api}/node_spec.rb +3 -3
  70. data/spec/{logstash/api/modules → api/lib/api}/node_stats_spec.rb +3 -7
  71. data/spec/{logstash/api/modules → api/lib/api}/plugins_spec.rb +3 -4
  72. data/spec/{logstash/api/modules → api/lib/api}/root_spec.rb +2 -2
  73. data/spec/api/lib/api/support/resource_dsl_methods.rb +87 -0
  74. data/spec/{logstash/api/commands/stats_spec.rb → api/lib/commands/stats.rb} +2 -7
  75. data/spec/{logstash/api → api/lib}/errors_spec.rb +1 -1
  76. data/spec/{logstash/api → api/lib}/rack_app_spec.rb +0 -0
  77. data/spec/api/spec_helper.rb +106 -0
  78. data/spec/logstash/agent/converge_spec.rb +286 -0
  79. data/spec/logstash/agent/metrics_spec.rb +244 -0
  80. data/spec/logstash/agent_spec.rb +213 -225
  81. data/spec/logstash/compiler/compiler_spec.rb +584 -0
  82. data/spec/logstash/config/config_ast_spec.rb +8 -47
  83. data/spec/logstash/config/mixin_spec.rb +2 -42
  84. data/spec/logstash/config/pipeline_config_spec.rb +75 -0
  85. data/spec/logstash/config/source/local_spec.rb +395 -0
  86. data/spec/logstash/config/source_loader_spec.rb +122 -0
  87. data/spec/logstash/converge_result_spec.rb +179 -0
  88. data/spec/logstash/event_spec.rb +0 -66
  89. data/spec/logstash/execution_context_spec.rb +8 -12
  90. data/spec/logstash/filter_delegator_spec.rb +12 -24
  91. data/spec/logstash/inputs/base_spec.rb +7 -5
  92. data/spec/logstash/instrument/periodic_poller/cgroup_spec.rb +92 -225
  93. data/spec/logstash/instrument/periodic_poller/jvm_spec.rb +1 -1
  94. data/spec/logstash/instrument/periodic_poller/os_spec.rb +32 -29
  95. data/spec/logstash/instrument/wrapped_write_client_spec.rb +33 -33
  96. data/spec/logstash/legacy_ruby_event_spec.rb +13 -4
  97. data/spec/logstash/output_delegator_spec.rb +11 -20
  98. data/spec/logstash/outputs/base_spec.rb +7 -5
  99. data/spec/logstash/pipeline_action/create_spec.rb +83 -0
  100. data/spec/logstash/pipeline_action/reload_spec.rb +83 -0
  101. data/spec/logstash/pipeline_action/stop_spec.rb +37 -0
  102. data/spec/logstash/pipeline_pq_file_spec.rb +1 -1
  103. data/spec/logstash/pipeline_spec.rb +81 -137
  104. data/spec/logstash/plugin_spec.rb +2 -1
  105. data/spec/logstash/plugins/hooks_registry_spec.rb +6 -0
  106. data/spec/logstash/queue_factory_spec.rb +13 -1
  107. data/spec/logstash/runner_spec.rb +29 -140
  108. data/spec/logstash/settings/writable_directory_spec.rb +10 -13
  109. data/spec/logstash/settings_spec.rb +0 -91
  110. data/spec/logstash/state_resolver_spec.rb +156 -0
  111. data/spec/logstash/timestamp_spec.rb +2 -6
  112. data/spec/logstash/util/java_version_spec.rb +22 -0
  113. data/spec/logstash/util/safe_uri_spec.rb +0 -56
  114. data/spec/logstash/util/wrapped_synchronous_queue_spec.rb +22 -0
  115. data/spec/support/helpers.rb +9 -11
  116. data/spec/support/matchers.rb +96 -6
  117. data/spec/support/mocks_classes.rb +80 -0
  118. data/spec/support/shared_contexts.rb +2 -27
  119. metadata +100 -149
  120. data/lib/logstash/config/loader.rb +0 -107
  121. data/lib/logstash/config/modules_common.rb +0 -103
  122. data/lib/logstash/config/source/modules.rb +0 -55
  123. data/lib/logstash/config/string_escape.rb +0 -27
  124. data/lib/logstash/dependency_report.rb +0 -131
  125. data/lib/logstash/dependency_report_runner.rb +0 -17
  126. data/lib/logstash/elasticsearch_client.rb +0 -142
  127. data/lib/logstash/instrument/global_metrics.rb +0 -13
  128. data/lib/logstash/instrument/periodic_poller/dlq.rb +0 -24
  129. data/lib/logstash/modules/cli_parser.rb +0 -74
  130. data/lib/logstash/modules/elasticsearch_config.rb +0 -22
  131. data/lib/logstash/modules/elasticsearch_importer.rb +0 -37
  132. data/lib/logstash/modules/elasticsearch_resource.rb +0 -10
  133. data/lib/logstash/modules/file_reader.rb +0 -36
  134. data/lib/logstash/modules/kibana_base.rb +0 -24
  135. data/lib/logstash/modules/kibana_client.rb +0 -124
  136. data/lib/logstash/modules/kibana_config.rb +0 -105
  137. data/lib/logstash/modules/kibana_dashboards.rb +0 -36
  138. data/lib/logstash/modules/kibana_importer.rb +0 -17
  139. data/lib/logstash/modules/kibana_resource.rb +0 -10
  140. data/lib/logstash/modules/kibana_settings.rb +0 -40
  141. data/lib/logstash/modules/logstash_config.rb +0 -120
  142. data/lib/logstash/modules/resource_base.rb +0 -38
  143. data/lib/logstash/modules/scaffold.rb +0 -52
  144. data/lib/logstash/modules/settings_merger.rb +0 -23
  145. data/lib/logstash/modules/util.rb +0 -17
  146. data/lib/logstash/util/dead_letter_queue_manager.rb +0 -61
  147. data/lib/logstash/util/environment_variables.rb +0 -43
  148. data/spec/logstash/config/loader_spec.rb +0 -38
  149. data/spec/logstash/config/string_escape_spec.rb +0 -24
  150. data/spec/logstash/instrument/periodic_poller/dlq_spec.rb +0 -17
  151. data/spec/logstash/modules/logstash_config_spec.rb +0 -56
  152. data/spec/logstash/modules/scaffold_spec.rb +0 -234
  153. data/spec/logstash/pipeline_dlq_commit_spec.rb +0 -109
  154. data/spec/logstash/settings/splittable_string_array_spec.rb +0 -51
  155. data/spec/logstash/util/wrapped_acked_queue_spec.rb +0 -49
  156. data/versions-gem-copy.yml +0 -12
@@ -1,13 +0,0 @@
1
- class GlobalMetrics
2
- class Stats(metric)
3
- @metric = metric
4
- end
5
-
6
- def initialize(metric)
7
- @metric = metric
8
-
9
- @pipeline_reloads = metric.namespace([:stats, :pipelines])
10
- end
11
-
12
-
13
- end
@@ -1,24 +0,0 @@
1
- # encoding: utf-8
2
- require 'logstash/instrument/periodic_poller/base'
3
-
4
- module LogStash module Instrument module PeriodicPoller
5
- class DeadLetterQueue < Base
6
- def initialize(metric, agent, options = {})
7
- super(metric, options)
8
- @metric = metric
9
- @agent = agent
10
- end
11
-
12
- def collect
13
- pipelines = @agent.get_running_user_defined_pipelines
14
- unless pipelines.nil?
15
- pipelines.each {|_, pipeline|
16
- unless pipeline.nil?
17
- pipeline.collect_dlq_stats
18
- end
19
- }
20
- end
21
- end
22
- end
23
- end end end
24
-
@@ -1,74 +0,0 @@
1
- # encoding: utf-8
2
- require "logstash/namespace"
3
- require "logstash/logging"
4
- require "logstash/errors"
5
-
6
- module LogStash module Modules class CLIParser
7
- include LogStash::Util::Loggable
8
-
9
- attr_reader :output
10
- def initialize(module_names, module_variables)
11
- @output = []
12
- # The #compact here catches instances when module_variables may be nil or
13
- # [nil] and sets it to []
14
- parse_it(module_names, Array(module_variables).compact)
15
- end
16
-
17
- def parse_modules(module_list)
18
- parsed_modules = []
19
- module_list.each do |module_value|
20
- # Calling --modules but not filling it results in [nil], so skip that.
21
- next if module_value.nil?
22
- # Catch if --modules was launched empty but an option/flag (-something)
23
- # follows immediately after
24
- if module_value.start_with?('-')
25
- raise LogStash::ConfigLoadingError, I18n.t("logstash.modules.configuration.modules-invalid-name", :module_name => module_value)
26
- end
27
- parsed_modules.concat module_value.split(',')
28
- end
29
- parsed_modules
30
- end
31
-
32
- def get_kv(module_name, unparsed)
33
- # Ensure that there is at least 1 equals sign in our variable string
34
- # Using String#partition to split on the first '='
35
- # This hackery is to catch the possibility of an equals (`=`) sign
36
- # in a passphrase, which might result in an incomplete key. The
37
- # portion before the first `=` should always be the key, leaving
38
- # the rest to be the value
39
- k, op, rest = unparsed.partition('=')
40
- if rest.size.zero?
41
- raise LogStash::ConfigLoadingError, I18n.t("logstash.modules.configuration.modules-variables-malformed", :rawvar => (module_name + '.' + unparsed))
42
- end
43
- return k.strip, rest.strip
44
- end
45
-
46
- def name_splitter(unparsed)
47
- # It must have at least `modulename.something`
48
- module_name, dot, rest = unparsed.partition('.')
49
- if rest.count('.') >= 1
50
- return module_name, rest
51
- else
52
- raise LogStash::ConfigLoadingError, I18n.t("logstash.modules.configuration.modules-variables-malformed", :rawvar => unparsed)
53
- end
54
- end
55
-
56
- def parse_vars(module_name, vars_list)
57
- module_hash = {"name" => module_name}
58
- vars_list.each do |unparsed|
59
- extracted_name, modvar = name_splitter(unparsed)
60
- next if extracted_name != module_name
61
- k, v = get_kv(extracted_name, modvar)
62
- module_hash[k] = v
63
- end
64
- module_hash
65
- end
66
-
67
- def parse_it(module_list, module_variable_list)
68
- if module_list.is_a?(Array)
69
- parse_modules(module_list).each do |module_name|
70
- @output << parse_vars(module_name, module_variable_list)
71
- end
72
- end
73
- end
74
- end end end
@@ -1,22 +0,0 @@
1
- # encoding: utf-8
2
- require "logstash/namespace"
3
- require "logstash/logging"
4
-
5
- require_relative "elasticsearch_resource"
6
-
7
- module LogStash module Modules class ElasticsearchConfig
8
- attr_reader :index_name
9
-
10
- # We name it `modul` here because `module` has meaning in Ruby.
11
- def initialize(modul, settings)
12
- @directory = ::File.join(modul.directory, "elasticsearch")
13
- @name = modul.module_name
14
- @settings = settings
15
- @full_path = ::File.join(@directory, "#{@name}.json")
16
- @index_name = @settings.fetch("elasticsearch.template_path", "_template")
17
- end
18
-
19
- def resources
20
- [ElasticsearchResource.new(@index_name, "not-used", @full_path)]
21
- end
22
- end end end
@@ -1,37 +0,0 @@
1
- # encoding: utf-8
2
- require "logstash/namespace"
3
- require "logstash/logging"
4
-
5
- module LogStash module Modules class ElasticsearchImporter
6
- include LogStash::Util::Loggable
7
-
8
- def initialize(client)
9
- @client = client
10
- end
11
-
12
- def put(resource, overwrite = true)
13
- path = resource.import_path
14
- logger.debug("Attempting PUT", :url_path => path, :file_path => resource.content_path)
15
- if !overwrite && content_exists?(path)
16
- logger.debug("Found existing Elasticsearch resource.", :resource => path)
17
- return
18
- end
19
- put_overwrite(path, resource.content)
20
- end
21
-
22
- private
23
-
24
- def put_overwrite(path, content)
25
- if content_exists?(path)
26
- response = @client.delete(path)
27
- end
28
- # hmmm, versioning?
29
- @client.put(path, content).status == 201
30
- end
31
-
32
- def content_exists?(path)
33
- response = @client.head(path)
34
- response.status >= 200 && response.status < 300
35
- end
36
-
37
- end end end # class LogStash::Modules::Importer
@@ -1,10 +0,0 @@
1
- # encoding: utf-8
2
- require "logstash/namespace"
3
- require_relative "resource_base"
4
-
5
- module LogStash module Modules class ElasticsearchResource
6
- include ResourceBase
7
- def import_path
8
- base + "/" + content_id
9
- end
10
- end end end
@@ -1,36 +0,0 @@
1
- # encoding: utf-8
2
- require "logstash/namespace"
3
- require "logstash/logging"
4
- require "logstash/json"
5
-
6
- module LogStash module Modules class FileReader
7
- # stub these methods for testing
8
- include LogStash::Util::Loggable
9
-
10
- def self.read(path)
11
- begin
12
- ::File.read(path)
13
- rescue => e
14
- logger.error("Error when reading file from path", :path => path)
15
- ""
16
- end
17
- end
18
-
19
- def self.read_json(path)
20
- json = read(path)
21
- begin
22
- LogStash::Json.load(json)
23
- rescue => e
24
- logger.error("Error when parsing json from path", :path => path)
25
- return {}
26
- end
27
- end
28
-
29
- def self.glob(path)
30
- files = Dir.glob(path)
31
- if files.empty?
32
- logger.warn("No files found for glob", :pattern => path)
33
- end
34
- files
35
- end
36
- end end end
@@ -1,24 +0,0 @@
1
- # encoding: utf-8
2
- require "logstash/namespace"
3
- require "logstash/json"
4
-
5
- module LogStash module Modules class KibanaBase
6
- attr_reader :import_path, :content
7
-
8
- def initialize(import_path, content)
9
- @import_path, @content = import_path, content
10
- end
11
-
12
- def import(client)
13
- raise NotImplementedError, "#{self.class.name} needs to implement `#import`"
14
- end
15
-
16
- def to_s
17
- import_path
18
- end
19
-
20
- def content_as_object
21
- return content unless content.is_a?(String)
22
- LogStash::Json.load(content) rescue nil
23
- end
24
- end end end
@@ -1,124 +0,0 @@
1
- # encoding: utf-8
2
- require "logstash/namespace"
3
- require "logstash/logging"
4
- require "logstash/json"
5
- require "manticore/client"
6
-
7
- module LogStash module Modules class KibanaClient
8
- include LogStash::Util::Loggable
9
-
10
- class Response
11
- # to create a custom response with body as an Object (Hash or Array)
12
- attr_reader :status, :body, :headers
13
- def initialize(status, body, headers={})
14
- @status, @body, @headers = status, body, headers
15
- @body = body.is_a?(String) ? LogStash::Json.load(body) : body
16
- end
17
-
18
- def succeeded?
19
- @status >= 200 && @status < 300
20
- end
21
-
22
- def failed?
23
- !succeeded?
24
- end
25
- end
26
-
27
- attr_reader :version
28
-
29
- def initialize(settings)
30
- @settings = settings
31
-
32
- client_options = {
33
- request_timeout: 5,
34
- connect_timeout: 5,
35
- socket_timeout: 5,
36
- pool_max: 10,
37
- pool_max_per_route: 2
38
- }
39
-
40
- ssl_options = {}
41
-
42
- if @settings["var.kibana.ssl.enabled"] == "true"
43
- ssl_options[:verify] = @settings.fetch("var.kibana.ssl.verification_mode", "strict").to_sym
44
- ssl_options[:ca_file] = @settings.fetch("var.kibana.ssl.certificate_authority", nil)
45
- ssl_options[:client_cert] = @settings.fetch("var.kibana.ssl.certificate", nil)
46
- ssl_options[:client_key] = @settings.fetch("var.kibana.ssl.key", nil)
47
- end
48
-
49
- client_options[:ssl] = ssl_options
50
-
51
- @client = Manticore::Client.new(client_options)
52
- @host = @settings.fetch("var.kibana.host", "localhost:5601")
53
- username = @settings["var.kibana.username"]
54
- password = @settings["var.kibana.password"]
55
-
56
- @scheme = @settings.fetch("var.kibana.scheme", "http")
57
- @http_options = {:headers => {'Content-Type' => 'application/json'}}
58
- if username
59
- @http_options[:headers]['Authorization'] = 'Basic ' + Base64.encode64( "#{username}:#{password}" ).chomp
60
- end
61
-
62
- # e.g. {"name":"Elastics-MacBook-Pro.local","version":{"number":"6.0.0-alpha3","build_hash":"41e69","build_number":15613,"build_snapshot":true}..}
63
- @version = "0.0.0"
64
- response = get("api/status")
65
- if response.succeeded?
66
- status = response.body
67
- if status["version"].is_a?(Hash)
68
- @version = status["version"]["number"]
69
- if status["version"]["build_snapshot"]
70
- @version.concat("-SNAPSHOT")
71
- end
72
- else
73
- @version = status["version"]
74
- end
75
- end
76
- @http_options[:headers]['kbn-version'] = @version
77
- end
78
-
79
- def version_parts
80
- @version.split(/\.|\-/)
81
- end
82
-
83
- def host_settings
84
- "[\"#{@host}\"]"
85
- end
86
-
87
- def get(relative_path)
88
- # e.g. api/kibana/settings
89
- safely(:get, relative_path, @http_options)
90
- end
91
-
92
- # content will be converted to a json string
93
- def post(relative_path, content, headers = nil)
94
-
95
- body = content.is_a?(String) ? content : LogStash::Json.dump(content)
96
- options = {:body => body}.merge(headers || @http_options)
97
- safely(:post, relative_path, options)
98
- end
99
-
100
- def head(relative_path)
101
- safely(:head, relative_path, @http_options)
102
- end
103
-
104
- def can_connect?
105
- head("api/status").succeeded?
106
- end
107
-
108
- private
109
-
110
- def safely(method_sym, relative_path, options = {})
111
- begin
112
- resp = @client.http(method_sym, full_url(relative_path), options).call
113
- Response.new(resp.code, resp.body, resp.headers)
114
- rescue Manticore::ManticoreException => e
115
- logger.error("Error when executing Kibana client request", :error => e)
116
- body = {"statusCode" => 0, "error" => e.message}
117
- Response.new(0, body, {})
118
- end
119
- end
120
-
121
- def full_url(relative)
122
- "#{@scheme}://#{@host}/#{relative}"
123
- end
124
- end end end
@@ -1,105 +0,0 @@
1
- # encoding: utf-8
2
- require "logstash/namespace"
3
- require "logstash/logging"
4
-
5
- require_relative "file_reader"
6
- require_relative "kibana_settings"
7
- require_relative "kibana_dashboards"
8
- require_relative "kibana_resource"
9
-
10
- module LogStash module Modules class KibanaConfig
11
- include LogStash::Util::Loggable
12
-
13
- ALLOWED_DIRECTORIES = ["search", "visualization"]
14
- attr_reader :index_name # not used when importing via kibana but for BWC with ElastsearchConfig
15
-
16
- # We name it `modul` here because `module` has meaning in Ruby.
17
- def initialize(modul, settings)
18
- @directory = ::File.join(modul.directory, "kibana")
19
- @name = modul.module_name
20
- @settings = settings
21
- @index_name = "kibana"
22
- @pattern_name = "#{@name}-*"
23
- @kibana_settings = [
24
- KibanaSettings::Setting.new("defaultIndex", @pattern_name)
25
- ]
26
- end
27
-
28
- def dashboards
29
- # there can be more than one dashboard to load
30
- filenames = FileReader.read_json(dynamic("dashboard"))
31
- filenames.map do |filename|
32
- KibanaResource.new(@index_name, "dashboard", dynamic("dashboard", filename))
33
- end
34
- end
35
-
36
- def index_pattern
37
- [KibanaResource.new(@index_name, "index-pattern", dynamic("index-pattern"),nil, @pattern_name)]
38
- end
39
-
40
- def resources
41
- list = index_pattern
42
- dashboards.each do |board|
43
- list << board
44
- extract_panels_into(board, list)
45
- end
46
- list.concat(extract_saved_searches_into(list))
47
- [
48
- KibanaSettings.new("api/kibana/settings", @kibana_settings),
49
- KibanaDashboards.new("api/kibana/dashboards/import", list)
50
- ]
51
- end
52
-
53
- private
54
-
55
- def dynamic(dynamic_folder, filename = @name)
56
- ::File.join(@directory, dynamic_folder, "#{filename}.json")
57
- end
58
-
59
- def extract_panels_into(dashboard, list)
60
- dash = dashboard.content_as_object
61
-
62
- if !dash.is_a?(Hash)
63
- logger.warn("Kibana dashboard JSON is not an Object", :module => @name)
64
- return
65
- end
66
-
67
- panelsjson = dash["panelsJSON"]
68
-
69
- if panelsjson.nil?
70
- logger.info("No panelJSON key found in kibana dashboard", :module => @name)
71
- return
72
- end
73
-
74
- begin
75
- panels = LogStash::Json.load(panelsjson)
76
- rescue => e
77
- logger.error("JSON parse error when reading kibana panelsJSON", :module => @name)
78
- return
79
- end
80
-
81
- panels.each do |panel|
82
- panel_type = panel["type"]
83
- if ALLOWED_DIRECTORIES.member?(panel_type)
84
- list << KibanaResource.new(@index_name, panel_type, dynamic(panel_type, panel["id"]))
85
- else
86
- logger.warn("panelJSON contained unknown type", :type => panel_type)
87
- end
88
- end
89
- end
90
-
91
- def extract_saved_searches_into(list)
92
- result = [] # must not add to list while iterating
93
- list.each do |resource|
94
- content = resource.content_as_object
95
- next if content.nil?
96
- next unless content.keys.include?("savedSearchId")
97
- saved_search = content["savedSearchId"]
98
- next if saved_search.nil?
99
- ss_resource = KibanaResource.new(@index_name, "search", dynamic("search", saved_search))
100
- next if list.member?(ss_resource) || result.member?(ss_resource)
101
- result << ss_resource
102
- end
103
- result
104
- end
105
- end end end