From 50ec31c6d425c17b2e86070bf4b0bda7c2e03256 Mon Sep 17 00:00:00 2001 From: nopedial Date: Sun, 12 May 2013 13:35:37 +0100 Subject: models enhance --- lib/oxidized/model/powerconnect.rb | 6 +++++ lib/oxidized/model/procurve.rb | 45 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 lib/oxidized/model/procurve.rb diff --git a/lib/oxidized/model/powerconnect.rb b/lib/oxidized/model/powerconnect.rb index 0dbd808..304fc86 100644 --- a/lib/oxidized/model/powerconnect.rb +++ b/lib/oxidized/model/powerconnect.rb @@ -4,6 +4,11 @@ class PowerConnect < Oxidized::Model comment '! ' + expect /^\s--More--\s+.*$/ do |data, re| + send ' ' + data.sub re, '' + end + cmd :all do |cfg| cfg.each_line.to_a[1..-3].join end @@ -25,6 +30,7 @@ class PowerConnect < Oxidized::Model cfg :telnet, :ssh do post_login 'terminal datadump' + post_login 'enable' pre_logout 'exit' end diff --git a/lib/oxidized/model/procurve.rb b/lib/oxidized/model/procurve.rb new file mode 100644 index 0000000..b431629 --- /dev/null +++ b/lib/oxidized/model/procurve.rb @@ -0,0 +1,45 @@ +class Procurve < Oxidized::Model + + # FIXME: this is way too unsafe + prompt /.*?([\w\d_]+# ).*/m + + comment '! ' + + expect /Press any key to continue/ do + send ' ' + "" + end + + cmd :all do |cfg| + cfg = cfg.each_line.to_a[1..-3].join + cfg = cfg.gsub /\r/, '' + new_cfg = '' + cfg.each_line do |line| + line.sub! /^\e.*(\e.*)/, '\1' #leave last escape + line.sub! /\e\[24;1H/, '' #remove last escape, is it always this? + new_cfg << line + end + new_cfg + end + + cmd 'show running-config' + + cmd 'show version' do |cfg| + comment cfg + end + + cmd 'show system-information' do |cfg| + comment cfg + end + + cfg :telnet do + username /^\r?Username:/ + password /Password: / + end + + cfg :telnet, :ssh do + post_login 'no page' + pre_logout "logout\ny" + end + +end -- cgit v1.2.1 From 0d28c4a5e6a8c64d765229cc26e6574fb7a35a5d Mon Sep 17 00:00:00 2001 From: nopedial Date: Sun, 12 May 2013 14:31:46 +0100 Subject: add rescue for Errno::EHOSTUNREACH in input/ssh.rb --- lib/oxidized/input/ssh.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/oxidized/input/ssh.rb b/lib/oxidized/input/ssh.rb index 430eaa2..c0594db 100644 --- a/lib/oxidized/input/ssh.rb +++ b/lib/oxidized/input/ssh.rb @@ -12,7 +12,7 @@ module Oxidized begin @ssh = Net::SSH.start @node.ip, @node.auth[:username], :password => @node.auth[:password], :timeout => CFG.timeout - rescue Timeout::Error, Errno::ECONNREFUSED, Errno::ECONNRESET, Net::SSH::Disconnect + rescue Timeout::Error, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::EHOSTUNREACH, Net::SSH::Disconnect return false end open_shell @ssh unless @exec -- cgit v1.2.1