ytti / oxidized

Oxidized is a network device configuration backup tool. It's a RANCID replacement!
Apache License 2.0
2.75k stars 916 forks source link

Monkey patching changes the order of commands. #3209

Open sargon opened 2 months ago

sargon commented 2 months ago

When monkey patching a model with clear the output is appended instead of replaced in the same spot, e.g. enterasys.rb

require 'oxidized/model/enterasys.rb'

class Enterasys
  using Refinements

  cmd 'show system hardware', clear:true do |cfg|
    cfg = cfg.each_line.reject { |line| line.match(/RPM$/) || line.match(/Uptime:/) || line.match(/LM75:/) || line.match(/Temperature:/)}.join
    comment cfg
  end
end

leads to a configuration where the system hardware informations are appended, instead of prefixed to the configuration. When prepending (prepend:true) there are two hardware outputs in the same spot.

Lagertonne commented 2 months ago

Hi,

I had the same issue. One solution is to simply copy the whole enterasys.rb into your own model folder without using a require statement at the top and insert your own command where you want it to be in the final file. This way is also mentioned in the docs: https://github.com/ytti/oxidized/blob/master/docs/Creating-Models.md

Completely re-define an existing model by creating a file in ~/.config/oxidized/model/ with the same name as an existing model, but not require-ing the upstream model file.