ytti / oxidized

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

exclude some lines from backup #2247

Closed maddog-nn closed 2 years ago

maddog-nn commented 3 years ago

Hello, We have a lot of commits from some Dell equipment like VRTX switches when temperature changes on switch. I mean temperature info includes in output of 'show system' command. How we can exclude this information from output or ignore if temperature differs from previous temperature value? For example here is one of the last diffs:

index 71ca426..79f0dbb 100644
--- a/TEST/test-vrtx01
@@ -12,7 +12,7 @@
 ! 
 ! Unit            Temperature (Celsius)            Status
 ! ------------------------ ------------------------ ------------------------
-! 1                        45                       OK

config-file-header
 test-vrtx01
index 79f0dbb..71ca426 100644
+++ b/TEST/test-vrtx01
@@ -12,7 +12,7 @@
 ! 
 ! Unit            Temperature (Celsius)            Status
 ! ------------------------ ------------------------ ------------------------
+! 1                        40                       OK

config-file-header
 test-vrtx01

Thank you in advance!

davama commented 3 years ago

Probably a good start

https://github.com/ytti/oxidized/pull/1681

graceless70 commented 3 years ago

Look at 2078

cmd 'show system' do |cfg|

cfg.gsub! /^(System Up Time)./, '' cfg.gsub! /^(\sUnit\sTemperature)./, '' # Remove temperature table heading cfg.gsub! /^((-{24}\s){2}-{24}).$/, '' # Remove temperature table line cfg.gsub! /^(\s{10,11}\d).*/, '' # Remove temperature table values comment cfg.lines.to_a[5..-5].join

end

I did submit a vrtx.rb but it hasn't shown up. I might have done it. Bit of a github noob

I can add the file next week to this thread

davama commented 3 years ago

If you looking to add your own “cfg.secret” removal block you can look here:

https://github.com/ytti/oxidized/blob/master/docs/Creating-Models.md#monkey-patching-blocks-in-existing-models

That way you do not affect the default model for when you update oxidized and you have your own model which removes code at your discretion. In this case your temperature output.

maddog-nn commented 3 years ago

Hi guys, i'm pretty new in ruby so could you please explain more detailed what should i do?

davama commented 3 years ago

Here is a sample of what we do with Procurve model. We use the default model provided by oxidized but use our own secret block as stated in the previous link. At the end run some additional show cmds but irrelevant to this thread.

cat .config/oxidized/model/procurve.rb

require 'oxidized/model/procurve.rb'

class Procurve < Oxidized::Model
  prompt /^\r?(\w+\-\w+\-\w+\-*(?i)(ap|rtr|sw|olt)\-\d+[#>]\s?)$/

  cmd :secret, clear: true do |cfg|
    cfg.gsub! /^(password)\s(\S+)\s(user-name)\s(\S+)\s(\S+)\s(\S+)$/, '\\1 \\2 \\3 \\4 \\5 <redacted>'
    cfg.gsub! /^(snmp-server community).*/, '\\1 <redacted>'
    cfg.gsub! /^(snmp-server host).*/, '\\1 <redacted>'
    cfg.gsub! /^(radius-server key).*/, '\\1 <redacted>'
    cfg.gsub! /^(\s+((\d+\s+){2}|\d+\s+)\w+\s+(\w+\s+(Powered|Present)|Powered)\s+(AC\s+\S+|\s+)).*/, '\\1'
    cfg.gsub! /^(   Currently supplying ).*/, '\\1 <redacted>'
    cfg
  end

  pre do
    cmd 'show system power-supply | in Power|Not P|Model|---' do |cfg|
      comment cfg
    end
  end

end
mortzu commented 2 years ago

no-feedback -> closed