forked from ytti/oxidized
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gaiaos.rb
81 lines (69 loc) · 2.02 KB
/
gaiaos.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
class GaiaOS < Oxidized::Model
using Refinements
# CheckPoint - Gaia OS Model
# Gaia Prompt
prompt /^([\[\]\w.@:-]+[#>]\s?)$/
# Comment tag
comment '# '
cmd :all do |cfg|
cfg.cut_both
end
cmd :secret do |cfg|
cfg.gsub! /^(set expert-password-hash ).*/, '\1<EXPERT PASSWORD REMOVED>'
cfg.gsub! /^(set user \S+ password-hash ).*/, '\1<USER PASSWORD REMOVED>'
cfg.gsub! /^(set ospf .* secret ).*/, '\1<OSPF KEY REMOVED>'
cfg.gsub! /^(set snmp community )(.*)( read-only.*)/, '\1<SNMP COMMUNITY REMOVED>\3'
cfg.gsub! /^(add snmp .* community )(.*)(\S?.*)/, '\1<SNMP COMMUNITY REMOVED>\3'
cfg.gsub! /(auth|privacy)(-pass-phrase-hashed )(\S*)/, '\1-pass-phrase-hashed <SNMP PASS-PHRASE REMOVED>'
cfg
end
# check for vsx / multiple context
cmd 'show vsx' do |cfg|
@is_vsx = cfg.include? 'VSX Enabled'
Oxidized.logger.debug cfg
end
cmd 'show asset all' do |cfg|
comment cfg
end
cmd 'show version all' do |cfg|
comment cfg
end
post do
if @is_vsx
multiple_context
else
single_context
end
end
def single_context
Oxidized.logger.debug 'Single context tasks'
cmd 'show configuration' do |cfg|
cfg.gsub! /^# Exported by \S+ on .*/, '# '
cfg
end
end
def multiple_context
Oxidized.logger.debug 'Multi context tasks'
cmd 'show virtual-system all' do |systems|
vs_items = systems.scan(/^(?<VSID>\d+)\s+(?<VSNAME>.*[^\s])/)
allcfg = ''
vs_items.each do |item|
allcfg += "\n\n\n#--------======== [ VS #{item[0]} - #{item[1]} ] ========--------\n\n"
allcfg += "set virtual-system #{item[0]}\n\n"
cmd "set virtual-system #{item[0]}" do |vs|
Oxidized.logger.debug vs
cmd 'show configuration' do |vscfg|
vscfg.gsub! /^# Exported by \S+ on .*/, '# '
allcfg += vscfg
end
end
end
allcfg
end
end
cfg :ssh do
# User shell must be /etc/cli.sh
post_login 'set clienv rows 0'
pre_logout 'exit'
end
end