forked from ytti/oxidized
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hpmsm.rb
86 lines (68 loc) · 2.21 KB
/
hpmsm.rb
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
class HPMSM < Oxidized::Model
using Refinements
prompt /^CLI[>#] +$/
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
cmd :all do |cfg|
cfg = cfg.cut_both
cfg = cfg.gsub /^\r/, ''
cfg
end
cmd :secret do |cfg|
cfg.gsub! /^(snmp-server community) \S+(.*)/, '\\1 <secret hidden> \\2'
cfg.gsub! /^(snmp-server host \S+) \S+(.*)/, '\\1 <secret hidden> \\2'
cfg.gsub! /^(radius-server host \S+ key) \S+(.*)/, '\\1 <secret hidden> \\2'
cfg.gsub! /^(radius-server key).*/, '\\1 <configuration removed>'
cfg.gsub! /^(tacacs-server host \S+ key) \S+(.*)/, '\\1 <secret hidden> \\2'
cfg.gsub! /^(tacacs-server key).*/, '\\1 <secret hidden>'
cfg
end
cmd 'show system info' do |cfg|
sysinfo = ''
ram = cfg.match(/Total RAM:\s+(\S+)/)[1].to_i / 1024 / 1024
sysinfo << "Memory: #{ram}M\n"
serial = cfg.match(/Serial Number:\s+(\S+)/)[1]
sysinfo << "Serial Number: #{serial}\n"
firmware = cfg.match(/Firmware Version:\s+(\S+)/)[1]
sysinfo << "Firmware: #{firmware}\n"
comment sysinfo
end
cmd 'show ip' do |cfg|
comment cfg
end
cmd 'show ip route' do |cfg|
comment cfg
end
cmd 'show certificate' do |cfg|
comment cfg
end
cmd 'show certificate binding' do |cfg|
comment cfg
end
cmd 'show satellites' do |cfg|
comment cfg
end
cmd 'show web content' do |cfg|
comment cfg
end
cmd 'show all config' do |cfg|
cfg = cfg.each_line.reject { |line| line.match /^running configuration:/ }.join
# The who line contains SSH source port number, and the When line contains the timestamp of the run
cfg = cfg.each_line.reject { |line| line.match /(^#\s+Who:)|(^#\s+When:)/ }.join
# igmp proxy line keeps changing with weird characters every run, filter it out
cfg = cfg.each_line.reject { |line| line.match /^[ \t]*igmp proxy (upstream|downstream)/ }.join
cfg
end
cfg :ssh do
post_login "enable"
pre_logout "quit"
pty_options(chars_wide: 1000)
end
end