diff options
author | Saku Ytti <saku@ytti.fi> | 2014-08-08 21:25:18 +0300 |
---|---|---|
committer | Saku Ytti <saku@ytti.fi> | 2014-08-08 21:25:18 +0300 |
commit | 96d6c0213178241ab3170141906c152c6984e446 (patch) | |
tree | dc5168d8dd2beebba56e4c9b9131da173727ce40 /lib/oxidized/input/ssh.rb | |
parent | a2df4cabc72383936f215b766311b159e6800a17 (diff) |
Support creating session log of telnet/ssh
If you have
input:
debug: session_log
Then session_log-telnet and session_log-ssh will be created showing what
the telnet/ssh saw. Helpful in model development.
Diffstat (limited to 'lib/oxidized/input/ssh.rb')
-rw-r--r-- | lib/oxidized/input/ssh.rb | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/lib/oxidized/input/ssh.rb b/lib/oxidized/input/ssh.rb index e3fcede..62a31eb 100644 --- a/lib/oxidized/input/ssh.rb +++ b/lib/oxidized/input/ssh.rb @@ -20,6 +20,7 @@ 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], :password => @node.auth[:password], :timeout => CFG.timeout, :paranoid => secure @@ -59,12 +60,14 @@ module Oxidized Timeout::timeout(CFG.timeout) { @ssh.loop } rescue Errno::ECONNRESET, Net::SSH::Disconnect, IOError ensure + @log.close if CFG.input.debug? (@ssh.close rescue true) unless @ssh.closed? end def shell_open ssh @ses = ssh.open_channel do |ch| ch.on_data do |_ch, data| + @log.print data if CFG.input.debug? @output << data @output = @node.model.expects @output end |