ytti / oxidized

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

Oxidized::Telnet failed OneOS equipements #2174

Closed sgalliani-efs closed 4 years ago

sgalliani-efs commented 4 years ago

Hello,

I've been trying to backup our internet provides routeurs from the company Orange which are Oneaccess but it's been painfull and a bunch of issues keep happening.

I had no problem with cisco equipements that use ssh but for some reason the telnet on the oneos keep failing nonstop, i've tried chaging the oneos.rb file and checked my config file but nothin seems to help.

I know telnet works towards this equipement cause i can manually connect to them in cli.

Here is my config file :

model: hpe
interval: 3600
log: /home/oxidized/.config/oxidized/log
debug: true
threads: 30
timeout: 100
retries: 2
prompt: !ruby/regexp /^([\w.@-]+[#>]\s?)$/
next_adds_job: false
vars:
  remove_secret: true
groups: {}
models: {}
pid: /home/oxidized/.config/oxidized/pid
input:
  default: telnet
  debug: true
  ssh:
    secure: true
output:
  default: git
  git:
    single_repo: false
    user: Oxidized
    email: farid.mallem.ext@efs.sante.fr
    repo: "~/.config/oxidized/default.git"
  file:
    directory: "/home/oxidized/.config/oxidized/configs"
source:
  default: csv
  csv:
    file: "/home/oxidized/.config/oxidized/router.db"
    delimiter: !ruby/regexp /:/
    map:
      name: 0
      ip: 1
      model: 2
      username: 3
      password: 4

model_map:
  orange: oneos
  cisco: ios
  h3c: comware
  alc: aos
  omni: ciscosmb

and here is the oneos.rb :

class OneOS < Oxidized::Model
#  prompt /^([\w.@()-]+#\s?)$/
#  prompt /^([\w.@-]+[#>]\s?)$/
#  prompt /^([\w.@()-]+[#>]\s?)$/
#  prompt /^([\w.@-]+[#>]\s?)$/
#  prompt /^([\w.@-]+[#>]\s?)$/
  prompt /^([\w.@()-]+[#>]\s?)$/

  comment  '! '

  # example how to handle pager
  # expect /^\s--More--\s+.*$/ do |data, re|
  #  send ' '
  #  data.sub re, ''
  # end

  # non-preferred way to handle additional PW prompt
  # expect /^[\w.]+>$/ do |data|
  #  send "enable\n"
  #  send vars(:enable) + "\n"
  #  data
  # end

  cmd :all do |cfg|
    # cfg.gsub! /\cH+\s{8}/, ''         # example how to handle pager
    # cfg.gsub! /\cH+/, ''              # example how to handle pager
    cfg.cut_both
  end

#  cmd :secret do |cfg|
#    cfg.gsub! /^(snmp set-read-community ").*+?(".*)$/, '\\1<secret hidden>\\2'
#    cfg
#  end

  cmd "show version\r" do |cfg|
    comment cfg
  end
  cmd "show system hardware\r" do |cfg|
    comment cfg
  end

#  cmd 'show product-info-area' do |cfg|
#    comment cfg
#  end

  cmd "show running-config\r" do |cfg|
    cfg = cfg.each_line.to_a[0..-1].join
    cfg.gsub! /^Building configuration...\s*[^\n]*\n/, ''
    cfg.gsub! /^Current configuration :\s*[^\n]*\n/, ''
    cfg
  end

#  cfg :telnet do
#    username /^Username:/
#    password /^Password:/
#  end
#  cmd :secret do |cfg|
#    cfg.gsub! /^(snmp set-read-community ").*+?(".*)$/, '\\1<secret hidden>\\2'
#    cfg
#  end

  cmd "show version\r" do |cfg|
    comment cfg
  end
  cmd "show system hardware\r" do |cfg|
    comment cfg
  end

#  cmd 'show product-info-area' do |cfg|
#    comment cfg
#  end

  cmd "show running-config\r" do |cfg|
    cfg = cfg.each_line.to_a[0..-1].join
    cfg.gsub! /^Building configuration...\s*[^\n]*\n/, ''
    cfg.gsub! /^Current configuration :\s*[^\n]*\n/, ''
    cfg
  end

#  cfg :telnet do
#    username /^Username:/
#    password /^Password:/
#  end

  cfg :telnet, :ssh do
    # preferred way to handle additional passwords
    if vars :enable
      post_login do
        send "enable"
        cmd vars(:enable)
     end
    end
    post_login "term len 0\r"
    pre_logout "exit\r"
  end
end

and these are the type of errors i keep getting :

D, [2020-08-25T14:05:14.467479 #2687] DEBUG -- : lib/oxidized/worker.rb: 1 jobs running in parallel
W, [2020-08-25T14:05:14.478912 #2687]  WARN -- : 10.22.254.10 raised EOFError (rescued IOError) with msg "end of file reached"
D, [2020-08-25T14:05:14.478988 #2687] DEBUG -- : lib/oxidized/node.rb: Oxidized::Telnet failed for RENNES_Secours
D, [2020-08-25T14:05:14.479019 #2687] DEBUG -- : lib/oxidized/job.rb: Config fetched for RENNES_Secours at 2020-08-25 14:05:14 UTC
W, [2020-08-25T14:05:15.467855 #2687]  WARN -- : /RENNES_Secours status no_connection, retry attempt 1
D, [2020-08-25T14:05:15.467959 #2687] DEBUG -- : lib/oxidized/worker.rb: Jobs running: 0 of 1 - ended: 1 of 6
D, [2020-08-25T14:05:15.468061 #2687] DEBUG -- : lib/oxidized/worker.rb: Added /RENNES_Secours to the job queue
D, [2020-08-25T14:05:15.468082 #2687] DEBUG -- : lib/oxidized/worker.rb: 1 jobs running in parallel
D, [2020-08-25T14:05:15.468264 #2687] DEBUG -- : lib/oxidized/job.rb: Starting fetching process for RENNES_Secours at 2020-08-25 14:05:15 UTC
D, [2020-08-25T14:05:16.468249 #2687] DEBUG -- : lib/oxidized/worker.rb: 1 jobs running in parallel

If anyone would have any idea why it keeps failing so much and why can't oxidized establish a telnet connection to my equipements,

thanks,

Stef

sgalliani-efs commented 4 years ago

Well egg on my face, the solution was in front of my face, i didn't put the right lines in my oneos.rb profile so it would work with telnet :

class OneOS < Oxidized::Model
#  prompt /^([\w.@()-]+#\s?)$/
#  prompt /^([\w.@-]+[#>]\s?)$/
#  prompt /^([\w.@()-]+[#>]\s?)$/
#  prompt /^([\w.@-]+[#>]\s?)$/
#  prompt /^([\w.@-]+[#>]\s?)$/
  prompt /^([\w.@()-]+[#>]\s?)$/

  comment  '! '

  cmd "show running-config\r" do |cfg|
    cfg = cfg.each_line.to_a[0..-1].join
    cfg.gsub! /^Building configuration...\s*[^\n]*\n/, ''
    cfg.gsub! /^Current configuration :\s*[^\n]*\n/, ''
    cfg
  end

  cfg :telnet do
    username /^Username:/
    password /^Password:/
  end

  cfg :telnet, :ssh do
    # preferred way to handle additional passwords
    if vars :enable
      post_login do
        send "enable"
        cmd vars(:enable)
     end
    end
    post_login "term len 0\r"
    pre_logout "exit\r"
  end