From 7c2565720c898b0573a5a30db958d8a78577f4a4 Mon Sep 17 00:00:00 2001 From: Saku Ytti Date: Sat, 1 Mar 2014 11:35:17 +0200 Subject: Add Model#output method Outputs about what we've seen last in input class. Quite dirty in telnet, so not sure I'm going to support it. Let's see if there is use-case for it. --- lib/oxidized/input/input.rb | 1 + lib/oxidized/input/ssh.rb | 6 +++++- lib/oxidized/input/telnet.rb | 9 ++++++++- lib/oxidized/model/model.rb | 4 ++++ oxidized.gemspec | 2 +- 5 files changed, 19 insertions(+), 3 deletions(-) diff --git a/lib/oxidized/input/input.rb b/lib/oxidized/input/input.rb index 61f4634..a64a1f4 100644 --- a/lib/oxidized/input/input.rb +++ b/lib/oxidized/input/input.rb @@ -5,6 +5,7 @@ module Oxidized Errno::ECONNREFUSED, ], :warn => [ + IOError, Timeout::Error, Errno::ECONNRESET, Errno::EHOSTUNREACH, diff --git a/lib/oxidized/input/ssh.rb b/lib/oxidized/input/ssh.rb index 5c9a4f0..24401dd 100644 --- a/lib/oxidized/input/ssh.rb +++ b/lib/oxidized/input/ssh.rb @@ -17,7 +17,7 @@ module Oxidized def connect node @node = node @output = '' - @node.model.cfg['ssh'].each { |cb| instance_exec &cb } + @node.model.cfg['ssh'].each { |cb| instance_exec(&cb) } secure = CFG.input[:ssh][:secure] @ssh = Net::SSH.start @node.ip, @node.auth[:username], :password => @node.auth[:password], :timeout => CFG.timeout, @@ -39,6 +39,10 @@ module Oxidized @ses.send_data data end + def output + @output + end + private def disconnect diff --git a/lib/oxidized/input/telnet.rb b/lib/oxidized/input/telnet.rb index 31ed8d0..26df113 100644 --- a/lib/oxidized/input/telnet.rb +++ b/lib/oxidized/input/telnet.rb @@ -9,7 +9,7 @@ module Oxidized def connect node @node = node @timeout = CFG.timeout - @node.model.cfg['telnet'].each { |cb| instance_exec &cb } + @node.model.cfg['telnet'].each { |cb| instance_exec(&cb) } @telnet = Net::Telnet.new 'Host' => @node.ip, 'Waittime' => @timeout, 'Model' => @node.model expect username @@ -30,6 +30,10 @@ module Oxidized @telnet.write data end + def output + @telnet.output + end + private def expect re @@ -59,6 +63,8 @@ end class Net::Telnet ## FIXME: we just need 'line = model.expects line' to handle pager ## how to do this, without redefining the whole damn thing + ## FIXME: we also need output (not sure I'm going to support this) + attr_reader :output def waitfor(options) # :yield: recvdata time_out = @options["Timeout"] waittime = @options["Waittime"] @@ -93,6 +99,7 @@ class Net::Telnet end begin c = @sock.readpartial(1024 * 1024) + @output = c @dumplog.log_dump('<', c) if @options.has_key?("Dump_log") if @options["Telnetmode"] c = rest + c diff --git a/lib/oxidized/model/model.rb b/lib/oxidized/model/model.rb index 2a6cbc4..f95443d 100644 --- a/lib/oxidized/model/model.rb +++ b/lib/oxidized/model/model.rb @@ -53,6 +53,10 @@ module Oxidized out end + def output + @input.output + end + def send data @input.send data end diff --git a/oxidized.gemspec b/oxidized.gemspec index c25b64b..db9c761 100644 --- a/oxidized.gemspec +++ b/oxidized.gemspec @@ -1,6 +1,6 @@ Gem::Specification.new do |s| s.name = 'oxidized' - s.version = '0.0.30' + s.version = '0.0.31' s.platform = Gem::Platform::RUBY s.authors = [ 'Saku Ytti' ] s.email = %w( saku@ytti.fi ) -- cgit v1.2.1