forked from ytti/oxidized
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouteros.rb
63 lines (55 loc) · 2.01 KB
/
routeros.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
class RouterOS < Oxidized::Model
prompt /\[\w+@\S+(\s+\S+)*\]\s?>\s?$/
comment "# "
cmd :all do |cfg|
cfg.gsub! /\x1B\[([0-9]{1,3}(;[0-9]{1,3})*)?[m|K]/, '' # strip ANSI colours
if screenscrape
cfg = cfg.cut_both
cfg.gsub! /^\r+(.+)/, '\1'
cfg.gsub! /([^\r]*)\r+$/, '\1'
end
cfg
end
cmd '/system routerboard print without-paging' do |cfg|
cfg = cfg.each_line.grep(/(model|firmware-type|current-firmware|serial-number):/).join
comment cfg
end
cmd '/system package update print without-paging' do |cfg|
version_line = cfg.each_line.grep(/installed-version: /)[0]
comment version_line
@ros_version = /: ([0-9])/.match(version_line)[1].to_i
end
cmd '/system history print without-paging' do |cfg|
comment cfg
end
post do
Oxidized.logger.debug "lib/oxidized/model/routeros.rb: running /export for routeros version #{@ros_version}"
run_cmd = if vars(:remove_secret)
'/export hide-sensitive'
elsif (not @ros_version.nil?) && (@ros_version >= 7)
'/export show-sensitive'
else
'/export'
end
cmd run_cmd do |cfg|
cfg.gsub! /\\\r?\n\s+/, '' # strip new line
cfg.gsub! /# inactive time\r\n/, '' # Remove time based system comment
cfg.gsub! /# received packet from \S+ bad format\r\n/, '' # Remove intermittent VRRP/CARP collision comment
cfg.gsub! /# poe-out status: short_circuit\r\n/, '' # Remove intermittent POE short_circuit comment
cfg.gsub! /# Firmware upgraded successfully, please reboot for changes to take effect!\r\n/, '' # Remove transient firmware upgrade comment
cfg.gsub! /# \S+ not ready\r\n/, '' # Remove intermittent $interface not ready comment
cfg = cfg.split("\n").reject { |line| line[/^#\s\w{3}\/\d{2}\/\d{4}.*$/] }
cfg.join("\n") + "\n"
end
end
cfg :telnet do
username /^Login:/
password /^Password:/
end
cfg :telnet, :ssh do
pre_logout 'quit'
end
cfg :ssh do
exec true
end
end