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

How to handle pager in comware.rb #2262

Closed pavelbischoffi closed 1 year ago

pavelbischoffi commented 3 years ago

Hi,

I am using the code in comware.rb file to archive configuration from some 3 com 5500 EI switches. But I am able to download only begining of the config output exactly to first pager (---- More ---- string) I can see in comware.rb, I am pasting below, the example how to manage pager, but I do not understand how to use it in display current config command on end of the file, has anybody some idea?

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.delete "\r"
cfg.cut_both

end

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

cfg :telnet do username /^(Username|login):/ 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
    # 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

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 device' do |cfg| comment cfg end

cmd 'display device manuinfo' do |cfg| cfg = cfg.each_line.reject { |l| l.match 'FF'.hex.chr }.join comment cfg end

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

xosepe commented 3 years ago

In case of old 3Com models (3ComOS 3.x), you need a couple to tricks to make them work, Read this link:

https://github.com/ytti/oxidized/issues/2173

In summary, you need to add these 2 lines:

info-center source default channel 1 log state off debug state off
screen-length 0

Last one under "user-interface vty 0 4". It should work with that

mortzu commented 2 years ago

Can you please reformat your paste to make it readable? (https://docs.github.com/en/github/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#quoting-code)