summaryrefslogtreecommitdiff
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
parenta44e81e706db8ce9639868f3d97c6c97ceec9716 (diff)
refactor telnet input logging for consistently with ssh
-rw-r--r--.rubocop_todo.yml2
-rw-r--r--lib/oxidized/input/telnet.rb20
2 files changed, 14 insertions, 8 deletions
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index 77c1026..6598a37 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -140,7 +140,7 @@ Metrics/CyclomaticComplexity:
# Offense count: 53
# Configuration parameters: CountComments.
Metrics/MethodLength:
- Max: 72
+ Max: 75
# Offense count: 2
# Configuration parameters: CountKeywordArgs.
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?