[rancid] Help to add new command in rancid script

Skye Hagen skyeh at uidaho.edu
Thu Feb 23 15:55:29 UTC 2012


The code you have for adding the commands to the command table are correct.
I added both CDP and LLDP information to RANCID, here is the code I used to
handle Œshow cdp neighbor detail¹. The top part is pretty standard for any
parsing routine, to skip the junk, and exit if we have hit the end of what
we are interested in. After than, I look for specific lines, looking for the
DeviceID, platform and interface. For the first two, I just store the data.
When I hit an interface line, I create a line in the RANCID output. When
done, I add a blank comment line to separated the CDP section from the next
part of the RANCID output. This produces lines like this...

!CDP: Device: hub001D3.csrv.uidaho.edu Platform: cisco WS-C2960G-48TC-L
Interface: GigabitEthernet2/14
!CDP: Device: lib6500.csrv.uidaho.edu Platform: cisco WS-C6509-E Interface:
GigabitEthernet3/1

Here is the code.

# This routine parses "show cdp neighbor detail"
sub ShowCDPDetail {
    print STDERR "    In ShowCDPDetail: $_" if ($debug);

    my($deviceID, $platform, $interface);
    while (<INPUT>) {
        tr/\015//d;
        last if (/^$prompt/);
        next if (/^(\s*|\s*$cmd\s*)$/);
        return(1) if (/Line has invalid autocommand /);
        return(1) if (/(Invalid (input|command) detected|Type help or )/i);
        # the pager can not be disabled per-session on the PIX
        if (/^(<-+ More -+>)/) {
            my($len) = length($1);
            s/^$1\s{$len}//;
        }

        if (/^Device ID: (.*)/) {
            $deviceID = $1;
            next;
        }

        if (/^Platform: ([^,]+)/) {
            $platform = $1;
            next;
        }

        /^Interface: (\S+),/ &&
            ProcessHistory("CDP","keysort","$deviceID $1",
                           "!CDP: Device: $deviceID Platform: $platform
Interface: $1\n") && next;
    }

    ProcessHistory("","","","!\n");
    return(0);

}



On 2/22/12 9:44 PM, "Mohan L" <l.mohanphy at gmail.com> wrote:

> Dear All,
> 
> Thanks for you time to maintain such a amazing tool rancid.
> 
> I am trying to add two more command in rancid(bin/rancid) script to pull
> information in Cisco routers.
> 
> I found cisco router is points to rancid(bin/rancid) script:
> 
> %vendortable = (
>     
>     'cisco'             => 'rancid',
> 
> )
> 
> I want to add the below two commands in rancid script :
> 1). show cdp interface
> 2). show cdp neighbors
> 
> Here I have added the method to pull the output of the above commands 
> @commandtable = (
>         {'show cdp interface'                 => 'ShowCdpInterface'},
>         {'show cdp neighbors'    => 'ShowCdpNeighbors'},
>    )
> 
> sub ShowCdpInterface {
> 
> }
> 
> 
> sub ShowCdpNeighbors {
> 
> 
> }
> 
> I need some pointer/guide to write the above two method. I am Intermediate
> level Perl guy. I am able to fine tune if some one have already written the
> script.
> 
> I will greatly appreciate any help on this.
> 
> 
> Thanks
> Mohan L  
> 
> 
> _______________________________________________
> Rancid-discuss mailing list
> Rancid-discuss at shrubbery.net
> http://www.shrubbery.net/mailman/listinfo.cgi/rancid-discuss

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.shrubbery.net/pipermail/rancid-discuss/attachments/20120223/5c9f4d09/attachment-0001.html>


More information about the Rancid-discuss mailing list