Class: LogStash::Outputs::Pipe

Inherits:
Base show all
Defined in:
lib/logstash/outputs/pipe.rb

Overview

Pipe output.

Pipe events to stdin of another program. You can use fields from the event as parts of the command. WARNING: This feature can cause logstash to fork off multiple children if you are not carefull with per-event commandline.

Constant Summary

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

#handle, #handle_worker, #initialize, #worker_setup, #workers_not_supported

Methods included from Config::Mixin

#config_init, included

Methods inherited from Plugin

#eql?, #finished, #finished?, #hash, #initialize, #inspect, lookup, #reload, #running?, #shutdown, #terminating?, #to_s

Constructor Details

This class inherits a constructor from LogStash::Outputs::Base

Instance Method Details

#receive(event) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/logstash/outputs/pipe.rb', line 35

def receive(event)
  return unless output?(event)

  command = event.sprintf(@command)
  pipe = get_pipe(command)

  if @message_format
    output = event.sprintf(@message_format) + "\n"
  else
    output = event.to_json
  end

  begin
    pipe.puts(output)
  rescue IOError, Errno::EPIPE => e
    @logger.error("Error writing to pipe, closing pipe.", :command => command, :pipe => pipe)
    drop_pipe(command)
  end

  close_stale_pipes
end

#registerObject



29
30
31
32
# File 'lib/logstash/outputs/pipe.rb', line 29

def register
  @pipes = {}
  @last_stale_cleanup_cycle = Time.now
end

#teardownObject

def receive



57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/logstash/outputs/pipe.rb', line 57

def teardown
  @logger.info("Teardown: closing pipes")
  @pipes.each do |command, pipe|
    begin
      drop_pipe(command)
      @logger.debug("Closed pipe #{command}", :pipe => pipe)
    rescue Exception => e
      @logger.error("Excpetion while closing pipes.", :exception => e)
    end
  end
  finished
end