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 codec.
Public Class Methods
new(params)
click to toggle source
Calls superclass method
# File lib/logstash/inputs/pipe.rb, line 30 def initialize(params) super @pipe = nil end
Public Instance Methods
register()
click to toggle source
# File lib/logstash/inputs/pipe.rb, line 36 def register @logger.info("Registering pipe input", :command => @command) end
run(queue)
click to toggle source
# File lib/logstash/inputs/pipe.rb, line 41 def run(queue) while !stop? begin @pipe = IO.popen(@command, "r") hostname = Socket.gethostname @pipe.each do |line| line = line.chomp @logger.debug? && @logger.debug("Received line", :command => @command, :line => line) @codec.decode(line) do |event| event.set("host", hostname) event.set("command", @command) decorate(event) queue << event end end @pipe.close @pipe = nil rescue Exception => e @logger.error("Exception while running command", :e => e, :backtrace => e.backtrace) end # Keep running the command forever. Stud.stoppable_sleep(10) do stop? end end end
stop()
click to toggle source
# File lib/logstash/inputs/pipe.rb, line 70 def stop if @pipe Process.kill("KILL", @pipe.pid) rescue nil @pipe.close rescue nil @pipe = nil end end