Class: Oxidized::SCP

Inherits:
Input
  • Object
show all
Includes:
Input::CLI
Defined in:
lib/oxidized/input/scp.rb

Constant Summary collapse

RESCUE_FAIL =
{
  debug: [
    Net::SSH::Disconnect,
    Net::SSH::ConnectionTimeout
  ],
  warn:  [
    Net::SCP::Error,
    Net::SSH::HostKeyUnknown,
    Net::SSH::AuthenticationFailed,
    Timeout::Error
  ]
}.freeze

Instance Attribute Summary

Attributes included from Input::CLI

#node

Instance Method Summary collapse

Methods included from Input::CLI

#connect_cli, #disconnect_cli, #get, #initialize, #login, #newline, #password, #post_login, #pre_logout, #username

Methods included from Config::Vars

#vars

Instance Method Details

#cmd(file) ⇒ Object



54
55
56
57
58
59
# File 'lib/oxidized/input/scp.rb', line 54

def cmd(file)
  logger.debug "SCP: #{file} @ #{@node.name}"
  Timeout.timeout(@node.timeout) do
    @ssh.scp.download!(file)
  end
end

#connect(node) ⇒ Object

rubocop:disable Naming/PredicateMethod



22
23
24
25
26
27
28
# File 'lib/oxidized/input/scp.rb', line 22

def connect(node) # rubocop:disable Naming/PredicateMethod
  @node = node
  @node.model.cfg['scp'].each { |cb| instance_exec(&cb) }
  @log = File.open(Oxidized::Config::LOG + "/#{@node.ip}-scp", 'w') if Oxidized.config.input.debug?
  @ssh = Net::SSH.start(@node.ip, @node.auth[:username], make_ssh_opts)
  connected?
end

#connected?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/oxidized/input/scp.rb', line 50

def connected?
  @ssh && (not @ssh.closed?)
end

#make_ssh_optsObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/oxidized/input/scp.rb', line 30

def make_ssh_opts
  secure = Oxidized.config.input.scp.secure?
  ssh_opts = {
    number_of_password_prompts:      0,
    verify_host_key:                 secure ? :always : :never,
    append_all_supported_algorithms: true,
    password:                        @node.auth[:password],
    timeout:                         @node.timeout,
    port:                            (vars(:ssh_port) || 22).to_i,
    forward_agent:                   false
  }

  # Use our logger for Net::SSH
  ssh_logger = SemanticLogger[Net::SSH]
  ssh_logger.level = Oxidized.config.input.debug? ? :debug : :fatal
  ssh_opts[:logger] = ssh_logger

  ssh_opts
end

#outputObject



65
66
67
# File 'lib/oxidized/input/scp.rb', line 65

def output
  ""
end

#send(my_proc) ⇒ Object



61
62
63
# File 'lib/oxidized/input/scp.rb', line 61

def send(my_proc)
  my_proc.call
end