<HTML>
<HEAD>
<TITLE>Re: [rancid] Help to add new command in rancid script</TITLE>
</HEAD>
<BODY>
<FONT FACE="Calibri, Verdana, Helvetica, Arial"><SPAN STYLE='font-size:11pt'>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...<BR>
<BR>
!CDP: Device: hub001D3.csrv.uidaho.edu Platform: cisco WS-C2960G-48TC-L Interface: GigabitEthernet2/14<BR>
!CDP: Device: lib6500.csrv.uidaho.edu Platform: cisco WS-C6509-E Interface: GigabitEthernet3/1<BR>
<BR>
Here is the code.<BR>
<BR>
# This routine parses "show cdp neighbor detail"<BR>
sub ShowCDPDetail {<BR>
print STDERR " In ShowCDPDetail: $_" if ($debug);<BR>
<BR>
my($deviceID, $platform, $interface);<BR>
while (<INPUT>) {<BR>
tr/\015//d;<BR>
last if (/^$prompt/);<BR>
next if (/^(\s*|\s*$cmd\s*)$/);<BR>
return(1) if (/Line has invalid autocommand /);<BR>
return(1) if (/(Invalid (input|command) detected|Type help or )/i);<BR>
# the pager can not be disabled per-session on the PIX<BR>
if (/^(<-+ More -+>)/) {<BR>
my($len) = length($1);<BR>
s/^$1\s{$len}//;<BR>
}<BR>
<BR>
if (/^Device ID: (.*)/) {<BR>
$deviceID = $1;<BR>
next;<BR>
}<BR>
<BR>
if (/^Platform: ([^,]+)/) {<BR>
$platform = $1;<BR>
next;<BR>
}<BR>
<BR>
/^Interface: (\S+),/ &&<BR>
ProcessHistory("CDP","keysort","$deviceID $1",<BR>
"!CDP: Device: $deviceID Platform: $platform Interface: $1\n") && next;<BR>
}<BR>
<BR>
ProcessHistory("","","","!\n");<BR>
return(0);<BR>
<BR>
}<BR>
<BR>
<BR>
<BR>
On 2/22/12 9:44 PM, "Mohan L" <<a href="l.mohanphy@gmail.com">l.mohanphy@gmail.com</a>> wrote:<BR>
<BR>
</SPAN></FONT><BLOCKQUOTE><SPAN STYLE='font-size:11pt'><FONT FACE="Courier New">Dear All,<BR>
<BR>
Thanks for you time to maintain such a amazing tool rancid.<BR>
<BR>
I am trying to add two more command in rancid(bin/rancid) script to pull information in Cisco routers. <BR>
<BR>
I found cisco router is points to rancid(bin/rancid) script:<BR>
<BR>
%vendortable = (<BR>
<BR>
'cisco' => 'rancid',<BR>
<BR>
)<BR>
<BR>
I want to add the below two commands in rancid script : <BR>
1). show cdp interface<BR>
2). show cdp neighbors<BR>
<BR>
Here I have added the method to pull the output of the above commands <BR>
@commandtable = (<BR>
{'show cdp interface' => 'ShowCdpInterface'},<BR>
{'show cdp neighbors' => 'ShowCdpNeighbors'},<BR>
)<BR>
<BR>
sub ShowCdpInterface {<BR>
<BR>
}<BR>
<BR>
<BR>
sub ShowCdpNeighbors {<BR>
<BR>
<BR>
}<BR>
<BR>
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.<BR>
<BR>
I will greatly appreciate any help on this.<BR>
<BR>
<BR>
Thanks<BR>
Mohan L <BR>
</FONT><FONT FACE="Calibri, Verdana, Helvetica, Arial"><BR>
<HR ALIGN=CENTER SIZE="3" WIDTH="95%"></FONT></SPAN><FONT SIZE="2"><FONT FACE="Consolas, Courier New, Courier"><SPAN STYLE='font-size:10pt'>_______________________________________________<BR>
Rancid-discuss mailing list<BR>
<a href="Rancid-discuss@shrubbery.net">Rancid-discuss@shrubbery.net</a><BR>
<a href="http://www.shrubbery.net/mailman/listinfo.cgi/rancid-discuss">http://www.shrubbery.net/mailman/listinfo.cgi/rancid-discuss</a><BR>
</SPAN></FONT></FONT></BLOCKQUOTE>
</BODY>
</HTML>