Skip to content

Instantly share code, notes, and snippets.

@mdpuma
Created December 13, 2020 07:18
Show Gist options
  • Select an option

  • Save mdpuma/0df4bc4fe6dd8d0aad6d0445902a9f63 to your computer and use it in GitHub Desktop.

Select an option

Save mdpuma/0df4bc4fe6dd8d0aad6d0445902a9f63 to your computer and use it in GitHub Desktop.
VSOL OLT oxidized model
class VSOLOLT < Oxidized::Model
prompt /^([\w.@()-]+[#>]\s?)$/
comment '! '
cmd :all do |cfg|
cfg.gsub! /^% Invalid input detected at '\^' marker\.$|^\s+\^$/, ''
cfg.cut_both
end
# cmd :secret do |cfg|
# cfg.gsub! /^(snmp-server community).*/, '\\1 <configuration removed>'
# cfg.gsub! /^(tacacs-server (.+ )?key) .+/, '\\1 <secret hidden>'
# cfg.gsub! /^username (\S+) privilege (\d+) (\S+).*/, '<secret hidden>'
# cfg.gsub! /^(enable (password|secret)( level \d+)? \d) .+/, '\\1 <secret hidden>'
# cfg
# end
# cmd 'show version-running' do |cfg|
# comment cfg
# end
#
# cmd 'show patch-running' do |cfg|
# comment cfg
# end
cmd 'show running-config' do |cfg|
cfg.gsub! /^Current configuration:/, ''
cfg
end
cfg :telnet do
username /^Login:/i
password /^Password:/i
end
cfg :telnet, :ssh do
# preferred way to handle additional passwords
post_login do
if vars(:enable) == true
cmd "enable"
elsif vars(:enable)
cmd "enable", /^[pP]assword:/
cmd vars(:enable)
end
end
post_login 'terminal length 0'
pre_logout 'disable'
pre_logout 'exit'
end
end
@CharlyBote
Copy link

Hi!
I try to use this script, but doesn't work for me.
The OLT Model is 1600G1.
Can you help me with this?

my debbug

D, [2021-05-19T15:26:20.933982 #54012] DEBUG -- : lib/oxidized/worker.rb: Added default/xxx.xxx.xxx.xxx to the job queue
D, [2021-05-19T15:26:20.934057 #54012] DEBUG -- : lib/oxidized/worker.rb: 1 jobs running in parallel
D, [2021-05-19T15:26:20.934014 #54012] DEBUG -- : lib/oxidized/job.rb: Starting fetching process for xxx.xxx.xxx.xxx at 2021-05-19 18:26:20 UTC
D, [2021-05-19T15:26:20.934141 #54012] DEBUG -- : lib/oxidized/input/ssh.rb: Connecting to xxx.xxx.xxx.xxx
D, [2021-05-19T15:26:20.934207 #54012] DEBUG -- : AUTH METHODS::["none", "publickey", "password"]
D, [2021-05-19T15:26:21.487078 #54012] DEBUG -- : lib/oxidized/input/ssh.rb: expecting [/^([\w.@()-]+[#>]\s?)$/] at xxx.xxx.xxx.xxx
W, [2021-05-19T15:26:41.487479 #54012] WARN -- : xxx.xxx.xxx.xxx raised Oxidized::PromptUndetect with msg "
Hello, this is gpon olt platform (version 1.00).
Copyright 2016-2028,All Rights Reserved.
User Access Verification
Entering character mode
Escape character is '^]'.
Login: not matching configured prompt (?-mix:^([\w.@()-]+[#>]\s?)$)"
D, [2021-05-19T15:26:41.487525 #54012] DEBUG -- : lib/oxidized/node.rb: Oxidized::SSH failed for xxx.xxx.xxx.xxx
D, [2021-05-19T15:26:41.487546 #54012] DEBUG -- : lib/oxidized/job.rb: Config fetched for xxx.xxx.xxx.xxx at 2021-05-19 18:26:41 UTC
W, [2021-05-19T15:26:41.937564 #54012] WARN -- : default/xxx.xxx.xxx.xxx status no_connection, retry attempt 1

ssh login

ssh [email protected]
[email protected]'s password:
Hello, this is gpon olt platform (version 1.00).
Copyright 2016-2028,All Rights Reserved.
User Access Verification
Entering character mode
Escape character is '^]'.
Login: admin
Password:
OLT> en
Password:
2021/05/19 15:53:19 User Login User admin logged in from xxx.xxx.xxx.xxx on vty
OLT#

@WojRep
Copy link

WojRep commented Aug 2, 2022

Small change -> VSOL V1600G1 OLT series -> ssh connection:


  prompt /^([\w.@()-]+[#>]\s?)$/
  comment  '! '

  cmd :all do |cfg|
    cfg.gsub! /^% Invalid input detected at '\^' marker\.$|^\s+\^$/, ''
    cfg.cut_both
  end

#   cmd :secret do |cfg|
#     cfg.gsub! /^(snmp-server community).*/, '\\1 <configuration removed>'
#     cfg.gsub! /^(tacacs-server (.+ )?key) .+/, '\\1 <secret hidden>'
#     cfg.gsub! /^username (\S+) privilege (\d+) (\S+).*/, '<secret hidden>'
#     cfg.gsub! /^(enable (password|secret)( level \d+)? \d) .+/, '\\1 <secret hidden>'
#     cfg
#   end

#   cmd 'show version-running' do |cfg|
#     comment cfg
#   end
# 
#   cmd 'show patch-running' do |cfg|
#     comment cfg
#   end

  cmd 'show running-config' do |cfg|
	cfg.gsub! /^Current configuration:/, ''
    cfg
  end

  cfg :telnet, :ssh do
    username /^Login:/i
    password /^Password:/i
    # preferred way to handle additional passwords
    post_login do
      if vars(:enable) == true
        cmd "enable"
      elsif vars(:enable)
        cmd "enable", /^[pP]assword:/
        cmd vars(:enable)
      end
    end
    post_login 'terminal length 0'
    pre_logout 'disable'
    pre_logout 'exit'
  end
end

@AAm-kun
Copy link

AAm-kun commented Mar 14, 2024

FOR
Hardware Version V1.3.4 Firmware Version V2.03.75R (tested on UPLINK EPON OLT 4440 as it seems to use the same firmware as VSOL)

This also works for UPLINK EPON OLT 4440 or should work on any uplink OLT.

class VSOLOLT < Oxidized::Model

  prompt /^([\w.@()-]+[#>]\s?)$/
  comment  '! '

  cmd :all do |cfg|
    cfg.gsub! /^% Invalid input detected at '\^' marker\.$|^\s+\^$/, ''
    cfg.gsub!(/^show running-config$/, '')
    cfg.gsub!(/^.*\s*#\s*$/, '')

    # Remove leading and trailing whitespace
    cfg.strip!

    # Remove empty lines
    cfg.gsub!(/^\s*$/, '')

    cfg
  end


  cmd 'show running-config' do |cfg|
        cfg.gsub! /^Current configuration:/, ''
    cfg
  end

  cfg :telnet, :ssh do
    username /^Login:/i
    password /^Password:/i
    # preferred way to handle additional passwords
    post_login do
      if vars(:enable) == true
        cmd "enable"
      elsif vars(:enable)
        cmd "enable", /^[pP]assword:/
        cmd vars(:enable)
      end
    end
    post_login 'terminal length 0'
    pre_logout 'disable'
    pre_logout 'exit'
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment