Skip to content

Commit

Permalink
input/ssh: update debug logfile
Browse files Browse the repository at this point in the history
  • Loading branch information
robertcheramy committed Dec 17, 2024
1 parent 392ec60 commit dfeb060
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).

### Changed
- sonicos: accept policy message. Fixes #3339 (@Steve-M-C, @robertcheramy)
- input/ssh: change input.debug to dump all characters and include sent commands. (@robertcheramy)

### Fixed
- tplink: send 'enable' before the enable password. Fixes #3271 (@robertcheramy)
Expand Down
14 changes: 11 additions & 3 deletions lib/oxidized/input/ssh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ def connect(node)
@output = ''
@pty_options = { term: "vt100" }
@node.model.cfg['ssh'].each { |cb| instance_exec(&cb) }
@log = File.open(Oxidized::Config::LOG + "/#{@node.ip}-ssh", 'w') if Oxidized.config.input.debug?
if Oxidized.config.input.debug?
logfile = Oxidized::Config::LOG + "/#{@node.ip}-ssh"
@log = File.open(logfile, 'w')
Oxidized.logger.debug "lib/oxidized/input/ssh.rb: I/O Debuging to #{logfile}"
end

Oxidized.logger.debug "lib/oxidized/input/ssh.rb: Connecting to #{@node.name}"
@ssh = Net::SSH.start(@node.ip, @node.auth[:username], make_ssh_opts)
Expand All @@ -41,7 +45,11 @@ def connected?
end

def cmd(cmd, expect = node.prompt)
Oxidized.logger.debug "lib/oxidized/input/ssh.rb #{cmd} @ #{node.name} with expect: #{expect.inspect}"
Oxidized.logger.debug "lib/oxidized/input/ssh.rb #{cmd.dump} @ #{node.name} with expect: #{expect.inspect}"
if Oxidized.config.input.debug?
@log.puts "sent #{cmd.dump}"
@log.flush
end
cmd_output = if @exec
@ssh.exec! cmd
else
Expand Down Expand Up @@ -78,7 +86,7 @@ def shell_open(ssh)
@ses = ssh.open_channel do |ch|
ch.on_data do |_ch, data|
if Oxidized.config.input.debug?
@log.print data
@log.puts "received #{data.dump}"
@log.flush
end
@output << data
Expand Down

0 comments on commit dfeb060

Please sign in to comment.