found this one today haven't tried it.
credit to Skye Hagen skyeh at uidaho.edu
Skye says:
...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.
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);
}