summaryrefslogtreecommitdiff
path: root/lib/oxidized/model/ironware.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/oxidized/model/ironware.rb')
-rw-r--r--lib/oxidized/model/ironware.rb49
1 files changed, 35 insertions, 14 deletions
diff --git a/lib/oxidized/model/ironware.rb b/lib/oxidized/model/ironware.rb
index e18902b..87a51a6 100644
--- a/lib/oxidized/model/ironware.rb
+++ b/lib/oxidized/model/ironware.rb
@@ -1,6 +1,6 @@
class IronWare < Oxidized::Model
- prompt /^.+[>#]\s?$/
+ prompt /^.*(telnet|ssh)\@.+[>#]\s?$/i
comment '! '
#to handle pager without enable
@@ -16,22 +16,34 @@ class IronWare < Oxidized::Model
#end
cmd :all do |cfg|
- cfg.each_line.to_a[1..-2].join
- end
-
- cmd 'show running-config' do |cfg|
- cfg = cfg.each_line.to_a[3..-1].join
- cfg
+ # sometimes ironware inserts arbitrary whitespace after commands are
+ # issued on the CLI, from run to run. this normalises the output.
+ cfg.each_line.to_a[1..-2].drop_while { |e| e.match /^\s+$/ }.join
end
cmd 'show version' do |cfg|
- cfg.gsub! /(^((.*)system uptime(.*))$)/, '' #remove unwanted line system uptime
+ cfg.gsub! /(^((.*)[Ss]ystem uptime(.*))$)/, '' #remove unwanted line system uptime
+ cfg.gsub! /[Uu]p\s?[Tt]ime is .*/,''
+
comment cfg
end
cmd 'show chassis' do |cfg|
- cfg.gsub! "\xFF", '' # ugly hack - avoids JSON.dump utf-8 breakage on 1.9..
+ cfg.encode!("UTF-8", :invalid => :replace) #sometimes ironware returns broken encoding
cfg.gsub! /(^((.*)Current temp(.*))$)/, '' #remove unwanted lines current temperature
+ cfg.gsub! /Speed = [A-Z]{3} \(\d{2}\%\)/, '' #remove unwanted lines Speed Fans
+ cfg.gsub! /current speed is [A-Z]{3} \(\d{2}\%\)/, ''
+ cfg.gsub! /\d{2}\.\d deg-C/, 'XX.X deg-C'
+ if cfg.include? "TEMPERATURE"
+ sc = StringScanner.new cfg
+ out = ''
+ temps = ''
+ out << sc.scan_until(/.*TEMPERATURE/)
+ temps << sc.scan_until(/.*Fans/)
+ out << sc.rest
+ cfg = out
+ end
+
comment cfg
end
@@ -40,22 +52,31 @@ class IronWare < Oxidized::Model
end
cmd 'show module' do |cfg|
+ cfg.gsub! /^((Invalid input)|(Type \?)).*$/, '' # some ironware devices are fixed config
comment cfg
end
+ cmd 'show running-config' do |cfg|
+ arr = cfg.each_line.to_a
+ arr[2..-1].join unless arr.length < 2
+ end
+
cfg :telnet do
- username /^Username:/
- password /^Password:/
+ # match expected prompts on both older and newer
+ # versions of IronWare
+ username /^(Please Enter Login Name|Username):/
+ password /^(Please Enter )Password:/
end
#handle pager with enable
cfg :telnet, :ssh do
if vars :enable
post_login do
- send "enable\n"
- send vars(:enable) + "\n"
+ send "enable\r\n"
+ send vars(:enable) + "\r\n"
end
end
+ post_login ''
post_login 'skip-page-display'
post_login 'terminal length 0'
pre_logout 'logout'
@@ -63,4 +84,4 @@ class IronWare < Oxidized::Model
pre_logout 'exit'
end
-end \ No newline at end of file
+end