Skip to content

Commit

Permalink
routeros: /export params depending on version (#2435)
Browse files Browse the repository at this point in the history
* routeros: /export params depending on version

* routeros.rb: fix rubocop offenses

* routeros.rb: add check on @ros_version

restore previous behaviour when routeros version could
not be found (run "/export" without parameters)
  • Loading branch information
azielke authored Dec 17, 2021
1 parent 879d489 commit 78a8003
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/oxidized/model/routeros.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ class RouterOS < Oxidized::Model
end

cmd '/system package update print without-paging' do |cfg|
cfg.split("\n").each do |line|
@ros_version = Regexp.last_match(1).to_i if line =~ /installed-version: ([0-9])/
end
comment cfg
end

Expand All @@ -25,7 +28,14 @@ class RouterOS < Oxidized::Model
end

post do
run_cmd = vars(:remove_secret) ? '/export hide-sensitive' : '/export show-sensitive'
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
Expand Down

0 comments on commit 78a8003

Please sign in to comment.