Class: OAS::LogCollector::Source

Inherits:
Object
  • Object
show all
Defined in:
lib/oas/log_collector/source.rb

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, user, port = 22) ⇒ Source

Returns a new instance of Source.



12
13
14
# File 'lib/oas/log_collector/source.rb', line 12

def initialize(host, user, port = 22)
  @host, @user, @port = host, user, port
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



10
11
12
# File 'lib/oas/log_collector/source.rb', line 10

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



10
11
12
# File 'lib/oas/log_collector/source.rb', line 10

def port
  @port
end

#userObject (readonly)

Returns the value of attribute user.



10
11
12
# File 'lib/oas/log_collector/source.rb', line 10

def user
  @user
end

Instance Method Details

#download(files) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/oas/log_collector/source.rb', line 27

def download(files)
  Net::SCP.start(host, user, :port => port) do |scp|
    files.each do |remote_path, dest_path|
      FileUtils.mkdir_p(File.dirname(dest_path))
      scp.download!(remote_path, dest_path, :preserve => true)
    end
  end
end

#find(path, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/oas/log_collector/source.rb', line 16

def find(path, options = {})
  out = ''
  ssh = Net::SSH.start(host, user, :port => port)
  ssh.exec!(build_find(path, options)) do |channel, stream, data|
    raise Error.new(data) if stream == :stderr
    out << data
  end
  ssh.close
  out.split("\n")
end