logstash-core 2.4.1-java → 5.0.0.alpha1-java

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of logstash-core might be problematic. Click here for more details.

Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/lib/logstash-core/version.rb +1 -1
  3. data/lib/logstash/agent.rb +124 -411
  4. data/lib/logstash/api/init.ru +31 -0
  5. data/lib/logstash/api/lib/app.rb +40 -0
  6. data/lib/logstash/api/lib/app/command.rb +29 -0
  7. data/lib/logstash/api/lib/app/command_factory.rb +29 -0
  8. data/lib/logstash/api/lib/app/commands/stats/events_command.rb +13 -0
  9. data/lib/logstash/api/lib/app/commands/stats/hotthreads_command.rb +120 -0
  10. data/lib/logstash/api/lib/app/commands/stats/memory_command.rb +25 -0
  11. data/lib/logstash/api/lib/app/commands/system/basicinfo_command.rb +15 -0
  12. data/lib/logstash/api/lib/app/commands/system/plugins_command.rb +28 -0
  13. data/lib/logstash/api/lib/app/modules/node.rb +25 -0
  14. data/lib/logstash/api/lib/app/modules/node_stats.rb +51 -0
  15. data/lib/logstash/api/lib/app/modules/plugins.rb +15 -0
  16. data/lib/logstash/api/lib/app/modules/stats.rb +21 -0
  17. data/lib/logstash/api/lib/app/root.rb +13 -0
  18. data/lib/logstash/api/lib/app/service.rb +61 -0
  19. data/lib/logstash/api/lib/app/stats.rb +56 -0
  20. data/lib/logstash/api/lib/helpers/app_helpers.rb +23 -0
  21. data/lib/logstash/codecs/base.rb +1 -29
  22. data/lib/logstash/config/config_ast.rb +18 -31
  23. data/lib/logstash/config/loader.rb +3 -5
  24. data/lib/logstash/config/mixin.rb +25 -64
  25. data/lib/logstash/filter_delegator.rb +65 -0
  26. data/lib/logstash/inputs/base.rb +1 -1
  27. data/lib/logstash/inputs/metrics.rb +47 -0
  28. data/lib/logstash/instrument/collector.rb +109 -0
  29. data/lib/logstash/instrument/metric.rb +102 -0
  30. data/lib/logstash/instrument/metric_store.rb +228 -0
  31. data/lib/logstash/instrument/metric_type.rb +24 -0
  32. data/lib/logstash/instrument/metric_type/base.rb +35 -0
  33. data/lib/logstash/instrument/metric_type/counter.rb +29 -0
  34. data/lib/logstash/instrument/metric_type/gauge.rb +22 -0
  35. data/lib/logstash/instrument/metric_type/mean.rb +33 -0
  36. data/lib/logstash/instrument/namespaced_metric.rb +54 -0
  37. data/lib/logstash/instrument/null_metric.rb +4 -3
  38. data/lib/logstash/instrument/periodic_poller/base.rb +57 -0
  39. data/lib/logstash/instrument/periodic_poller/jvm.rb +92 -0
  40. data/lib/logstash/instrument/periodic_poller/os.rb +13 -0
  41. data/lib/logstash/instrument/periodic_poller/periodic_poller_observer.rb +19 -0
  42. data/lib/logstash/instrument/periodic_pollers.rb +26 -0
  43. data/lib/logstash/instrument/snapshot.rb +16 -0
  44. data/lib/logstash/json.rb +2 -3
  45. data/lib/logstash/namespace.rb +1 -0
  46. data/lib/logstash/output_delegator.rb +16 -3
  47. data/lib/logstash/outputs/base.rb +1 -32
  48. data/lib/logstash/pipeline.rb +67 -8
  49. data/lib/logstash/plugin.rb +57 -19
  50. data/lib/logstash/runner.rb +348 -84
  51. data/lib/logstash/util.rb +9 -0
  52. data/lib/logstash/util/duration_formatter.rb +15 -0
  53. data/lib/logstash/util/java_version.rb +2 -4
  54. data/lib/logstash/util/loggable.rb +29 -0
  55. data/lib/logstash/version.rb +1 -1
  56. data/lib/logstash/webserver.rb +98 -0
  57. data/locales/en.yml +42 -24
  58. data/logstash-core.gemspec +9 -6
  59. data/spec/api/lib/api/node_spec.rb +64 -0
  60. data/spec/api/lib/api/node_stats_spec.rb +68 -0
  61. data/spec/api/lib/api/plugins_spec.rb +57 -0
  62. data/spec/api/lib/api/root_spec.rb +20 -0
  63. data/spec/api/lib/api/stats_spec.rb +19 -0
  64. data/spec/api/lib/commands/events_spec.rb +17 -0
  65. data/spec/api/lib/commands/jvm_spec.rb +45 -0
  66. data/spec/api/spec_helper.rb +128 -0
  67. data/spec/logstash/agent_spec.rb +62 -169
  68. data/spec/logstash/config/config_ast_spec.rb +2 -47
  69. data/spec/logstash/config/mixin_spec.rb +0 -157
  70. data/spec/logstash/filter_delegator_spec.rb +143 -0
  71. data/spec/logstash/inputs/metrics_spec.rb +52 -0
  72. data/spec/logstash/instrument/collector_spec.rb +49 -0
  73. data/spec/logstash/instrument/metric_spec.rb +110 -0
  74. data/spec/logstash/instrument/metric_store_spec.rb +163 -0
  75. data/spec/logstash/instrument/metric_type/counter_spec.rb +40 -0
  76. data/spec/logstash/instrument/metric_type/gauge_spec.rb +40 -0
  77. data/spec/logstash/instrument/namespaced_metric_spec.rb +25 -0
  78. data/spec/logstash/instrument/null_metric_spec.rb +9 -51
  79. data/spec/logstash/json_spec.rb +14 -0
  80. data/spec/logstash/output_delegator_spec.rb +6 -3
  81. data/spec/logstash/outputs/base_spec.rb +0 -107
  82. data/spec/logstash/pipeline_spec.rb +204 -33
  83. data/spec/logstash/plugin_spec.rb +80 -15
  84. data/spec/logstash/runner_spec.rb +134 -38
  85. data/spec/logstash/shutdown_watcher_spec.rb +0 -1
  86. data/spec/logstash/util/duration_formatter_spec.rb +11 -0
  87. data/spec/logstash/util/java_version_spec.rb +10 -2
  88. data/spec/logstash/util_spec.rb +28 -0
  89. data/spec/support/matchers.rb +30 -0
  90. metadata +154 -20
  91. data/lib/logstash/logging/json.rb +0 -21
  92. data/lib/logstash/special_agent.rb +0 -8
  93. data/lib/logstash/util/safe_uri.rb +0 -50
  94. data/spec/logstash/codecs/base_spec.rb +0 -74
  95. data/spec/static/i18n_spec.rb +0 -25
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+ require "app"
3
+
4
+ module LogStash::Api
5
+ class Root < BaseApp
6
+
7
+ get "/" do
8
+ command = factory.build(:system_basic_info)
9
+ respond_with command.run
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,61 @@
1
+ # encoding: utf-8
2
+ require "logstash/instrument/collector"
3
+ require "logstash/util/loggable"
4
+
5
+ class LogStash::Api::Service
6
+
7
+ include Singleton
8
+ include LogStash::Util::Loggable
9
+
10
+ def initialize
11
+ @snapshot_rotation_mutex = Mutex.new
12
+ @snapshot = nil
13
+ logger.debug("[api-service] start") if logger.debug?
14
+ LogStash::Instrument::Collector.instance.add_observer(self)
15
+ end
16
+
17
+ def stop
18
+ logger.debug("[api-service] stop") if logger.debug?
19
+ LogStash::Instrument::Collector.instance.delete_observer(self)
20
+ end
21
+
22
+ def agent
23
+ LogStash::Instrument::Collector.instance.agent
24
+ end
25
+
26
+ def started?
27
+ !@snapshot.nil? && has_counters?
28
+ end
29
+
30
+ def update(snapshot)
31
+ logger.debug("[api-service] snapshot received", :snapshot => snapshot) if logger.debug?
32
+ if @snapshot_rotation_mutex.try_lock
33
+ @snapshot = snapshot
34
+ @snapshot_rotation_mutex.unlock
35
+ end
36
+ end
37
+
38
+ def get(key)
39
+ metric_store = @snapshot.metric_store
40
+ if key == :jvm_memory_stats
41
+ data = metric_store.get_with_path("jvm/memory")[:jvm][:memory]
42
+ else
43
+ data = metric_store.get_with_path("stats/events")
44
+ end
45
+ LogStash::Json.dump(data)
46
+ end
47
+
48
+ private
49
+
50
+ def has_counters?
51
+ (["LogStash::Instrument::MetricType::Counter", "LogStash::Instrument::MetricType::Gauge"] - metric_types).empty?
52
+ end
53
+
54
+ def metric_types
55
+ types = []
56
+ @snapshot_rotation_mutex.synchronize do
57
+ types = @snapshot.metric_store.all.map { |t| t.class.to_s }
58
+ end
59
+ return types
60
+ end
61
+ end
@@ -0,0 +1,56 @@
1
+ # encoding: utf-8
2
+ require "app"
3
+ require "app/stats/events_command"
4
+ require "app/stats/hotthreads_command"
5
+
6
+ module LogStash::Api
7
+ class Stats < BaseApp
8
+
9
+ helpers AppHelpers
10
+
11
+
12
+ # Global _stats resource where all information is
13
+ # retrieved and show
14
+ get "/" do
15
+ events_command = factory.build(:events_command)
16
+ memory_command = factory.build(:memory_command)
17
+ payload = {
18
+ :events => events_command.run,
19
+ :jvm => { :memory => memory_command.run }
20
+ }
21
+ respond_with payload
22
+ end
23
+
24
+ # Show all events stats information
25
+ # (for ingested, emitted, dropped)
26
+ # - #events since startup
27
+ # - #data (bytes) since startup
28
+ # - events/s
29
+ # - bytes/s
30
+ # - dropped events/s
31
+ # - events in the pipeline
32
+ get "/events" do
33
+ command = factory.build(:events_command)
34
+ respond_with({ :events => command.run })
35
+ end
36
+
37
+ # return hot threads information
38
+ get "/jvm/hot_threads" do
39
+ top_threads_count = params["threads"] || 3
40
+ ignore_idle_threads = params["ignore_idle_threads"] || true
41
+ options = {
42
+ :threads => top_threads_count.to_i,
43
+ :ignore_idle_threads => as_boolean(ignore_idle_threads)
44
+ }
45
+ command = factory.build(:hot_threads_command)
46
+ respond_with(command.run(options), :string)
47
+ end
48
+
49
+ # return hot threads information
50
+ get "/jvm/memory" do
51
+ command = factory.build(:memory_command)
52
+ respond_with({ :memory => command.run })
53
+ end
54
+
55
+ end
56
+ end
@@ -0,0 +1,23 @@
1
+ # encoding: utf-8
2
+ require "logstash/json"
3
+
4
+ module LogStash::Api::AppHelpers
5
+
6
+ def respond_with(data, options={})
7
+ as = options.fetch(:as, :json)
8
+ pretty = params.has_key?("pretty")
9
+ if as == :json
10
+ content_type "application/json"
11
+ LogStash::Json.dump(data, {:pretty => pretty})
12
+ else
13
+ content_type "text/plain"
14
+ data.to_s
15
+ end
16
+ end
17
+
18
+ def as_boolean(string)
19
+ return true if string == true || string =~ (/(true|t|yes|y|1)$/i)
20
+ return false if string == false || string.blank? || string =~ (/(false|f|no|n|0)$/i)
21
+ raise ArgumentError.new("invalid value for Boolean: \"#{string}\"")
22
+ end
23
+ end
@@ -13,7 +13,6 @@ module LogStash::Codecs; class Base < LogStash::Plugin
13
13
  super
14
14
  config_init(@params)
15
15
  register if respond_to?(:register)
16
- setup_multi_encode!
17
16
  end
18
17
 
19
18
  public
@@ -24,37 +23,10 @@ module LogStash::Codecs; class Base < LogStash::Plugin
24
23
  alias_method :<<, :decode
25
24
 
26
25
  public
27
- # DEPRECATED: Prefer defining encode_sync or multi_encode
28
26
  def encode(event)
29
- encoded = multi_encode([event])
30
- encoded.each {|event,data| @on_event.call(event,data) }
27
+ raise "#{self.class}#encode must be overidden"
31
28
  end # def encode
32
29
 
33
- public
34
- # Relies on the codec being synchronous (which they all are!)
35
- # We need a better long term design here, but this is an improvement
36
- # over the current API for shared plugins
37
- # It is best if the codec implements this directly
38
- def multi_encode(events)
39
- if @has_encode_sync
40
- events.map {|event| [event, self.encode_sync(event)]}
41
- else
42
- batch = Thread.current[:logstash_output_codec_batch] ||= []
43
- batch.clear
44
-
45
- events.each {|event| self.encode(event) }
46
- batch
47
- end
48
- end
49
-
50
- def setup_multi_encode!
51
- @has_encode_sync = self.methods.include?(:encode_sync)
52
-
53
- on_event do |event, data|
54
- Thread.current[:logstash_output_codec_batch] << [event, data]
55
- end
56
- end
57
-
58
30
  public
59
31
  def close; end;
60
32
 
@@ -76,14 +76,6 @@ module LogStash; module Config; module AST
76
76
  @defered_conditionals_index = val
77
77
  end
78
78
 
79
- def self.plugin_instance_index
80
- @plugin_instance_index
81
- end
82
-
83
- def self.plugin_instance_index=(val)
84
- @plugin_instance_index = val
85
- end
86
-
87
79
  class Node < Treetop::Runtime::SyntaxNode
88
80
  def text_value_for_comments
89
81
  text_value.gsub(/[\r\n]/, " ")
@@ -94,7 +86,6 @@ module LogStash; module Config; module AST
94
86
  def compile
95
87
  LogStash::Config::AST.defered_conditionals = []
96
88
  LogStash::Config::AST.defered_conditionals_index = 0
97
- LogStash::Config::AST.plugin_instance_index = 0
98
89
  code = []
99
90
 
100
91
  code << <<-CODE
@@ -103,7 +94,6 @@ module LogStash; module Config; module AST
103
94
  @outputs = []
104
95
  @periodic_flushers = []
105
96
  @shutdown_flushers = []
106
- @generated_objects = {}
107
97
  CODE
108
98
 
109
99
  sections = recursive_select(LogStash::Config::AST::PluginSection)
@@ -147,9 +137,7 @@ module LogStash; module Config; module AST
147
137
  class PluginSection < Node
148
138
  # Global plugin numbering for the janky instance variable naming we use
149
139
  # like @filter_<name>_1
150
- def initialize(*args)
151
- super(*args)
152
- end
140
+ @@i = 0
153
141
 
154
142
  # Generate ruby code to initialize all the plugins.
155
143
  def compile_initializer
@@ -159,31 +147,31 @@ module LogStash; module Config; module AST
159
147
 
160
148
 
161
149
  code << <<-CODE
162
- @generated_objects[:#{name}] = #{plugin.compile_initializer}
163
- @#{plugin.plugin_type}s << @generated_objects[:#{name}]
150
+ #{name} = #{plugin.compile_initializer}
151
+ @#{plugin.plugin_type}s << #{name}
164
152
  CODE
165
153
 
166
154
  # The flush method for this filter.
167
155
  if plugin.plugin_type == "filter"
168
156
 
169
157
  code << <<-CODE
170
- @generated_objects[:#{name}_flush] = lambda do |options, &block|
171
- @logger.debug? && @logger.debug(\"Flushing\", :plugin => @generated_objects[:#{name}])
158
+ #{name}_flush = lambda do |options, &block|
159
+ @logger.debug? && @logger.debug(\"Flushing\", :plugin => #{name})
172
160
 
173
- events = @generated_objects[:#{name}].flush(options)
161
+ events = #{name}.flush(options)
174
162
 
175
163
  return if events.nil? || events.empty?
176
164
 
177
- @logger.debug? && @logger.debug(\"Flushing\", :plugin => @generated_objects[:#{name}], :events => events)
165
+ @logger.debug? && @logger.debug(\"Flushing\", :plugin => #{name}, :events => events)
178
166
 
179
167
  #{plugin.compile_starting_here.gsub(/^/, " ")}
180
168
 
181
169
  events.each{|e| block.call(e)}
182
170
  end
183
171
 
184
- if @generated_objects[:#{name}].respond_to?(:flush)
185
- @periodic_flushers << @generated_objects[:#{name}_flush] if @generated_objects[:#{name}].periodic_flush
186
- @shutdown_flushers << @generated_objects[:#{name}_flush]
172
+ if #{name}.respond_to?(:flush)
173
+ @periodic_flushers << #{name}_flush if #{name}.periodic_flush
174
+ @shutdown_flushers << #{name}_flush
187
175
  end
188
176
  CODE
189
177
 
@@ -204,10 +192,9 @@ module LogStash; module Config; module AST
204
192
 
205
193
  plugins.each do |plugin|
206
194
  # Unique number for every plugin.
207
- LogStash::Config::AST.plugin_instance_index += 1
195
+ @@i += 1
208
196
  # store things as ivars, like @filter_grok_3
209
- var = :"#{plugin.plugin_type}_#{plugin.plugin_name}_#{LogStash::Config::AST.plugin_instance_index}"
210
- # puts("var=#{var.inspect}")
197
+ var = "@#{plugin.plugin_type}_#{plugin.plugin_name}_#{@@i}"
211
198
  @variables[plugin] = var
212
199
  end
213
200
  return @variables
@@ -249,13 +236,13 @@ module LogStash; module Config; module AST
249
236
  def compile
250
237
  case plugin_type
251
238
  when "input"
252
- return "start_input(@generated_objects[:#{variable_name}])"
239
+ return "start_input(#{variable_name})"
253
240
  when "filter"
254
241
  return <<-CODE
255
- events = @generated_objects[:#{variable_name}].multi_filter(events)
242
+ events = #{variable_name}.multi_filter(events)
256
243
  CODE
257
244
  when "output"
258
- return "targeted_outputs << @generated_objects[:#{variable_name}]\n"
245
+ return "targeted_outputs << #{variable_name}\n"
259
246
  when "codec"
260
247
  settings = attributes.recursive_select(Attribute).collect(&:compile).reject(&:empty?)
261
248
  attributes_code = "LogStash::Util.hash_merge_many(#{settings.map { |c| "{ #{c} }" }.join(", ")})"
@@ -357,7 +344,7 @@ module LogStash; module Config; module AST
357
344
 
358
345
  if duplicate_values.size > 0
359
346
  raise ConfigurationError.new(
360
- I18n.t("logstash.agent.configuration.invalid_plugin_settings_duplicate_keys",
347
+ I18n.t("logstash.runner.configuration.invalid_plugin_settings_duplicate_keys",
361
348
  :keys => duplicate_values.join(', '),
362
349
  :line => input.line_of(interval.first),
363
350
  :column => input.column_of(interval.first),
@@ -404,7 +391,7 @@ module LogStash; module Config; module AST
404
391
  if type == "filter"
405
392
  i = LogStash::Config::AST.defered_conditionals_index += 1
406
393
  source = <<-CODE
407
- @generated_objects[:cond_func_#{i}] = lambda do |input_events|
394
+ define_singleton_method :cond_func_#{i} do |input_events|
408
395
  result = []
409
396
  input_events.each do |event|
410
397
  events = [event]
@@ -418,7 +405,7 @@ module LogStash; module Config; module AST
418
405
  LogStash::Config::AST.defered_conditionals << source
419
406
 
420
407
  <<-CODE
421
- events = @generated_objects[:cond_func_#{i}].call(events)
408
+ events = cond_func_#{i}(events)
422
409
  CODE
423
410
  else # Output
424
411
  <<-CODE
@@ -1,8 +1,6 @@
1
1
  require "logstash/config/defaults"
2
2
 
3
3
  module LogStash; module Config; class Loader
4
- attr_accessor :debug_config
5
-
6
4
  def initialize(logger, debug_config=false)
7
5
  @logger = logger
8
6
  @debug_config = debug_config
@@ -40,7 +38,7 @@ module LogStash; module Config; class Loader
40
38
  when "file" then
41
39
  local_config(uri.path)
42
40
  else
43
- fail(I18n.t("logstash.agent.configuration.scheme-not-supported", :path => path))
41
+ fail(I18n.t("logstash.runner.configuration.scheme-not-supported", :path => path))
44
42
  end
45
43
  rescue URI::InvalidURIError
46
44
  # fallback for windows.
@@ -55,7 +53,7 @@ module LogStash; module Config; class Loader
55
53
  path = ::File.join(path, "*") if ::File.directory?(path)
56
54
 
57
55
  if Dir.glob(path).length == 0
58
- fail(I18n.t("logstash.agent.configuration.file-not-found", :path => path))
56
+ fail(I18n.t("logstash.runner.configuration.file-not-found", :path => path))
59
57
  end
60
58
 
61
59
  config = ""
@@ -91,7 +89,7 @@ module LogStash; module Config; class Loader
91
89
  begin
92
90
  Net::HTTP.get(uri) + "\n"
93
91
  rescue Exception => e
94
- fail(I18n.t("logstash.agent.configuration.fetch-failed", :path => uri.to_s, :message => e.message))
92
+ fail(I18n.t("logstash.runner.configuration.fetch-failed", :path => uri.to_s, :message => e.message))
95
93
  end
96
94
  end
97
95
  end end end
@@ -3,7 +3,6 @@ require "logstash/namespace"
3
3
  require "logstash/config/registry"
4
4
  require "logstash/logging"
5
5
  require "logstash/util/password"
6
- require "logstash/util/safe_uri"
7
6
  require "logstash/version"
8
7
  require "logstash/environment"
9
8
  require "logstash/util/plugin_version"
@@ -133,7 +132,7 @@ module LogStash::Config::Mixin
133
132
 
134
133
  if !self.class.validate(params)
135
134
  raise LogStash::ConfigurationError,
136
- I18n.t("logstash.agent.configuration.invalid_plugin_settings")
135
+ I18n.t("logstash.runner.configuration.invalid_plugin_settings")
137
136
  end
138
137
 
139
138
  # We remove any config options marked as obsolete,
@@ -334,89 +333,58 @@ module LogStash::Config::Mixin
334
333
  return true
335
334
  end # def validate_check_invalid_parameter_names
336
335
 
337
- def validate_check_required_parameter(config_key, config_opts, k, v)
338
- if config_key.is_a?(Regexp)
339
- (k =~ config_key && v)
340
- elsif config_key.is_a?(String)
341
- k && v
342
- end
343
- end
344
-
345
336
  def validate_check_required_parameter_names(params)
346
337
  is_valid = true
347
338
 
348
339
  @config.each do |config_key, config|
349
340
  next unless config[:required]
350
341
 
351
- value = params[config_key]
352
-
353
- if config_key.is_a?(Regexp) && !params.keys.any? { |k| k =~ config_key }
354
- is_valid = false
355
- end
356
-
357
- if value.nil? || (config[:list] && Array(value).empty?)
358
- @logger.error(I18n.t("logstash.agent.configuration.setting_missing",
359
- :setting => config_key, :plugin => @plugin_name,
360
- :type => @plugin_type))
361
- is_valid = false
342
+ if config_key.is_a?(Regexp)
343
+ next if params.keys.select { |k| k =~ config_key }.length > 0
344
+ elsif config_key.is_a?(String)
345
+ next if params.keys.member?(config_key)
362
346
  end
347
+ @logger.error(I18n.t("logstash.runner.configuration.setting_missing",
348
+ :setting => config_key, :plugin => @plugin_name,
349
+ :type => @plugin_type))
350
+ is_valid = false
363
351
  end
364
352
 
365
353
  return is_valid
366
354
  end
367
355
 
368
- def process_parameter_value(value, config_settings)
369
- config_val = config_settings[:validate]
370
-
371
- if config_settings[:list]
372
- value = Array(value) # coerce scalars to lists
373
- # Empty lists are converted to nils
374
- return true, nil if value.empty?
375
-
376
- validated_items = value.map {|v| validate_value(v, config_val)}
377
- is_valid = validated_items.all? {|sr| sr[0] }
378
- processed_value = validated_items.map {|sr| sr[1]}
379
- else
380
- is_valid, processed_value = validate_value(value, config_val)
381
- end
382
-
383
- return [is_valid, processed_value]
384
- end
385
-
386
356
  def validate_check_parameter_values(params)
387
357
  # Filter out parametrs that match regexp keys.
388
358
  # These are defined in plugins like this:
389
359
  # config /foo.*/ => ...
390
- all_params_valid = true
360
+ is_valid = true
391
361
 
392
362
  params.each do |key, value|
393
363
  @config.keys.each do |config_key|
394
364
  next unless (config_key.is_a?(Regexp) && key =~ config_key) \
395
365
  || (config_key.is_a?(String) && key == config_key)
396
-
397
- config_settings = @config[config_key]
398
-
399
- is_valid, processed_value = process_parameter_value(value, config_settings)
400
-
401
- if is_valid
402
- # Accept coerced value if valid
366
+ config_val = @config[config_key][:validate]
367
+ #puts " Key matches."
368
+ success, result = validate_value(value, config_val)
369
+ if success
370
+ # Accept coerced value if success
403
371
  # Used for converting values in the config to proper objects.
404
- params[key] = processed_value
372
+ params[key] = result if !result.nil?
405
373
  else
406
- @logger.error(I18n.t("logstash.agent.configuration.setting_invalid",
374
+ @logger.error(I18n.t("logstash.runner.configuration.setting_invalid",
407
375
  :plugin => @plugin_name, :type => @plugin_type,
408
376
  :setting => key, :value => value.inspect,
409
- :value_type => config_settings[:validate],
410
- :note => processed_value))
377
+ :value_type => config_val,
378
+ :note => result))
411
379
  end
412
-
413
- all_params_valid &&= is_valid
380
+ #puts "Result: #{key} / #{result.inspect} / #{success}"
381
+ is_valid &&= success
414
382
 
415
383
  break # done with this param key
416
384
  end # config.each
417
385
  end # params.each
418
386
 
419
- return all_params_valid
387
+ return is_valid
420
388
  end # def validate_check_parameter_values
421
389
 
422
390
  def validator_find(key)
@@ -437,7 +405,7 @@ module LogStash::Config::Mixin
437
405
  result = nil
438
406
 
439
407
  if validator.nil?
440
- return true, value
408
+ return true
441
409
  elsif validator.is_a?(Array)
442
410
  value = [*value]
443
411
  if value.size > 1
@@ -551,12 +519,6 @@ module LogStash::Config::Mixin
551
519
  end
552
520
 
553
521
  result = value.first.is_a?(::LogStash::Util::Password) ? value.first : ::LogStash::Util::Password.new(value.first)
554
- when :uri
555
- if value.size > 1
556
- return false, "Expected uri (one value), got #{value.size} values?"
557
- end
558
-
559
- result = value.first.is_a?(::LogStash::Util::SafeURI) ? value.first : ::LogStash::Util::SafeURI.new(value.first)
560
522
  when :path
561
523
  if value.size > 1 # Only 1 value wanted
562
524
  return false, "Expected path (one value), got #{value.size} values?"
@@ -592,9 +554,8 @@ module LogStash::Config::Mixin
592
554
 
593
555
  def secure_params!(params)
594
556
  params.each do |key, value|
595
- if [:uri, :password].include? @config[key][:validate]
596
- is_valid, processed_value = process_parameter_value(value, @config[key])
597
- params[key] = processed_value
557
+ if @config[key][:validate] == :password && !value.is_a?(::LogStash::Util::Password)
558
+ params[key] = ::LogStash::Util::Password.new(value)
598
559
  end
599
560
  end
600
561
  end