Discussion:
[rancid] Help to add new command in rancid script
Mohan L
2012-02-23 05:44:11 UTC
Permalink
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
Skye Hagen
2012-02-23 15:55:29 UTC
Permalink
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);

}
Post by Mohan L
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.
%vendortable = (
   
    'cisco'             => 'rancid',
)
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
http://www.shrubbery.net/mailman/listinfo.cgi/rancid-discuss
Mohan L
2012-02-23 16:21:33 UTC
Permalink
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
Post by Skye Hagen
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);
}
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.
%vendortable = (
'cisco' => 'rancid',
)
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
http://www.shrubbery.net/mailman/listinfo.cgi/rancid-discuss
Continue reading on narkive:
Search results for '[rancid] Help to add new command in rancid script' (Questions and Answers)
3
replies
I need an article from wikipedia,help me?
started 2007-10-10 03:04:38 UTC
wikipedia
Loading...