class LogStash::Inputs::Pipe

Stream events from a long running command pipe.

By default, each event is assumed to be one line. If you want to join lines, you'll want to use the multiline filter.

Public Instance Methods

register() click to toggle source
# File lib/logstash/inputs/pipe.rb, line 27
def register
  @logger.info("Registering pipe input", :command => @command)
end
run(queue) click to toggle source
# File lib/logstash/inputs/pipe.rb, line 32
def run(queue)
  loop do
    begin
      @pipe = IO.popen(@command, mode="r")
      hostname = Socket.gethostname

      @pipe.each do |line|
        line = line.chomp
        source = "pipe://#{hostname}/#{@command}"
        @logger.debug? && @logger.debug("Received line", :command => @command, :line => line)
        @codec.decode(line) do |event|
          event["host"] = hostname
          event["command"] = @command
          decorate(event)
          queue << event
        end
      end
    rescue Exception => e
      @logger.error("Exception while running command", :e => e, :backtrace => e.backtrace)
    end

    # Keep running the command forever.
    sleep(10)
  end
end