Class: LogStash::Inputs::Pipe

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

Overview

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.

Constant Summary

Constants included from Config::Mixin

Config::Mixin::CONFIGSORT

Instance Attribute Summary

Attributes inherited from Base

#params, #threadable

Attributes included from Config::Mixin

#config, #original_params

Attributes inherited from Plugin

#logger, #params

Instance Method Summary collapse

Methods inherited from Base

#initialize, #tag

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::Inputs::Base

Instance Method Details

#registerObject



27
28
29
# File 'lib/logstash/inputs/pipe.rb', line 27

def register
  @logger.info("Registering pipe input", :command => @command)
end

#run(queue) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 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