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 | 7 | ||||
-rw-r--r-- | lib/oxidized/input/telnet.rb | 15 |
3 files changed, 68 insertions, 8 deletions
diff --git a/lib/oxidized/input/ftp.rb b/lib/oxidized/input/ftp.rb new file mode 100644 index 0000000..70db60c --- /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(Oxidized::Config::Crash + "-#{@node.ip}-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 46f90f9..21fb02c 100644 --- a/lib/oxidized/input/ssh.rb +++ b/lib/oxidized/input/ssh.rb @@ -20,11 +20,12 @@ module Oxidized @output = '' @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], + @log = File.open(Oxidized::Config::Crash + "-#{@node.ip}-ssh", 'w') if CFG.input.debug? + 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(publickey password), + :auth_methods => %w(none publickey password keyboard-interactive), :number_of_password_prompts => 0 unless @exec shell_open @ssh diff --git a/lib/oxidized/input/telnet.rb b/lib/oxidized/input/telnet.rb index 13fccf7..bf0140c 100644 --- a/lib/oxidized/input/telnet.rb +++ b/lib/oxidized/input/telnet.rb @@ -10,14 +10,19 @@ 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['Output_log'] = CFG.input.debug?.to_s + '-telnet' if CFG.input.debug? + opt = { 'Host' => @node.ip, + 'Port' => port.to_i, + 'Timeout' => @timeout, + 'Model' => @node.model } + opt['Output_log'] = Oxidized::Config::Crash + "-#{@node.ip}-telnet" if CFG.input.debug? @telnet = Net::Telnet.new opt - expect username - @telnet.puts @node.auth[:username] + if @node.auth[:username] and @node.auth[:username].length > 0 + expect username + @telnet.puts @node.auth[:username] + end expect password @telnet.puts @node.auth[:password] begin |