Class: LogStash::Inputs::Folder

Inherits:
Base
  • Object
show all
Defined in:
lib/logstash/inputs/folder.rb

Instance Method Summary collapse

Instance Method Details

#registerObject



19
20
21
22
23
24
25
26
27
# File 'lib/logstash/inputs/folder.rb', line 19

def register
  @logger.info("Registering folder input", :path => @path)

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

  @fileQueue = Queue.new
end

#run(queue) ⇒ Object



30
31
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
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/logstash/inputs/folder.rb', line 30

def run(queue)
hostname = Socket.gethostname

@notifier = INotify::Notifier.new

@notifier.watch(@path, :create) do |event|
  @logger.debug("new file", :path => event.name)
  @fileQueue << event
end

@consumer = Thread.new do
  while true do
      fileEvent = @fileQueue.pop
      fileName = "#{@path}/#{fileEvent.name}"
      begin
        if File.writable?(fileName)
          @codec.decode(File.read(fileName)) do |event|
            decorate(event)
            event["host"] = hostname if !event.include?("host")
            event["path"] = fileName
            queue << event
          end
        else
          sleep(1)
          @fileQueue << fileEvent
        end
      rescue Exception => e
        @fileQueue << fileEvent
      end
    end
  end

  @notifier.run

  finished

  puts "folder plugin started"
end

#teardownObject



70
71
72
73
# File 'lib/logstash/inputs/folder.rb', line 70

def teardown
  @notifier.close
  @consumer
end