[rancid] Rancid-missed cmds

Alan McKinnon alan.mckinnon at gmail.com
Mon Sep 16 13:33:32 UTC 2013


The approach to fixing this is always the same, at this point nothing
rancid is outputting helps debug in the slightest - all it says is that
something went wrong, but we already know that.

Do the following:

1. telnet to device and check you can auth manually
2. "hulogin <device>" and check it logs in and enables properly, and
that the prompt etc on the screen is correct
3. run "hulogin -t 90 -c"display current-configuration,display version"
<device>" and check that the commands do actually run correctly
4. run "hurancid -d <device>" - this dumps a *complete* log in the
current directory containing more info than the regular log you quoted
and often reveals the problem (but not always).


But first a few prior steps need to be verified:

- the command in #3 I pasted from your log output, and that has comma
separators. Your device might need semicolons, I have no idea as I don;t
know that vendors stuff
- the relevant line in router.db must contain the appropriate type
string in field 3
- you will have had to edit rancid-fe and add a line for huawei to a
perl hash. Without this, rancid-run doesn't know what parser script to
call and it cannot work.
- the device you have must be supported by the script you are using;
just because Huawei made it is no guarantee it works similarly to
anything else they might have made.


If all of that checks out, then we need to look into the running perl
itself.

I believe we've been over most of this before, I don't recall getting a
definitive answer. You really do need to go through all these steps as
given, nothing else is going to get to the root of your problem.



On 16/09/2013 15:11, Erica James wrote:
> Hello
> I have a problem with rancid parsing script. Logs show missed cmd(s).
> Trying to get all of the configs.
> 10.3.4.5: missed cmd(s): display current-configuration,display version
> 10.3.4.5: End of run not found
> #
> All routers sucessfully completed.
> cvs diff: Diffing .
> cvs diff: Diffing configs
> cvs commit: Examining .
> cvs commit: Examining configs
>  
> The script is for Huawei. The problem now seems to be that rancid is not
> collecting configs.
> Anyone with an idea on what to do?
>  
> Below is the rancid-script
>  
> #! /usr/bin/perl
> ##
> ## $Id$
> ##
> ## rancid 2.3.8
> ##
> ## Copyright (C) 1997-2004 by Terrapin Communications, Inc.
> ## All rights reserved.
> ##
> ## This software may be freely copied, modified and redistributed
> ## without fee for non-commerical purposes provided that this license
> ## remains intact and unmodified with any RANCID distribution.
> ##
> ## There is no warranty or other guarantee of fitness of this software.
> ## It is provided solely "as is".  The author(s) disclaim(s) all
> ## responsibility and liability with respect to this software's usage
> ## or its effect upon hardware, computer systems, other software, or
> ## anything else.
> ##
> ## Except where noted otherwise, rancid was written by and is maintained by
> ## Henry Kilmer, John Heasley, Andrew Partan, Pete Whiting, and Austin
> Schutz.
> ##
> #
> # hurancid - Interface to Huawei devices
> #
> #  RANCID - Really Awesome New Cisco confIg Differ
> #
> # usage: rancid [-d] [-l] [-f filename | $host]
> #
> use Getopt::Std;
> getopts('dfl');
> $log = $opt_l;
> $debug = $opt_d;
> $file = $opt_f;
> $host = $ARGV[0];
> $clean_run = 0;
> $found_end = 0;
> $timeo = 90;                    # hulogin timeout in seconds
> 
> my(%filter_pwds);               # password filtering mode
> # This routine is used to print out the router configuration
> sub ProcessHistory {
>     my($new_hist_tag,$new_command,$command_string, at string)=(@_);
> if((($new_hist_tag ne $hist_tag) || ($new_command ne $command))
>        && defined %history) {
>         print eval "$command \%history";
>         undef %history;
>     }
>     if (($new_hist_tag) && ($new_command) && ($command_string)) {
>         if ($history{$command_string}) {
>             $history{$command_string} =
> "mailto:$history%7B$command_string%7D at string";
>         } else {
>             $history{$command_string} = "@string";
>         }
>     } elsif (($new_hist_tag) && ($new_command)) {
>         $history{++$#history} = "@string";
>     } else {
>         print "@string";
>     }
>     $hist_tag = $new_hist_tag;
>     $command = $new_command;
>     1;
> }
> 
> sub numerically { $a <=> $b; }
> 
> # This is a sort routing that will sort numerically on the
> # keys of a hash as if it were a normal array.
> sub keynsort {
>     local(%lines)=@_;
>     local($i) = 0;
>     local(@sorted_lines);
>     foreach $key (sort numerically keys(%lines)) {
>         $sorted_lines[$i] = $lines{$key};
>         $i++;
>     }
>     @sorted_lines;
> }
> 
> # This is a sort routing that will sort on the
> # keys of a hash as if it were a normal array.
> sub keysort {
>     local(%lines)=@_;
>     local($i) = 0;
>     local(@sorted_lines);
>     foreach $key (sort keys(%lines)) {
>         $sorted_lines[$i] = $lines{$key};
>         $i++;
>     }
>     @sorted_lines;
> }
> 
> # This is a sort routing that will sort on the
> # values of a hash as if it were a normal array.
> sub valsort{
>     local(%lines)=@_;
>     local($i) = 0;
>     local(@sorted_lines);
>     foreach $key (sort values %lines) {
>         $sorted_lines[$i] = $key;
>         $i++;
>     }
>     @sorted_lines;
> }
> 
> # This is a numerical sort routing (ascending).
> sub numsort {
>     local(%lines)=@_;
>     local($i) = 0;
>     local(@sorted_lines);
>     foreach $num (sort {$a <=> $b} keys %lines) {
>         $sorted_lines[$i] = $lines{$num};
>         $i++;
>     }
>     @sorted_lines;
> }
> 
> # This is a sort routine that will sort on the
> # ip address when the ip address is anywhere in
> # the strings.
> sub ipsort {
>     local(%lines)=@_;
>     local($i) = 0;
>     local(@sorted_lines);
>     foreach $addr (sort sortbyipaddr keys %lines) {
>         $sorted_lines[$i] = $lines{$addr};
>         $i++;
>     }
>     @sorted_lines;
> }
> 
> # These two routines will sort based upon IP addresses
> sub ipaddrval {
>     my(@a) = ($_[0] =~ m#^(\d+)\.(\d+)\.(\d+)\.(\d+)$#);
>     $a[3]+256*($a[2]+256*($a[1]+256*$a[0]));
> }
> sub sortbyipaddr {
>     &ipaddrval($a) <=> &ipaddrval($b);
> }
>  
> 
> # This routine processes a "show configuration"
> # This routine processes a "show configuration"
> sub WriteTerm {
>     print STDERR "    In WriteTerm: $_" if ($debug);
>     #my($lineauto) = 0;
> 
>     while (<INPUT>) {
> #print STDERR "History $_\n";   
>    
>         tr/\015//d;
>         last if(/^$prompt/);
>        next if (/^(\s*|\s*$cmd\s*)$/);
>         return(1) if (/^\s*\^\s*$/);
>         return(1) if (/Line has invalid autocommand /);
>         return(1) if (/(Invalid (input|command) detected|Type help or )/i);
>         return(-1) if (/command authorization failed/i);
>         # the pager can not be disabled per-session on the PIX
>         if (/^(<-+ More -+>)/) {
>             my($len) = length($1);
>             s/^$1\s{$len}//;
>         }
>        
>         /^/ && next;
>         ProcessHistory("COMMENTS","keysort","B1","# $_") && next;
>     }
>  
>         # end of config...is a comment.
>         if (/^return/i) {
> $found_end = 1;
>             return(1);
>         }
>    
>         return(0);
> }
> 
> # This routine copies everything with precefing "#"
> sub CopyComment {
>     print STDERR "    In CopyComment: $_" if ($debug);
> 
>     while (<INPUT>) {
>         tr/\015//d;
>         last if (/^$prompt/);
> 
>         ProcessHistory("","","","# $_");
>         # end of config
>     }
>     return(0);
> }
> 
> # filter out "uptime" lines
> sub FilterUptime {
>     print STDERR "    In FilterUptime: $_" if ($debug);
> 
>     while (<INPUT>) {
>         tr/\015//d;
>         last if (/^$prompt/);
> #nmeongeza
>         next if (/^(\s*|\s*$cmd\s*)$/);
>         return(-1) if (/command authorization failed/i);
>         /^VERSION\=>(\s+.*)$/ &&
> ProcessHistory("COMMENTS","keysort","C1","\#\n# Version: $1\n")
> && next;
>         /^PATCH\=>(\s+.*)$/ &&
> ProcessHistory("COMMENTS","keysort","C2","\# Patch: $1\n")
> && next;
> 
>         /^PRODUCT\=>(\s+.*)$/ &&
> ProcessHistory("COMMENTS","keysort","C3","\# Version: $1\n")
> && next;
> }
> return(0);
> }
>  
>  
> # dummy function
> sub DoNothing {print STDOUT;}
> 
> # Main
> @commandtable = (
>         {'display version'                       => 'FilterUptime'},
>         {'display patch-information'             => 'CopyComment'},
>         {'display device'                        => 'CopyComment'},
>         {'display device pic-status'             => 'CopyComment'},
>         {'display current-configuration'         => 'WriteTerm'},
> );
> 
> # Use an array to preserve the order of the commands and a hash for mapping
> # commands to the subroutine and track commands that have been completed.
> @commands = map(keys(%$_), @commandtable);
> %commands = map(%$_, @commandtable);
> 
> $huaw_cmds=join(";", at commands);
> $cmds_regexp=join("|", at commands);
> 
> open(OUTPUT,">$host.new") || die "Can't open $host.new for writing: $!\n";
> select(OUTPUT);
> # make OUTPUT unbuffered if debugging
> if ($debug) { $| = 1; }
> 
> if ($file) {
>     print STDERR "opening file $host\n" if ($debug);
>     print STDOUT "opening file $host\n" if ($log);
>     open(INPUT,"<$host") || die "open failed for $host: $!\n";
> } else {
>     print STDERR "executing hulogin -t $timeo -c\"$huaw_cmds\" $host\n"
> if ($debug);
>     print STDOUT "executing hulogin -t $timeo -c\"$huaw_cmds\" $host\n"
> if ($debug);
>     if (defined($ENV{NOPIPE}) && $ENV{NOPIPE} =~ /^YES/i) {
>         system "hulogin -t $timeo -c \"$huaw_cmds\" $host </dev/null >
> $host.raw" || die "hulogin failed for $host: $!\n";
>         open(INPUT, "< $host.raw") || die "hulogin failed for $host: $!\n";
>     } else {
>         open(INPUT,"hulogin -t $timeo -c \"$huaw_cmds\" $host </dev/null
> |") || die "hulogin failed for $host: $!\n";
>     }
> }
> 
> # determine password filtering mode
> if ($ENV{"FILTER_PWDS"} =~ /no/i) {
>         $filter_pwds = 0;
> } elsif ($ENV{"FILTER_PWDS"} =~ /all/i) {
>         $filter_pwds = 2;
> } else {
>         $filter_pwds = 1;
> }
> 
> ProcessHistory("","","","#RANCID-CONTENT-TYPE: Huawei\n#\n");
> ProcessHistory("COMMENTS","keysort","B0","#\n");
> ProcessHistory("COMMENTS","keysort","F0","#\n");
> ProcessHistory("COMMENTS","keysort","G0","#\n");
> TOP: while(<INPUT>) {
>     tr/\015//d;
> 
> #print STDERR ("CMD: $_\n");   
>    
>     if (/\>\s?quit.*$/) {
>         $clean_run=1;
>         last;
>     }
>  
>     if (/^Error:/) {
>         print STDOUT ("$host hulogin error: $_");
>         print STDERR ("$host hulogin error: $_") if ($debug);
>         $clean_run=0;
>         last;
> }
>    
>     while (/\>\007*\s*($cmds_regexp)\s*$/) {
>         $cmd = $1;
> 
>         if (!defined($prompt)) {
>             $prompt = ($_ =~ /^([^>]+\>)/)[0];
>             $prompt =~ s/([][}{)(file://])///$1/g;
>             print STDERR ("PROMPT MATCH: $prompt\n") if ($debug);
>         }
>         print STDERR ("HIT COMMAND:$_") if ($debug);
>         if (! defined($commands{$cmd})) {
>             print STDERR "$host: found unexpected command - \"$cmd\"\n";
>             $clean_run = 0;
>             last TOP;
>         }
>         $rval = &{$commands{$cmd}};
>         delete($commands{$cmd});
>         if ($rval == -1) {
>             $clean_run = 0;
>             last TOP;
>         }
>     }
> }
> print STDOUT "Done $logincmd: $_\n" if ($log);
> # Flush History
> ProcessHistory("","","","");
> # Cleanup
> close(INPUT);
> close(OUTPUT);
>  
> if (defined($ENV{NOPIPE})) {
>     #unlink("$host.raw") if (! $debug);
> }
> # check for completeness
> if (scalar(%commands) || !$clean_run || !$found_end) {
>     if (scalar(%commands)) {
>         printf(STDOUT "$host: missed cmd(s): %s\n", join(',',
> keys(%commands)));
>         printf(STDERR "$host: missed cmd(s): %s\n", join(',',
> keys(%commands))) if ($debug);
>     }
>     if (!$clean_run || !$found_end) {
>         print STDOUT "$host: End of run not found\n";
>         print STDERR "$host: End of run not found\n" if ($debug);
>         system("/usr/bin/tail -1 $host.new");
>     }
>     #unlink "$host.new" if (! $debug);
> }
>  
>  


-- 
Alan McKinnon
alan.mckinnon at gmail.com



More information about the Rancid-discuss mailing list