Cisco::Reconfig
Poking around on CPAN a week or so ago, I stumbled across Cisco::Reconfig.
It looked pretty interesting, and turned out to be the work of David Muir Sharnoff. He’s responsible for Net::Netmask, which is one of my five favorites, so I had to check it out.
Sample router config (not all lines shown):
interface Loopback0 ip address 10.254.254.1 255.255.255.255 ! interface Ethernet0/0 description Admin LAN ip address 10.10.1.1 255.255.255.0 duplex auto ! interface Serial0/0 description to Internet ID W065432 ip address 1.1.1.1 255.255.255.252 ! interface Ethernet0/1 no ip address shutdown ! interface Ethernet1/0 description User LAN ip address 10.10.2.1 255.255.254.0 duplex auto ! interface Ethernet1/1 ip address 10.10.4.1 255.255.254.0 duplex auto !
Let’s write a quick & dirty script^W program to look for blank interface descriptions, because that’s something I find really annoying:
#!/usr/local/bin/perl
use strict;
use Cisco::Reconfig;
my $host = "gabrielle";
my $host_config = "$host.confg";
print ("Checking: $host\n");
my $config = readconfig("$host_config");
for my $intf ( $config->get('interface') ) {
next if ( $intf->get('shutdown') ); #ignore, don't care
next if ( $intf =~ /Loopback/ ); #idc
my $descr = $intf->get('description');
chomp ($intf, $descr); # hm, kinda feel like I shouldn't have to do this?
print ("$intf: $descr\n"); # just to be chatty
if (! $descr) {
print ("$host: $intf: Description is blank!\n");
}
}
exit 0;
:::–>./sample.pl
Checking: gabrielle
interface Ethernet0/0: description Admin LAN
interface Serial0/0: description to Internet ID W065432
interface Ethernet1/0: description User LAN
interface Ethernet1/1:
gabrielle: interface Ethernet1/1: Description is blank!
I’m primarily interested in it for checking compliance of our configurations with our business standards. No need to chunk through a config line-by-line with regexps; in a lot of cases, a simple ‘get’ will tell me if something’s configured or not (eg “snmp server-location”.)
Specific features that look really intriguing:
- you can generate the commands you need to “fix” your config
- the “context” method allows you to draw out the surrounding lines
I can’t wait to mess around with this some more.