Class: LogStash::Filters::Ruby::Script

Inherits:
Object
  • Object
show all
Includes:
Util::Loggable
Defined in:
lib/logstash/filters/ruby/script.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(script_path, parameters) ⇒ Script

Returns a new instance of Script.



7
8
9
10
11
# File 'lib/logstash/filters/ruby/script.rb', line 7

def initialize(script_path, parameters)
  @content = File.read(script_path)
  @script_path = script_path
  @context = Context.new(self, parameters)
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content.



5
6
7
# File 'lib/logstash/filters/ruby/script.rb', line 5

def content
  @content
end

#script_pathObject (readonly)

Returns the value of attribute script_path.



5
6
7
# File 'lib/logstash/filters/ruby/script.rb', line 5

def script_path
  @script_path
end

Instance Method Details

#execute(event) ⇒ Object



29
30
31
# File 'lib/logstash/filters/ruby/script.rb', line 29

def execute(event)
  @context.execute_filter(event)
end

#loadObject



13
14
15
16
17
18
19
20
21
# File 'lib/logstash/filters/ruby/script.rb', line 13

def load
  @context.load_script

  if !@context.execution_context.methods.include?(:filter)
    raise "Script does not define a filter! Please ensure that you have defined a filter method!"
  end
rescue => e
  raise ::LogStash::Filters::Ruby::ScriptError.new("Error during load of '#{script_path}': #{e.inspect}")
end

#registerObject



23
24
25
26
27
# File 'lib/logstash/filters/ruby/script.rb', line 23

def register
  @context.execute_register
rescue => e
  raise ::LogStash::Filters::Ruby::ScriptError.new("Error during register of '#{script_path}': #{e.inspect}")
end

#testObject



33
34
35
36
37
38
39
# File 'lib/logstash/filters/ruby/script.rb', line 33

def test
  results = @context.execute_tests
  logger.info("Test run complete", :script_path => script_path, :results => results)
  if results[:failed] > 0 || results[:errored] > 0
    raise ::LogStash::Filters::Ruby::ScriptError.new("Script '#{script_path}' had #{results[:failed] + results[:errored]} failing tests! Check the error log for details.")
  end
end