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

Comware switch 1920 - Oxidized config #2337

Closed jsinic closed 1 year ago

jsinic commented 3 years ago

Hi

I have troubles to get config from my Comware switch. I use Oxidized v.0.28.0.

I get only file with this input

^

% Unrecognized command found at '^' position.

^

% Unrecognized command found at '^' position.

^

% Unrecognized command found at '^' position.

           ^

% Unrecognized command found at '^' position.

I have followed tutorials, so i have changed comware.rb files

So I modified comware.rb file from: prompt /^\0(<[\w.-]+>)$/ to allow whitespaces prompt /^\0(<[\w\s.-]+>)$/

if vars :comware_cmdline post_login do

HP V1910, V1920

    cmd '_cmdline-mode on', /(#{@node.prompt}|Continue)/
    cmd 'y', /(#{@node.prompt}|input password)/
    cmd vars(:comware_cmdline)
    cmd vars(:enable)

Config in config

map: name: 0 model: 1 ip: 2 group: 3 username: 4 password: 5 var_maps: enable: 6 comware_cmdline: 6

Config in router.db

HP_1920:comware:ip_address:HP:username:password:Jinhua1920unauthorized

Could you help me with this trouble?

xosepe commented 3 years ago

Hi, I use those switches successfully with oxidized 0.23. My config file:

    map:
      name: 0
      model: 1
      ip: 2
      username: 3
      password: 4
    vars_map:
      comware_cmdline: 5
      enable: 6

You have a number 6 for both enable and comware_cmdline

jsinic commented 3 years ago

I have modified config file to yours config. but error is still here.

Do I need put some special configuration on switch?

In logs I have errors AUTH METHODS::["none", "publickey", "password"] D, [2021-09-01T20:47:14.190484 #33015] DEBUG -- : lib/oxidized/input/ssh.rb: expecting [/^\0(<[\w.-]+>).?$/] at HP_1920_192.168.1.253 D, [2021-09-01T20:47:14.873932 #33015] DEBUG -- : lib/oxidized/worker.rb: 1 jobs running in parallel D, [2021-09-01T20:47:14.991902 #33015] DEBUG -- : lib/oxidized/input/cli.rb: Running post_login commands at HP_1920_192.168.1.253 D, [2021-09-01T20:47:14.991951 #33015] DEBUG -- : lib/oxidized/input/cli.rb: Running post_login command: "screen-length disable", block: nil at HP_1920_192.168.1.253 D, [2021-09-01T20:47:14.991975 #33015] DEBUG -- : lib/oxidized/input/ssh.rb screen-length disable @ HP_1920_192.168.1.253 with expect: /^\0(<[\w.-]+>).?$/ D, [2021-09-01T20:47:14.992057 #33015] DEBUG -- : lib/oxidized/input/ssh.rb: expecting [/^\0(<[\w.-]+>).?$/] at HP_1920_192.168.1.253 D, [2021-09-01T20:47:15.393497 #33015] DEBUG -- : lib/oxidized/input/cli.rb: Running post_login command: "undo terminal monitor", block: nil at HP_1920_192.168.1.253 D, [2021-09-01T20:47:15.393582 #33015] DEBUG -- : lib/oxidized/input/ssh.rb undo terminal monitor @ HP_1920_192.168.1.253 with expect: /^\0(<[\w.-]+>).?$/ D, [2021-09-01T20:47:15.393703 #33015] DEBUG -- : lib/oxidized/input/ssh.rb: expecting [/^\0*(<[\w.-]+>).?$/] at HP_1920_192.168.1.253 D, [2021-09-01T20:47:15.797911 #33015] DEBUG -- : lib/oxidized/model/model.rb Collecting commands' outputs D, [2021-09-01T20:47:15.797982 #33015] DEBUG -- : lib/oxidized/model/model.rb Executing display version

Could you share your config file and comware.rb file with me?

xosepe commented 3 years ago

Hi! I don't have debug enabled and I´m afraid I cannot change it now.

This is my comware.rb file:

# more /usr/local/share/gems/gems/oxidized-0.24.0/lib/oxidized/model/comware.rb
class Comware < Oxidized::Model
  # HP (A-series)/H3C/3Com Comware

  # sometimes the prompt might have a leading nul or trailing ASCII Bell (^G)
  prompt /^\0*(<[\w.-]+>).?$/
  comment '# '

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

  cmd :all do |cfg|
    # cfg.gsub! /^.*\e\[42D/, ''        # example how to handle pager
    # skip rogue ^M
    cfg = cfg.gsub /\r/, ''
#    cfg.each_line.to_a[1..-2].join  Mine: I change this line to log the commands as well
    cfg.each_line.to_a[0..-1].join
  end

  cmd :secret do |cfg|
    cfg.gsub! /^( snmp-agent community).*/, '\\1 <configuration removed>'
    cfg.gsub! /^( password hash).*/, '\\1 <configuration removed>'
    cfg
  end

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

  cfg :telnet, :ssh do
    # enable command-line mode on SMB comware switches (HP V1910, V1920)
    # autodetection is hard, because the 'summary' command is paged, and
    # the pager cannot be disabled before _cmdline-mode on.
    if vars :comware_cmdline
      post_login do
        send "_cmdline-mode on\n"
        send "y\n"
        send vars(:comware_cmdline) + "\n"
        send "xtd-cli-mode on\n"
        send "y\n"
        send vars(:comware_cmdline) + "\n"
        send "screen-length disable\n"
        send "undo terminal monitor\n"
      end
    end

    post_login 'screen-length disable'
    post_login 'undo terminal monitor'
    pre_logout 'quit'
  end

  cmd 'display version' do |cfg|
#      cfg = cfg.each_line.reject { |l| l.match /uptime/i }.join
    comment cfg
  end

  cmd 'display current-configuration' do |cfg|
    cfg
  end

end
xosepe commented 3 years ago

This is the beginning of the file I get:

# y
#          ^
#  % Unrecognized command found at '^' position.
# <HPE>Jinhua1920unauthorized
         ^
 % Unrecognized command found at '^' position.
<HPE>screen-length disable
% Screen-length configuration is disabled for current user.
<HPE>undo terminal monitor
Info: Current terminal monitor is off.

<HPE># screen-length disableundo terminal monitor
#                        ^
#  % Unrecognized command found at '^' position.
# <HPE># display version
# HP Comware Platform Software
# Comware Software, Version 5.20.99, Release 1105
# Copyright (c) 2010-2014 Hewlett-Packard Development Company, L.P.
# HP 1920-8G Switch uptime is 4 weeks, 3 days, 0 hour, 20 minutes
# 
# HP 1920-8G Switch
# 128M    bytes DRAM
# 32M     bytes Flash Memory
# Config Register points to Flash
# 
# Hardware Version is REV.A
# Bootrom Version is 110
# [SubSlot 0] 8GE+2SFP Hardware Version is REV.A
# 
# <HPE># display current-configuration
# #
#  version 5.20.99, Release 1105
# #
#  sysname HPE
# #
#  clock timezone Amsterdam add 01:00:00

And I have to say that, with this model 1920-8G, the file is usually not complete... I have an extension of the comware.rb file to add lots of commands, and the file usually breaks around the middle not always in the same point. These are my other commands (from the logbuffer of the HP):

# %Jun 16 03:59:20:756 2021 HPE SC/6/SC_AAA_LAUNCH: -AAAType=AUTHEN-AAAScheme= local-Service=login-UserName=admin@system; AAA launched.
# %Jun 16 03:59:20:757 2021 HPE SC/6/SC_AAA_SUCCESS: -AAAType=AUTHEN-AAAScheme= local-Service=login-UserName=admin@system; AAA is successful.
# %Jun 16 03:59:20:758 2021 HPE SC/6/SC_AAA_LAUNCH: -AAAType=AUTHOR-AAAScheme= local-Service=login-UserName=admin@system; AAA launched.
# %Jun 16 03:59:20:759 2021 HPE SC/6/SC_AAA_SUCCESS: -AAAType=AUTHOR-AAAScheme= local-Service=login-UserName=admin@system; AAA is successful.
# %Jun 16 03:59:20:761 2021 HPE SC/6/SC_AAA_LAUNCH: -AAAType=ACCOUNT-AAAScheme= local-Service=login-UserName=admin@system; AAA launched.
# %Jun 16 03:59:20:762 2021 HPE SC/6/SC_AAA_SUCCESS: -AAAType=ACCOUNT-AAAScheme= local-Service=login-UserName=admin@system; AAA is successful.
# %Jun 16 03:59:20:765 2021 HPE SHELL/5/SHELL_LOGIN: admin logged in from 10.0.0.1.
# %Jun 16 03:59:20:794 2021 HPE SHELL/6/SHELL_CMD: -Task=vt0-IPAddr=10.0.0.1-User=admin; Command is _cmdline-mode on
# %Jun 16 03:59:20:923 2021 HPE SHELL/6/SHELL_CMD: -Task=vt0-IPAddr=10.0.0.1-User=admin; Command is screen-length disable
# %Jun 16 03:59:20:960 2021 HPE SHELL/6/SHELL_CMD: -Task=vt0-IPAddr=10.0.0.1-User=admin; Command is undo terminal monitor
# %Jun 16 03:59:21:077 2021 HPE SHELL/6/SHELL_CMD: -Task=vt0-IPAddr=10.0.0.1-User=admin; Command is display version
# %Jun 16 03:59:21:140 2021 HPE SHELL/6/SHELL_CMD: -Task=vt0-IPAddr=10.0.0.1-User=admin; Command is display current-configuration
# %Jun 16 03:59:21:794 2021 HPE SHELL/6/SHELL_CMD: -Task=vt0-IPAddr=10.0.0.1-User=admin; Command is display clock
# %Jun 16 03:59:21:852 2021 HPE SHELL/6/SHELL_CMD: -Task=vt0-IPAddr=10.0.0.1-User=admin; Command is display device manuinfo
# %Jun 16 03:59:21:913 2021 HPE SHELL/6/SHELL_CMD: -Task=vt0-IPAddr=10.0.0.1-User=admin; Command is display device verbose
# %Jun 16 03:59:21:962 2021 HPE SHELL/6/SHELL_CMD: -Task=vt0-IPAddr=10.0.0.1-User=admin; Command is display environment
# %Jun 16 03:59:22:010 2021 HPE SHELL/6/SHELL_CMD: -Task=vt0-IPAddr=10.0.0.1-User=admin; Command is display cpu
# %Jun 16 03:59:22:061 2021 HPE SHELL/6/SHELL_CMD: -Task=vt0-IPAddr=10.0.0.1-User=admin; Command is display memory
# %Jun 16 03:59:22:136 2021 HPE SHELL/6/SHELL_CMD: -Task=vt0-IPAddr=10.0.0.1-User=admin; Command is display interface brief
# %Jun 16 03:59:22:271 2021 HPE SHELL/6/SHELL_CMD: -Task=vt0-IPAddr=10.0.0.1-User=admin; Command is display arp
# %Jun 16 03:59:22:385 2021 HPE SHELL/6/SHELL_CMD: -Task=vt0-IPAddr=10.0.0.1-User=admin; Command is display mac-address
# %Jun 16 03:59:22:778 2021 HPE SHELL/6/SHELL_CMD: -Task=vt0-IPAddr=10.0.0.1-User=admin; Command is display link-aggregation verbose
# %Jun 16 03:59:22:830 2021 HPE SHELL/6/SHELL_CMD: -Task=vt0-IPAddr=10.0.0.1-User=admin; Command is display stp brief
# %Jun 16 03:59:22:879 2021 HPE SHELL/6/SHELL_CMD: -Task=vt0-IPAddr=10.0.0.1-User=admin; Command is display stp root
# %Jun 16 03:59:23:063 2021 HPE SHELL/6/SHELL_CMD: -Task=vt0-IPAddr=10.0.0.1-User=admin; Command is display stp
# %Jun 16 03:59:23:167 2021 HPE SHELL/6/SHELL_CMD: -Task=vt0-IPAddr=10.0.0.1-User=admin; Command is dir
# %Jun 16 03:59:23:264 2021 HPE SHELL/6/SHELL_CMD: -Task=vt0-IPAddr=10.0.0.1-User=admin; Command is display lldp neighbor-information
# %Jun 16 03:59:23:511 2021 HPE SHELL/6/SHELL_CMD: -Task=vt0-IPAddr=10.0.0.1-User=admin; Command is display logbuffer
# %Jun 16 03:59:23:784 2021 HPE SHELL/6/SHELL_CMD: -Task=vt0-IPAddr=10.0.0.1-User=admin; Command is display interface
# %Jun 16 03:59:24:112 2021 HPE SHELL/6/SHELL_CMD: -Task=vt0-IPAddr=10.0.0.1-User=admin; Command is quit
# %Jun 16 03:59:24:118 2021 HPE SHELL/5/SHELL_LOGOUT: admin logged out from 10.0.0.1.

It usually breaks around the LLDP command

xosepe commented 3 years ago

And this is my config file, but I´m no expert, so, please don´t trust it:

# more config
---
username: admin
password: xxxxxxxxx
model: comware
resolve_dns: false
interval: 604800
use_syslog: false
debug: false
threads: 10
timeout: 300
retries: 2
#prompt: !ruby/regexp /^([\w.@-]+[#>]\s?)$/
rest: 127.0.0.1:8888
next_adds_job: false
vars: {}
groups: {}
models: {}
pid: /root/.config/oxidized/pid
stats:
  history_size: 150
input:
  default: ssh, telnet
  debug: false
  ssh:
    secure: false
  ftp:
    passive: true
  utf8_encoded: true
output:
  default: git
  git:
    user: root
    email: oxidized@oxidized@.com
    repo: /backups

source:
  default: csv
  csv:
    file: /root/.config/oxidized/router.db
    delimiter: !ruby/regexp /:/
    map:
      name: 0
      model: 1
      ip: 2
      username: 3
      password: 4
    vars_map:
      comware_cmdline: 5
      enable: 6
model_map:
  cisco: ios
  juniper: junos
  hp: comware
xosepe commented 3 years ago

router.db line:

HPE:comware:10.0.10.150:admin:PassWord:Jinhua1920unauthorized

jduke-halls commented 2 years ago

Hi @xosepe. I found this page when looking for a solution to our comware problem. We got ours working, but I noticed your comware.rb had send rather than cmd than ours. It appears that we're using the one from the master branch (downloadable at https://github.com/ytti/oxidized/blob/master/lib/oxidized/model/comware.rb ` if vars :comware_cmdline post_login do

HP V1910, V1920

    cmd '_cmdline-mode on', /(#{@node.prompt}|Continue)/
    cmd 'y', /(#{@node.prompt}|input password)/
    cmd vars(:comware_cmdline)

    # HP V1950
    cmd 'xtd-cli-mode on', /(#{@node.prompt}|Continue)/
    cmd 'y', /(#{@node.prompt}|input password)/
    cmd vars(:comware_cmdline)
  end
end

`

I'm still a newbie with oxidized, but found this page while I was looking at getting ours running to pull config on a single comware switch. Hope it helps.

xosepe commented 2 years ago

Hi jduke, have in mind that I´m using an old version of oxidized: 0.23. I don´t know Ruby, but I guess that's the reason for that difference. ;)