ytti / oxidized

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

Oxidized can't get my cisco configuration #1559

Closed wit12345 closed 1 year ago

wit12345 commented 6 years ago

I've Oxidized configured on my linux server to backup configurations from various Cisco devices. Have set these up with SSH access but there seems to be an issue that Oxidized will not run the show running config command with successful.

I can connect to the device from the command line on the oxidized server:

[oxidized@it-tests ~]$ oxidized 
Puma starting in single mode...
* Version 3.11.0 (ruby 2.0.0-p648), codename: Love Song
* Min threads: 0, max threads: 16
* Environment: development
* Listening on tcp://127.0.0.1:8888
Use Ctrl-C to stop

In my log file, I have the following output:

User Name:admin
Password:***********

sw-os5-dist-2>enable
Password:***********
enter
sw-os5-dist-2#show running-config
config-file-header
sw-os5-dist-2
v1.3.7.18 / R750_NIK_1_35_647_358
CLI v1.0
set system mode switch queues-mode 4 

file SSD indicator encrypted
@
ssd-control-start
ssd config
ssd file passphrase control unrestricted
no ssd file integrity control
ssd-control-end cb0a3fdb1f3a1af4e4430033719968c0
!
vlan database
vlan 2012-2013
exit
voice vlan id 2013
voice vlan oui-table add 0001e3 Siemens_AG_phone________
voice vlan oui-table add 00036b Cisco_phone_____________
voice vlan oui-table add 00096e Avaya___________________
voice vlan oui-table add 000fe2 H3C_Aolynk______________
More: <space>,  Quit: q or CTRL+Z, One line: <return>

It seems the script will wait for the Space command. How I can solve this?

My model file have this configuration:

class CiscoSMB < Oxidized::Model
prompt /^\r?([\w.@()-]+[#>]\s?)$/
comment  '! '

# handle paging
expect /-Press Any Key For More-+.*$/ do |data, re|
    send " "
    data.sub re, ''
end

cmd :all do |cfg|
   lines = cfg.each_line.to_a[1..-2]
   lines[0].gsub!(/^\r.*?/, '') if lines.length > 0
   lines.join
end

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

cmd 'show running-config' do |cfg|
    cfg = cfg.each_line.to_a[0..-1].join
    cfg.gsub! /^Current configuration : [^\n]*\n/, ''
    cfg.sub! /^(ntp clock-period).*/, '! \1'
    cfg.gsub! /^ tunnel mpls traffic-eng bandwidth[^\n]*\n*(
                  (?: [^\n]*\n*)*
                 tunnel mpls traffic-eng auto-bw)/mx, '\1'
     # Add a carriage return
     cfg.gsub! /([-\\\/,.\w><@]+)(\s{6})([-\\\/,.\w><@]+)/, "\\1\n\\2\\3"
     cfg
  end

cfg :telnet, :ssh do
    username /^User ?[nN]ame:/
    password /^\r?Password:$/
    if vars :enable
      post_login do
        send "enable\n"
        expect /[pP]assword:\s?$/
        send vars(:enable) + "\n"
      end
   end
    pre_logout 'exit'
    pre_logout 'exit'
end

I've tried to use the 'terminal datadump' command but doesn't work.

What I'm doing wrong? How I can use the space or tab command?

Thank you

rbeumer commented 6 years ago

This looks like the pager is not disabled in the model. Are you really using Cisco SMB switches or are they running normal IOS? The IOS model disables the pager after login, see an example.

Edit: I see that the SMB model also disables the pager, though it could still be a mismatch.

wit12345 commented 6 years ago

Hi rbeumer,

Thank you for your reply.

I've two different models:

My Cisco SMB switches are working fine now , but my sg500 not. I've applied the example that you suggested and now I've another problem, the show running command isn't executed.

My log file:

-----------------------------------------------------------------------------
=============================================================================
==        UNAUTHORIZED ACCESS TO THIS DEVICE IS PROHIBITED!!!              ==
==                                                                         ==
==  You must have explicit, authorized permission to access or configure   ==
==  this device. Unauthorized attempts and actions to access or use of     ==
==  this system may result in civil and/or criminal penalties.             ==
==                                                                         ==
==  All activities performed on this device are logged and monitored.      ==
==  -WIT IT Team                  itteam@xpto.com                  ==
=============================================================================
-----------------------------------------------------------------------------

sw-it-dist-4>enable
Password: 
sw-it-dist-4#terminal length 0
sw-it-dist-4#terminal width 0
sw-it-dist-4#show version
Cisco IOS Software, C2960L Software (C2960L-UNIVERSALK9-M), Version 15.2(6)E, RELEASE SOFTWARE (fc4)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2017 by Cisco Systems, Inc.
Compiled Sat 05-Aug-17 12:46 by prod_rel_team

ROM: Bootstrap program is C2960L boot loader
BOOTLDR: C2960L Boot Loader (C2960L-HBOOT-M) Version 15.2(5r)E3, RELEASE SOFTWARE (fc2)

sw-it-dist-4 uptime is 1 week, 6 days, 17 hours, 49 minutes
System returned to ROM by power-on
System restarted at 18:20:38 UTC Fri Sep 14 2018
System image file is "flash:c2960l-universalk9-mz.152-6.E/c2960l-universalk9-mz.152-6.E.bin"
Last reload reason: power-on

This product contains cryptographic features and is subject to United
States and local country laws governing import, export, transfer and
use. Delivery of Cisco cryptographic products does not imply
third-party authority to import, export, distribute or use encryption.
Importers, exporters, distributors and users are responsible for
compliance with U.S. and local country laws. By using this product you
agree to comply with applicable laws and regulations. If you are unable
to comply with U.S. and local laws, return this product immediately.

A summary of U.S. laws governing Cisco cryptographic products may be found at:
http://www.cisco.com/wwl/export/crypto/tool/stqrg.html

If you require further assistance please contact us by sending email to
export@cisco.com.

cisco WS-C2960L-24PQ-LL (Marvell PJ4B (584) v7 (Rev 2)) processor (revision A0) with 524288K bytes of memory.
Processor board ID FCW2132A5GM
Last reset from Reload
3 Virtual Ethernet interfaces
28 Gigabit Ethernet interfaces
4 Ten Gigabit Ethernet interfaces
The password-recovery mechanism is enabled.

512K bytes of flash-simulated non-volatile configuration memory.
Base ethernet MAC Address       : 70:1F:53:56:E5:80
Motherboard assembly number     : U58O342T09
Power supply part number        : 341-100560-01
Motherboard serial number       : FOC21311DLM
Power supply serial number      : LIT21052CYR
Model revision number           : A0
Motherboard revision number     : 04
Model number                    : WS-C2960L-24PQ-LL
System serial number            : FCW2132A5GM
Top Assembly Part Number        : 74-116106-01
Top Assembly Revision Number    : A0
Version ID                      : V01
CLEI Code Number                : CMM2B00ARA
Hardware Board Revision Number  : 0x01

Configuration register is 0xF

sw-it-dist-4#

What I'm missing?

Thank you

laf commented 6 years ago

Why are you using your own CiscoSMB model? Oxidized has one already: https://github.com/ytti/oxidized/blob/master/lib/oxidized/model/ciscosmb.rb

brwnie commented 6 years ago

I had a similar problem recently, it displayed all the symptoms that oxidized could not connect

Checking debugs I found that oxidized was running show running on the SG500, but the configuration (stacked switches) was so large oxidized would time out and not store any configs

I found I needed to increase the timeout: value in my oxidized configuration for oxidized to finishgetting the running configuration

wit12345 commented 6 years ago

Why are you using your own CiscoSMB model? Oxidized has one already: https://github.com/ytti/oxidized/blob/master/lib/oxidized/model/ciscosmb.rb

@laf , yes I'm using the CiscoSMB model available on: https://github.com/ytti/oxidized/blob/master/lib/oxidized/model/ciscosmb.rb

Now If I check my log files, I able to see the show running command stopped on my cisco WS-C2960L-24PQ-LL in the step --More-- :

sw-it-dist-4>terminal datadump
                          ^
% Invalid input detected at '^' marker.

sw-it-dist-4>terminal width 0
sw-it-dist-4>enable
Password:
sw-it-dist-4#show running-config
Building configuration...

Current configuration : 7585 bytes
!
! Last configuration change at 17:50:56 UTC Mon Oct 15 2018
!
version 15.2
no service pad
service timestamps debug datetime msec
service timestamps log datetime msec
no service password-encryption
!
hostname sw-it-dist-4
!
boot-start-marker
boot-end-marker
!
enable secret 5  password
!
username admin secret 5 password
username rancid privilege 4 secret 5 password
no aaa new-model
!
!
 --More--

I'm missing something?

Thank you.

wit12345 commented 6 years ago

I had a similar problem recently, it displayed all the symptoms that oxidized could not connect

Checking debugs I found that oxidized was running show running on the SG500, but the configuration (stacked switches) was so large oxidized would time out and not store any configs

I found I needed to increase the timeout: value in my oxidized configuration for oxidized to finishgetting the running configuration

@Brooniee , I've changed my timeout and the result are the same I explained to @laf. Seems the problems isn't the timeout , but the show running stopped with --More-- option.

I don't understand what I'm missing.

Thank you

rbeumer commented 5 years ago

It would seem that disabling the pager does not work for your switch software version. terminal datadump is not recognized as a command, does it work if you try it yourself on the CLI?

wit12345 commented 5 years ago

@rbeumer ,

Yes the command isn't recognized with this switch software version but if I remove the terminal datadump command the result is the same

systeembeheerder commented 5 years ago

@wit12345

I've two different models:

cisco WS-C2960L-24PQ-LL - Cisco SMB switches cisco sg500 - normal IOS

That is not correct; SG500 is SMB, 2960 is IOS

menvol3 commented 5 years ago

Hi, i have similar problem with ciscosmb.rb

I use vars: enable in oxidized config

with cisco ios.rb it works fine

**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)**

but in ciscosmb.rb this part of code not exist

Is it possible to add it to ciscosmb.rb ?