summaryrefslogtreecommitdiff
path: root/lib/oxidized/model/procurve.rb
blob: 444fb5b62a45ebd02cf252b117fcbf8b22e2f518 (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
88
89
90
91
class Procurve < Oxidized::Model

  # some models start lines with \r
  # previous command is repeated followed by "\eE", which sometimes ends up on last line
  prompt /^\r?([\w.-]+# )$/

  comment  '! '

  # replace next line control sequence with a new line
  expect /(\e\[1M\e\[\??\d+(;\d+)*[A-Za-z]\e\[1L)|(\eE)/ do |data, re|
    data.gsub re, "\n"
  end

  # replace all used vt100 control sequences
  expect /\e\[\??\d+(;\d+)*[A-Za-z]/ do |data, re|
    data.gsub re, ''
  end

  expect /Press any key to continue(\e\[\??\d+(;\d+)*[A-Za-z])*$/ do
    send ' '
    ""
  end

  expect /Enter switch number/ do
    send "\n"
    ""
  end

  cmd :all do |cfg|
    cfg = cfg.each_line.to_a[1..-2].join
    cfg = cfg.gsub /^\r/, ''
  end

  cmd :secret do |cfg|
    cfg.gsub! /^(snmp-server community).*/, '\\1 <configuration removed>'
    cfg.gsub! /^(snmp-server host).*/, '\\1 <configuration removed>'
    cfg.gsub! /^(radius-server host).*/, '\\1 <configuration removed>'
    cfg.gsub! /^(radius-server key).*/, '\\1 <configuration removed>'
    cfg
  end

  cmd 'show version' do |cfg|
    comment cfg
  end

  cmd 'show modules' do |cfg|
    comment cfg
  end

  cmd 'show system power-supply' do |cfg|
    comment cfg
  end

  cmd 'show interfaces transceiver' do |cfg|
    comment cfg
  end

  cmd 'show flash' do |cfg|
    comment cfg
  end

  # not supported on all models
  cmd 'show system-information' do |cfg|
    cfg = cfg.split("\n")[0..-8].join("\n")
    comment cfg
  end

  # not supported on all models
  cmd 'show system information' do |cfg|
    cfg = cfg.each_line.select { |line| not line.match /(.*CPU.*)|(.*Up Time.*)|(.*Total.*)|(.*Free.*)|(.*Lowest.*)|(.*Missed.*)/ }
    cfg = cfg.join
    comment cfg
  end

  cmd 'show running-config'

  cfg :telnet do
    username /Username:/
    password /Password:/
  end

  cfg :telnet, :ssh do
    post_login 'no page'
    pre_logout "logout\ny\nn"
  end

  cfg :ssh do
    pty_options({ chars_wide: 1000 })
  end

end