by gorthx

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
interface Ethernet0/0
 description Admin LAN
 ip address
 duplex auto
interface Serial0/0
 description to Internet ID W065432
 ip address
interface Ethernet0/1
 no ip address
interface Ethernet1/0
 description User LAN
 ip address
 duplex auto
interface Ethernet1/1
 ip address
 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:


use strict;
use Cisco::Reconfig;

my $host        = "gabrielle";
my $host_config = "$host.confg";
print ("Checking: $hostn");
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: $descrn");	# just to be chatty
    if (! $descr) {
        print ("$host: $intf: Description is blank!n");

exit 0;

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.

Tags: , ,
%d bloggers like this: