Cisco::Accounting

This Perl module can be used to parse and aggregate IP accounting data from Cisco devices and hosts running the IPCAD daemon.
The module is also available on CPAN and can be installed like any other default Perl module.

Use Cisco::Accounting if you want to parse IP accounting data from remote devices using telnet. The module keeps track of summarized data as well as detailed data and historical data.

This module allows you to automatically enable or disable ip accounting on the interfaces of a Cisco device.

Current version : 1.01

CIPAT is a front-end tool which uses the Cisco::Accounting module. This tool generates user friendly reports based on the IP accounting information gathered by Cisco::Accounting.

More information and examples on the CPAN website.

Here’s a fully working example that shows how to use this module :

use Cisco::Accounting;
use Data::Dumper;

my %data = (
‘host’ => “foo”,
‘user’ => “user”,
‘pwd’ => “pass”,
‘enable_user’ => “user”,
‘enable_pwd’ => “enable_pass”,
);

my $acct;
my @interfaces;
my $output;
my $stats;
my $historical;
my $count = 5;
my $i = 0;
my $interval = 10;

## initialize : make a new object, get the interfaces and enable ip accounting on 2 interfaces
eval {
$acct = Cisco::Accounting->new(%data);
@interfaces = $acct->get_interfaces();
$acct->enable_accounting(2,1);
};
die ($@) if ($@);

## start polling, 5 times with interval of 60 seconds
while ($i < $count) {

## parse IP accounnting info and clear the accounting after each 'poll'
eval {
print "getting accounting information";
$acct->do_accounting();
print ” … OK\n”;
$acct->clear_accounting();
};
if ($@) {
warn $@;
}

$i++;
sleep $interval if ($i < $count);
}

$output = $acct->get_output();
$stats = $acct->get_statistics();
$historical = $acct->get_history();

# print output
print &Dumper(\@interfaces);
print &Dumper($output);
print &Dumper($stats);
print &Dumper($historical);