#!/usr/local/bin/perl -w

require 5.003;

use strict;

use BER;
use SNMP_Session;

my $host = shift @ARGV || die;
my $community = shift @ARGV || die;

my $ciscoMemoryPoolName = [1,3,6,1,4,1,9,9,48,1,1,1,2];
my $ciscoMemoryPoolAlternate = [1,3,6,1,4,1,9,9,48,1,1,1,3];
my $ciscoMemoryPoolValid = [1,3,6,1,4,1,9,9,48,1,1,1,4];
my $ciscoMemoryPoolUsed = [1,3,6,1,4,1,9,9,48,1,1,1,5];
my $ciscoMemoryPoolFree = [1,3,6,1,4,1,9,9,48,1,1,1,6];
my $ciscoMemoryPoolLargestFree = [1,3,6,1,4,1,9,9,48,1,1,1,7];

my %CiscoMemoryPoolTypes = (
			    1 => "processor memory",
			    2 => "i/o memory",
			    3 => "pci memory",
			    4 => "fast memory",
			    5 => "multibus memory");

sub out_memory_pool_entry {
  my ($index, $name, $alt, $valid, $used, $free, $largest) = @_;

  grep (defined $_ && ($_=pretty_print $_),
	($name, $alt, $valid, $used, $free, $largest));
  my $type = $CiscoMemoryPoolTypes{$index} || $index;
  printf STDOUT ("%-13s %6d %3s %10d %10d %10d %10d\n",
		 $name, $alt,
		 $valid ? 'yes' : 'no',
		 $used+$free, $used, $free, $largest);
}

my $session = SNMP_Session->open ($host, $community, 161)
  || die "Opening SNMP_Session";
printf STDOUT ("%-13s %6s %3s %10s %10s %10s %10s\n",
	       "Name", "Alt", "Vld", "Total", "Used", "Free", "Largest");
print STDOUT "-" x (13+7+4+11+11+11+11),"\n";
$session->map_table ([
		      $ciscoMemoryPoolName,
		      $ciscoMemoryPoolAlternate,
		      $ciscoMemoryPoolValid,
		      $ciscoMemoryPoolUsed,
		      $ciscoMemoryPoolFree,
		      $ciscoMemoryPoolLargestFree],
		     \&out_memory_pool_entry);
$session->close ();
1;
