Class: Tailer::Listener

Inherits:
Object
  • Object
show all
Defined in:
lib/tailer/listener.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Listener

Returns a new instance of Listener.



27
28
29
30
31
32
33
34
# File 'lib/tailer/listener.rb', line 27

def initialize(options)
  @hosts = options[:hosts]
  @files = options[:files]
  @log = options[:log] || ::Logger.new(STDERR)
  Handler.output = options[:output] || STDOUT
  Handler.log = log
  @last_status = 0
end

Instance Attribute Details

#filesObject

Returns the value of attribute files.



26
27
28
# File 'lib/tailer/listener.rb', line 26

def files
  @files
end

#hostsObject

Returns the value of attribute hosts.



26
27
28
# File 'lib/tailer/listener.rb', line 26

def hosts
  @hosts
end

#logObject

Returns the value of attribute log.



26
27
28
# File 'lib/tailer/listener.rb', line 26

def log
  @log
end

#outputObject

Returns the value of attribute output.



26
27
28
# File 'lib/tailer/listener.rb', line 26

def output
  @output
end

Instance Method Details

#executeObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/tailer/listener.rb', line 40

def execute
  begin
    @t_start = Time.now.to_f
    Handler.t_start = Time.now.to_f
    Handler.bytes = 0
    Handler.last_status = 0
    EventMachine.run do
      @hosts.each do |host|
        spawn(host)
      end
    end
  rescue Errno::EPIPE => e
    @log.info "Exiting..."
  rescue Interrupt => e
    @log.info "Exiting..."
  end
end

#spawn(host) ⇒ Object



36
37
38
# File 'lib/tailer/listener.rb', line 36

def spawn(host)
  EventMachine.popen("ssh #{Shellwords.escape(host)} \"tail -q -F #{@files.map { |file| Shellwords.escape(file) }.join(' ')}\"", Handler)
end