DX NetOps Manager

Expand all | Collapse all

[NCM] WLC capture script

Jump to Best Answer
  • 1.  [NCM] WLC capture script

    Posted 25 days ago
    Hello All

    I'm trying to get a script together for getting the config out of WLC devices. I found this thread: https://community.broadcom.com/enterprisesoftware/communities/community-home/librarydocuments/viewdocument?DocumentKey=f3bcb3a4-0be7-49c3-885d-c148403a8ed9&CommunityKey=671164c3-e575-4b08-96ab-edc2e1ceed13&tab=librarydocuments

    Out of the box, this script does not work for me. I managed to make it work by narrowing it down to this:

    #!/usr/Spectrum/bin/perl -w
    # This script will capture the running configuration of a
    # WLC device through an SSH session and print it to STDOUT.
    #
    # Error Codes:
    # 0 = Success
    # 255 = Usage error
    # 254 = Invalid timeout value
    # 252 = Login error
    # 249 = Exec prompt not found error
    # 244 = Error retrieving configuration
    # 245 = Insufficient privileges
    # 253 = Unexpected output
    #
    use strict;
    use warnings;
    use Net::SSH::Expect;
    $ENV{'PATH'} = "/usr/bin:" . $ENV{'PATH'};
    ### Main ###
    if ( $#ARGV != 4 && $#ARGV != 5 ) {
      print "Usage: wlc_capture.pl <device IP> <user> <pass> <enable_pass> <login_timeout_in_seconds> <capture_timeout_in_seconds>\n";
      print STDERR "Usage: wlc_capture.pl <deviceIP> <user> <pass> <enable_pass> <login_timeout_in_seconds> <capture_timeout_in_seconds>\n";
      exit 255;
    } elsif ( $ARGV[4] < 1 || $ARGV[4] > 600 ) {
      print "$ARGV[4] is the login timeout and must be an int between 1 and 600 seconds\n";
      print STDERR "$ARGV[4] is the login timeout and must be an int between 1 and 600 seconds\n";
      exit 254;
    } elsif ( $#ARGV == 5 && ( $ARGV[5] < 1 || $ARGV[5] > 600 ) ) {
      print "$ARGV[5] is the capture timeout and must be an int between 1 and 600 seconds\n";
      print STDERR "$ARGV[5] is the capture timeout and must be an int between 1and 600 seconds\n";
      exit 254;
    } else {
      my $capture_timeout = $ARGV[4];
      if ( $ARGV[5] ) {
        $capture_timeout = $ARGV[5];
      }
      my $errorCode = 1;
      my @data;
      my $errorString = "\nHost $ARGV[0]: \n";
      ( $errorCode, @data ) = GetConfig( $ARGV[0], $ARGV[1], $ARGV[2], $ARGV[3], $ARGV[4], $capture_timeout );
      if ( $errorCode == 0 ) {
    
        # Success. The startup configuration
        # content is in the data variable
        foreach (@data) { print "$_\n" };    # print the configuration to STDOUT
        exit 0;
      } else {
        print STDERR $errorString;
        if ( $errorCode == 245 ) {
          print STDERR join " ", @data, "\nEnsure that the device user has sufficient privileges to disable paging and view the config\n";
        } else {
          print STDERR join " ", @data, "\n";
        }
        exit $errorCode;
      }
    }
    exit 0;
    
    sub GetConfig {
      my $deviceIP        = shift;
      my $user            = shift;
      my $pass            = shift;
      my $epass           = shift;
      my $login_timeout   = shift;
      my $capture_timeout = shift;
      my @config;
      my $msg;
      my $ssh = Net::SSH::Expect->new(
        host        => $deviceIP,
        user        => $user,
        password    => $pass,
        raw_pty     => 1,
        no_terminal => 0,
        timeout     => $login_timeout
      );
      my $login_output;
      eval { $login_output = $ssh->login( 'user:', 'password:' ); };
      
     
    
     
    
      $ssh->send($user);
      $ssh->send($pass);
      $ssh->send( "config paging disable");
      $ssh->send( "show run-config commands", 10 );
      $ssh->timeout($capture_timeout);
      $ssh->peek(0);
      while ( my $line = $ssh->read_line() ) {
    
        # get configuration content
        push @config, $line;
      }
    
     
    
      return ( 0, @config );    # everything was okay, return the captured data
    }​


    This script actually works. So i can log in to the device and pull the config. However, It does not retrieve the whole config. It stops after about 170 lines of config and acts as it is the whole config. The whole config is 2000+ lines.
    The login_timeout is 20 and the capture timeout is 60.
    I do not think it is caused by delays on the network because when I log in manually and perform the commands, it all works perfect.

    Anyone with similar issues or maybe a solution to this?


  • 2.  RE: [NCM] WLC capture script
    Best Answer

    Posted 25 days ago
    Try to run the Perl script manually and see how it works. Especially how long is running.

    ------------------------------
    Senior Consultant
    SolvIT Networks
    ------------------------------