Sha256: 43f47239c84daa9dd0c2fa9ca7f3862d7198711f1cbadf715e5863b2171ec1cf

Contents?: true

Size: 1.01 KB

Versions: 3

Compression:

Stored size: 1.01 KB

Contents

module Oxidized
  require 'net/ssh'
  require 'net/scp'
  require 'timeout'
  require_relative 'cli'

  class SCP < Input
    RESCUE_FAIL = {
      debug: [
        # Net::SSH::Disconnect,
      ],
      warn:  [
        # RuntimeError,
        # Net::SSH::AuthenticationFailed,
      ]
    }.freeze
    include Input::CLI

    def connect(node)
      @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], password: @node.auth[:password])
      connected?
    end

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

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

    def send(my_proc)
      my_proc.call
    end

    def output
      ""
    end

    private

    def disconnect
      @ssh.close
    ensure
      @log.close if Oxidized.config.input.debug?
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
oxidized-0.31.0 lib/oxidized/input/scp.rb
oxidized-0.30.1 lib/oxidized/input/scp.rb
oxidized-0.30.0 lib/oxidized/input/scp.rb