Class: LogStash::Filters::Ruby
- Inherits:
-
Base
- Object
- Base
- 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:
- source,ruby
-
filter {
ruby { # Cancel 90% of events code => "event.cancel if rand <= 0.90" }}
Instance Method Summary collapse
Instance Method Details
#filter(event) ⇒ Object
32 33 34 35 36 37 38 39 40 |
# File 'lib/logstash/filters/ruby.rb', line 32 def filter(event) begin @codeblock.call(event) filter_matched(event) rescue Exception => e @logger.error("Ruby exception occurred: #{e}") event.tag("_rubyexception") end end |
#register ⇒ Object
26 27 28 29 30 |
# File 'lib/logstash/filters/ruby.rb', line 26 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 |