[rancid] Help to add new command in rancid script

Mohan L l.mohanphy at gmail.com
Thu Feb 23 16:21:33 UTC 2012


Dear Skye,

Thanks for sharing your code.

It will be very help full to have explanation of ProcessHistory method.

NOTE : I not sure this list is using top posting or bottom posting style.
I am top posting this because it seems previous mail using top posting
style.

Thanks
Mohan L




On Thu, Feb 23, 2012 at 9:25 PM, Skye Hagen <skyeh at uidaho.edu> wrote:

>  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/97cf80e2/attachment.html>


More information about the Rancid-discuss mailing list