summaryrefslogtreecommitdiff
path: root/lib/oxidized/model/ironware.rb
blob: 87a51a6eca2b84e48c180a3990935b8509268ea2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
class IronWare < Oxidized::Model

  prompt /^.*(telnet|ssh)\@.+[>#]\s?$/i
  comment  '! '
  
  #to handle pager without enable
  #expect /^((.*)--More--(.*))$/ do |data, re|
  #  send ' '
  #  data.sub re, ''
  #end

  
  #to remove backspace (if handle pager without enable)
  #expect /^((.*)[\b](.*))$/ do |data, re|
  #  data.sub re, ''
  #end

  cmd :all do |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! /(^((.*)[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.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
  
  cmd 'show flash' do |cfg|
    comment cfg
  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
    # 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\r\n"
        send vars(:enable) + "\r\n"
      end
    end
    post_login ''
    post_login 'skip-page-display'
    post_login 'terminal length 0'
    pre_logout 'logout'
    pre_logout 'exit'
    pre_logout 'exit'
  end

end