oxidized icon indicating copy to clipboard operation
oxidized copied to clipboard

Netgear devices do not work properly

Open mWachu opened this issue 2 years ago • 1 comments

Hello,

I've just installed 0.28 Version of oxidized and i have encountered issue with pulling configuration from Netgear devices. Screenshot 2022-07-25 at 23 33 21

It seems like "enable" is not triggered for some reason.

mWachu avatar Jul 25 '22 21:07 mWachu

Could you please paste your config file and your device input (yml, output from librenms, etc.)

mortzu avatar Aug 01 '22 14:08 mortzu

Which switch model is it? I saw similar symptoms on GS308T, which is in their "Smart Managed Pro" series. I have been fiddling with the netgear.rb model file to get it working, and it's now at a stage where it works decently for me: Oxidized can SSH to the switch and extract the config.

But the model file got more messy than I'd like, and for all I know it might break for other Netgear devices, so I wonder if the OS in the Smart Managed Pro series is different enough from the OS that netgear.rb was written for that it might merit a separate model file.

If you're interested, here's a diff showing my changes to lib/oxidized/model/netgear.rb:

--- a/lib/oxidized/model/netgear.rb
+++ b/lib/oxidized/model/netgear.rb
@@ -1,10 +1,16 @@
 class Netgear < Oxidized::Model
   comment '!'
-  prompt /^(\([\w\s\-.]+\)\s[#>])$/
+  prompt /((\(?[\w\s\-.]+\)?\s?[#>]\s?)$)/
+
+  expect /--More--/ do |data, re|
+    send ' '
+    data.sub re, ''
+  end
 
   cmd :secret do |cfg|
     cfg.gsub!(/password (\S+)/, 'password <hidden>')
     cfg.gsub!(/encrypted (\S+)/, 'encrypted <hidden>')
+    cfg.gsub!(/snmp community (\S+) (.*)$/, 'snmp community <hidden> \\2')
     cfg.gsub!(/snmp-server community (\S+)$/, 'snmp-server community <hidden>')
     cfg.gsub!(/snmp-server community (\S+) (\S+) (\S+)/, 'snmp-server community \\1 \\2 <hidden>')
     cfg
@@ -24,20 +30,28 @@ class Netgear < Oxidized::Model
         cmd vars(:enable)
       end
     end
-    post_login 'terminal length 0'
+    if !vars(:smartpro) || vars(:smartpro) == false
+      post_login 'terminal length 0'
+    end
     # quit / logout will sometimes prompt the user:
     #
     #     The system has unsaved changes.
     #     Would you like to save them now? (y/n)
     #
     # As no changes will be made over this simple SSH session, we can safely choose "n" here.
-    pre_logout 'quit'
-    pre_logout 'n'
+    if vars(:smartpro) == true
+      pre_logout 'exit'
+      pre_logout 'exit'
+    else 
+      pre_logout 'quit'
+      pre_logout 'n'
+    end
   end
 
   cmd :all do |cfg, cmdstring|
     new_cfg = comment "COMMAND: #{cmdstring}\n"
     new_cfg << cfg.each_line.to_a[1..-2].join
   end
 
   cmd 'show version' do |cfg|
@@ -48,8 +62,14 @@ class Netgear < Oxidized::Model
   cmd 'show bootvar' do |cfg|
     comment cfg
   end
+
   cmd 'show running-config' do |cfg|
-    cfg.gsub! /(System Up Time\s+).*/, '\\1 <removed>'
+    cfg.gsub! /(System Up Time).*/, '\\1 <removed>'
+    cfg.gsub! /\e\[.\e\[.K/, ''
+    cfg.gsub! /\cH/, ''
     cfg.gsub! /(Current SNTP Synchronized Time:).*/, '\\1 <removed>'
+    cfg
   end
 end

oyvindmo avatar Nov 17 '22 09:11 oyvindmo

I've worked on collecting the patch mentioned here and some related pieces to work with my gs108t and gs324t switches here: https://github.com/arrjay/oxidized/tree/netgear-model-fixes

arrjay avatar Nov 24 '22 22:11 arrjay