diff options
Diffstat (limited to 'lib/oxidized/input')
| -rw-r--r-- | lib/oxidized/input/ftp.rb | 54 | ||||
| -rw-r--r-- | lib/oxidized/input/ssh.rb | 3 | ||||
| -rw-r--r-- | lib/oxidized/input/telnet.rb | 7 | 
3 files changed, 61 insertions, 3 deletions
diff --git a/lib/oxidized/input/ftp.rb b/lib/oxidized/input/ftp.rb new file mode 100644 index 0000000..ccbf5ef --- /dev/null +++ b/lib/oxidized/input/ftp.rb @@ -0,0 +1,54 @@ +module Oxidized +  require 'net/ftp' +  require 'timeout' +  require_relative 'cli' + +  class FTP < Input +    RescueFail = { +      :debug => [ +        #Net::SSH::Disconnect, +      ], +      :warn => [ +        #RuntimeError, +        #Net::SSH::AuthenticationFailed, +      ], +    } +    include Input::CLI + +    def connect node +      @node       = node +      @node.model.cfg['ftp'].each { |cb| instance_exec(&cb) } +      @log = File.open(CFG.input.debug?.to_s + '-ftp', 'w') if CFG.input.debug? +      @ftp = Net::FTP.new @node.ip, @node.auth[:username], @node.auth[:password] +      connected? +    end + +    def connected? +      @ftp and not @ftp.closed? +    end + +    def cmd file +      Log.debug "FTP: #{file} @ #{@node.name}" +      @ftp.getbinaryfile file, nil +    end + +    # meh not sure if this is the best way, but perhaps better than not implementing send +    def send my_proc +      my_proc.call +    end + +    def output +      "" +    end + +    private + +    def disconnect +      @ftp.close +    #rescue Errno::ECONNRESET, IOError +    ensure +      @log.close if CFG.input.debug? +    end + +  end +end diff --git a/lib/oxidized/input/ssh.rb b/lib/oxidized/input/ssh.rb index b1f109b..d6b4e1f 100644 --- a/lib/oxidized/input/ssh.rb +++ b/lib/oxidized/input/ssh.rb @@ -21,7 +21,8 @@ module Oxidized        @node.model.cfg['ssh'].each { |cb| instance_exec(&cb) }        secure = CFG.input.ssh.secure        @log = File.open(CFG.input.debug?.to_s + '-ssh', 'w') if CFG.input.debug? -      @ssh = Net::SSH.start @node.ip, @node.auth[:username], +      port = vars(:ssh_port) || 22 +      @ssh = Net::SSH.start @node.ip, @node.auth[:username], :port => port.to_i,                              :password => @node.auth[:password], :timeout => CFG.timeout,                              :paranoid => secure,                              :auth_methods => %w(none publickey password keyboard-interactive), diff --git a/lib/oxidized/input/telnet.rb b/lib/oxidized/input/telnet.rb index 13fccf7..d305fcd 100644 --- a/lib/oxidized/input/telnet.rb +++ b/lib/oxidized/input/telnet.rb @@ -10,9 +10,12 @@ module Oxidized        @node    = node        @timeout = CFG.timeout        @node.model.cfg['telnet'].each { |cb| instance_exec(&cb) } +      port = vars(:telnet_port) || 23 -      opt = { 'Host' => @node.ip, 'Timeout' => @timeout, -              'Model' => @node.model } +      opt = { 'Host'    => @node.ip, +              'Port'    => port.to_i, +              'Timeout' => @timeout, +              'Model'   => @node.model }        opt['Output_log'] = CFG.input.debug?.to_s + '-telnet' if CFG.input.debug?        @telnet  = Net::Telnet.new opt  | 
