class LogStash::Inputs::Gunzip

This plugin decompress gzip input file

Public Instance Methods

register() click to toggle source

Open gz files

# File lib/logstash/inputs/gunzip.rb, line 33
def register
        @host = Socket.gethostname
        @gzstream = {}
        @path.each do |path|
                @logger.info("Opening file", :path => path)
                @gzstream[path] = Zlib::GzipReader.new(open(path), {"encoding"=>@codec.charset})
        end
end
run(queue) click to toggle source
# File lib/logstash/inputs/gunzip.rb, line 42
def run(queue)
    @path.each do |path|
        lineNumber = 0
        @gzstream[path].each_line do |line|
            lineNumber = lineNumber+1
            @codec.decode(line) do |event|
                  decorate(event)
                  event.set("host", @hostname) if !event.include?("host")
                  event.set("path", path)
                  event.set("line_number", lineNumber)
                  queue << event
            end
        end
    end

end
stop() click to toggle source

Close file

# File lib/logstash/inputs/gunzip.rb, line 60
def stop
  @path.each do |path|
    @gzstream[path].close
  end
end