summaryrefslogtreecommitdiff
path: root/lib/oxidized
diff options
context:
space:
mode:
authorytti <saku@ytti.fi>2018-05-03 07:27:34 -0700
committerGitHub <noreply@github.com>2018-05-03 07:27:34 -0700
commitba1226882e6a4f3e5a5da88528620148e2b399c4 (patch)
treeb0b19f851d5a57c2fd6270ed3e0f29ae4f74cd6d /lib/oxidized
parentdba1f023ce6b53e4e353ca0c9ccc88facdad796f (diff)
parent90aa9e68ed16c96f54ecd3e3e197d85850531f6e (diff)
Merge pull request #1328 from wk/refactor-telnet-log
make telnet input logging same as ssh (closes #1060)
Diffstat (limited to 'lib/oxidized')
-rw-r--r--lib/oxidized/input/telnet.rb20
1 files changed, 13 insertions, 7 deletions
diff --git a/lib/oxidized/input/telnet.rb b/lib/oxidized/input/telnet.rb
index b1b3222..e7c2ee3 100644
--- a/lib/oxidized/input/telnet.rb
+++ b/lib/oxidized/input/telnet.rb
@@ -10,15 +10,15 @@ module Oxidized
@node = node
@timeout = Oxidized.config.timeout
@node.model.cfg['telnet'].each { |cb| instance_exec(&cb) }
+ @log = File.open(Oxidized::Config::Log + "/#{@node.ip}-telnet", 'w') if Oxidized.config.input.debug?
port = vars(:telnet_port) || 23
- opt = { 'Host' => @node.ip,
- 'Port' => port.to_i,
- 'Timeout' => @timeout,
- 'Model' => @node.model }
- opt['Output_log'] = Oxidized::Config::Log + "/#{@node.ip}-telnet" if Oxidized.config.input.debug?
+ telnet_opts = { 'Host' => @node.ip,
+ 'Port' => port.to_i,
+ 'Timeout' => @timeout,
+ 'Model' => @node.model }
- @telnet = Net::Telnet.new opt
+ @telnet = Net::Telnet.new telnet_opts
if @node.auth[:username] and @node.auth[:username].length > 0
expect username
@telnet.puts @node.auth[:username]
@@ -62,6 +62,9 @@ module Oxidized
disconnect_cli
@telnet.close
rescue Errno::ECONNRESET
+ ensure
+ @log.close if Oxidized.config.input.debug?
+ (@telnet.close rescue true) unless @telnet.closed?
end
end
end
@@ -137,7 +140,10 @@ class Net::Telnet
buf.gsub!(/#{EOL}/no, "\n")
end
end
- @log.print(buf) if @options.has_key?("Output_log")
+ if Oxidized.config.input.debug?
+ @log.print buf
+ @log.flush
+ end
line += buf
line = model.expects line
line = yield line if block_given?