Class: LogStash::Filters::Ruby
- Defined in:
- lib/logstash/filters/ruby.rb
Overview
Execute ruby code.
For example, to cancel 90% of events, you can do this:
filter {
ruby {
# Cancel 90% of events
code => "event.cancel if rand <= 0.90"
}
}
Constant Summary
Constants inherited from Base
Constants included from Config::Mixin
Instance Attribute Summary
Attributes included from Config::Mixin
Attributes inherited from Plugin
Instance Method Summary collapse
Methods inherited from Base
#execute, #initialize, #threadsafe?
Methods included from Config::Mixin
Methods inherited from Plugin
#eql?, #finished, #finished?, #hash, #initialize, #inspect, lookup, #reload, #running?, #shutdown, #teardown, #terminating?, #to_s
Constructor Details
This class inherits a constructor from LogStash::Filters::Base
Instance Method Details
#filter(event) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/logstash/filters/ruby.rb', line 35 def filter(event) return unless filter?(event) @codeblock.call(event) filter_matched(event) end |
#register ⇒ Object
28 29 30 31 32 |
# File 'lib/logstash/filters/ruby.rb', line 28 def register # TODO(sissel): Compile the ruby code eval(@init, binding, "(ruby filter init)") if @init eval("@codeblock = lambda { |event| #{@code} }", binding, "(ruby filter code)") end |