class LogStash::Inputs::Xlsx

Stream events from files.

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

Files are followed in a manner similar to “tail -0F”. File rotation is detected and handled by this input.

Public Instance Methods

register() click to toggle source
# File lib/logstash/inputs/xlsx.rb, line 70
def register
  require "addressable/uri"
  require "filewatch/ext/xlsxtail"
  require "digest/md5"
  require "logstash/codecs/plain"

  @logger.info("Registering file input", :path => @path)

  @tail_config = {
    :exclude => @exclude,
    :stat_interval => @stat_interval,
    :discover_interval => @discover_interval,
    :sincedb_write_interval => @sincedb_write_interval,
    :logger => @logger,
    :progressdb => @progressdb,
    :progressdb_del => @progressdb_del,
  }

  @codec_plain = LogStash::Codecs::Plain.new

  @path.each do |path|
    if Pathname.new(path).relative?
      raise ArgumentError.new("File paths must be absolute, relative path specified: #{path}")
    end
  end

  if @sincedb_path.nil?
    if ENV["SINCEDB_DIR"].nil? && ENV["HOME"].nil?
      @logger.error("No SINCE_DB or HOME environment variable set, I don't know where " \
                    "to keep track of the files I'm watching. Either set " \
                    "HOME or SINCEDB_DIR in your environment, or set sincedb_path in " \
                    "in your logstash config for the file input with " \
                    "path '#{@path.inspect}'")
      raise # TODO(sissel): HOW DO I FAIL PROPERLY YO
    end

    #pick SINCEDB_DIR if available, otherwise use HOME
    sincedb_dir = ENV["SINCEDB_DIR"] || ENV["HOME"]

    # Join by ',' to make it easy for folks to know their own sincedb
    # generated path (vs, say, inspecting the @path array)
    @sincedb_path = File.join(sincedb_dir, ".sincedb_" + Digest::MD5.hexdigest(@path.join(",")))

    # Migrate any old .sincedb to the new file (this is for version <=1.1.1 compatibility)
    old_sincedb = File.join(sincedb_dir, ".sincedb")
    if File.exists?(old_sincedb)
      @logger.info("Renaming old ~/.sincedb to new one", :old => old_sincedb,
                   :new => @sincedb_path)
      File.rename(old_sincedb, @sincedb_path)
    end

    @logger.info("No sincedb_path set, generating one based on the file path",
                 :sincedb_path => @sincedb_path, :path => @path)
  end

  @tail_config[:sincedb_path] = @sincedb_path

  if @start_position == "beginning"
    @tail_config[:start_new_files_at] = :beginning
  end
end
run(queue) click to toggle source
# File lib/logstash/inputs/xlsx.rb, line 133
def run(queue)
  @tail = FileWatch::Ext::XlsxTail.new(@tail_config)
  @tail.logger = @logger
  @path.each { |path| @tail.tail(path) }
  hostname = Socket.gethostname

  @tail.subscribe do |path, data, type|
    @logger.debug("Received line", :path => path, :data => data, :type => type) if logger.debug?

    if type == :log
      @codec.decode(data) do |event|

        decorate(event)
        #event["tags"] ||= []
        event["host"] = hostname
        event["path"] = path

        queue << event
      end  #decode
    elsif type == :progressdb || type == :progressdb_del
      @codec_plain.decode(data) do |event|

        decorate(event)
        event["host"] = hostname
        event["path"] = path
        event["type"] = "progressdb";

        event.tag("del") if type == :progressdb_del

        queue << event
      end #decode
    end

  end # subscribe
  finished
end
teardown() click to toggle source
# File lib/logstash/inputs/xlsx.rb, line 171
def teardown
  @tail.sincedb_write
  @tail.quit
end