summaryrefslogtreecommitdiff
path: root/lib/oxidized
diff options
context:
space:
mode:
authorWild Kat <wk@futureinquestion.net>2018-04-29 19:55:35 +0200
committerWild Kat <wk@futureinquestion.net>2018-04-29 19:55:35 +0200
commit90aa9e68ed16c96f54ecd3e3e197d85850531f6e (patch)
tree8f913ed6a5445104318f949504632fdefa71ca25 /lib/oxidized
parenta44e81e706db8ce9639868f3d97c6c97ceec9716 (diff)
refactor telnet input logging for consistently with ssh
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?