DX NetOps

Expand all | Collapse all

NCM capture the first line of the host configuration of Array devcies

john Robert singh

john Robert singhNov 20, 2018 05:27 AM

john Robert singh

john Robert singhDec 19, 2018 01:38 AM

  • 1.  NCM capture the first line of the host configuration of Array devcies

    Posted Nov 12, 2018 09:24 AM

    Hi all,

     

    We are using spectrum 10.3 and we have trying to capture the host configuration of the Array devices , but it's capturing only the 1st line of the configuration and i am not a familiar in perl script can any one help me why it's doing like this, 

     

    #!/opt/SPECTRUM/bin/perl -w

    # This script will capture the running configuration of a
    # Array 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: capture_running.pl <device IP> <user> <pass> <enable_pass>
    <login_timeout_in_seconds> <capture_timeout_in_seconds>\n";
    print STDERR "Usage: capture_running.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 1 and 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 running 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="";
    $msg = "List of all environment variables:\n";
    while ( my($env_name,$env_value) = each %ENV ) {
    $msg = "\t$env_name = $env_value\n";
    }

    eval { $login_output = $ssh->login(); };

    # disable paging
    # different commands for different devices, if they don't
    # work then we will get messages about problems later
    # specifically the "No prompt after 'sh run'" error
    # errmsg doesn't get set when these error and if we use print
    # and getlines to read for errors it causes problems with print "sh run"
    # later.
    # $ssh->exec( "term pager 0" );
    # my $paging = $ssh->exec( "terminal pager 0" );
    # if ( $paging =~ /\s?%\s/ )
    # {
    # $msg = "Unable to set terminal size to 0 - Insufficient privileges";
    # $ssh->close();
    # return( 245, $msg);
    # }

    $ssh->exec( "en" );
    $ssh->send( "$epass" );
    my $paging = $ssh->exec( "no pager" );
    if ( $paging =~ /\s?%\s/ )
    {
    $msg = "Unable to set terminal size to 0 - Insufficient privileges";
    $ssh->close();
    return( 245, $msg);
    }
    $ssh->send( "show running" );
    $ssh->timeout( $capture_timeout );
    $ssh->peek(0);

    while( my $line = $ssh->read_line() )
    #my $line = $ssh->cmd("$cmd");
    {
    # get configuration content
    #next unless /\S/;
    if( $line !~
    /show running|Building configuration|Current configuration|^\s\n*$/ )
    {
    #next if /^$/;

    push @config, $line;
    }
    }

    if( @config <= 0 )
    {
    $msg = "No data retrieved, the capture timeout may be too low.";
    $ssh->close();
    return( 244, $msg );
    }

    if( scalar grep { $_ =~ /^%/ } @config )
    {
    # Ensure show running actually returned the config and not an error
    # message containing '%'
    return( 245, @config );
    }

    return( 0, @config ); # everything was okay, return the captured data
    }

     

     

     

     

    Thanks,

    john.



  • 2.  Re: NCM capture the first line of the host configuration of Array devcies

    Posted Nov 13, 2018 02:22 AM

    Hi All,

     

    Can anyone help me that why it's not capture the full configuration.

     

    Thanks,

    john



  • 3.  Re: NCM capture the first line of the host configuration of Array devcies

    Posted Nov 13, 2018 09:39 AM

    Hi All,

     

    can anyone help me that why it's not capture the full configuration...

    the below screen shot showing original device configuration and it's contains blank lines ..

     

     

    Thanks,

    john



  • 4.  Re: NCM capture the first line of the host configuration of Array devcies

    Posted Nov 14, 2018 01:08 AM

    Hi All,

     

    Can Anyone help me why the above perl script is not reading the line after the blank line...

     

    Thanks,

    john



  • 5.  Re: NCM capture the first line of the host configuration of Array devcies

    Posted Nov 16, 2018 02:49 AM

    Hi All,

     

    Can anyone help me why it's not capturing all lines...

     

    Thanks,

    john



  • 6.  Re: NCM capture the first line of the host configuration of Array devcies

    Posted Nov 20, 2018 05:27 AM

    Hi All,

     

    Can anyone help me in this....

    Thanks,

    john



  • 7.  Re: NCM capture the first line of the host configuration of Array devcies

    Posted Dec 19, 2018 01:38 AM

    Hi All,

     

    Can Anyone help me on this...

     

    Thanks,

    john.



  • 8.  Re: NCM capture the first line of the host configuration of Array devcies

    Broadcom Employee
    Posted Dec 19, 2018 08:50 AM

    Hi John

     

    Sorry you didnt get a response till now. I am not sure what may be causing the issue. Here's what I would suggest to gather some data: 

     

    1. run a sniffer trace while attempting to capture the config of the device

    - this is recommended anytime you are troubleshooting captures or uploads

     

    2. run the script in Command Line while also running sniffer trace

    - this is important to isolate the problem outside of Spectrum

    - export the script from NCM Device Family settings

    - export to *.pl file into the <SPECROOT>/bin directory

    Usage: capture_running.pl <device IP> <user> <pass> <enable_pass>
    <login_timeout_in_seconds> <capture_timeout_in_seconds>

     

    i.e.: test_capture.pl 192.168.1.1 spectrum spectrum enable 500 500

     

    3. review the capture via command line output to screen, and compare to the sniffer trace to investigate this issue

     

    4. From there, would recommend opening a case with CA Support if you are still seeing issue or need further help. 

     

    Hope that helps

    ~Jay V



  • 9.  Re: NCM capture the first line of the host configuration of Array devcies

    Posted Dec 21, 2018 07:59 AM

    Hi Jay,

    running the following thing also give the same result (one line only)

     

    2. run the script in Command Line while also running sniffer trace

    - this is important to isolate the problem outside of Spectrum

    - export the script from NCM Device Family settings

    - export to *.pl file into the <SPECROOT>/bin directory

    Usage: capture_running.pl <device IP> <user> <pass> <enable_pass>
    <login_timeout_in_seconds> <capture_timeout_in_seconds>

     

    i.e.: test_capture.pl 192.168.1.1 spectrum spectrum enable 500 500

     

    Thanks,

    john.



  • 10.  Re: NCM capture the first line of the host configuration of Array devcies

    Broadcom Employee
    Posted Dec 21, 2018 09:33 AM

    Hi John

     

    If the issue is occurring while attempting to capture via command line, then this issue is outside scope of Spectrum.

     

    We would recommend to run sniffer trace / tcpdump / wireshark capture while attempting command line capture to see if further clues can be obtained from the packet trace. 

     

    We would also recommend to reach the support of the device vendor for further troubleshooting. 

     

    Regards, 

    Jay V



  • 11.  Re: NCM capture the first line of the host configuration of Array devcies

    Posted Dec 24, 2018 12:24 AM

    Hi Jay,

     

    Thanks for your support...

     

    And When i am trying from secure shell it's showing all configuration ...

    it's really confusing that whether the issue is in my perl script(reading command , means it's reading the blank line or it's automatically ending when the blank line is reached  ) or issue in the device...

     

    Thanks,

    john.



  • 12.  Re: NCM capture the first line of the host configuration of Array devcies

    Posted Dec 21, 2018 08:48 AM

    Hi Jay,

     

    After the first line the configuration having some blank line ..

    can you tell me that how to read or jump the blank line ...

     

    Thanks,

    john.



  • 13.  Re: NCM capture the first line of the host configuration of Array devcies

    Broadcom Employee
    Posted Jan 02, 2019 10:05 AM

    Hi John,

     

    When I check your screenshot listed above what it looks like it is doing, is just showing the 1 difference that you have between each capture and this is the ArrayOS line as the date time is always changing.

    What i would suggest is to use the NCM mask and create a RegEX expression so that we mask this line out, this way it won´t count each update as a difference.

    Something like this should work for you in the NCM Mask list

     

    ArrayOS Rel.APV.*.$

     

    Best regards,

    Glenn



  • 14.  Re: NCM capture the first line of the host configuration of Array devcies

    Posted Jan 24, 2019 03:16 AM

    Hi All,

     

    I have done my best but still not able to capture the full configuration... any idea in this...

     

    Thanks,

    john.



  • 15.  Re: NCM capture the first line of the host configuration of Array devcies

    Posted Feb 20, 2019 11:47 PM

    Hi All,

     

    I have done my best but still not able to capture the full configuration... any idea in this...

     

    Thanks,

    john.



  • 16.  Re: NCM capture the first line of the host configuration of Array devcies

    Posted Mar 21, 2019 03:56 AM

    Hi All,

     

    Can anyone find the solution for this...

    anyone can share the script for capturing clickarray load balancer host configuration.

     

    Thanks,

    john.