Class: LogStash::Filters::Ruby

Inherits:
Base show all
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

Base::RESERVED

Constants included from Config::Mixin

Config::Mixin::CONFIGSORT

Instance Attribute Summary

Attributes included from Config::Mixin

#config, #original_params

Attributes inherited from Plugin

#logger, #params

Instance Method Summary collapse

Methods inherited from Base

#execute, #initialize, #threadsafe?

Methods included from Config::Mixin

#config_init, included

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

#registerObject



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