#!/usr/bin/perl -w
###
### cisco-cpus host [community]
###
### Use cpmCPUTotalTable from CISCO-PROCESS-MIB to read CPU
### utilization statistics from all CPUs in a Cisco router.
###
### Author:       Simon Leinen  <simon@switch.ch>
### Date Created: 2000/02/24
### RCS $Id: cisco-cpus,v 1.1 2000-02-24 12:12:26 leinen Exp $
###
require 5.003;

use strict;

use BER;
use SNMP_Session;

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

### From CISCO-PROCESS-MIB.my
###
my $cpmCPUTotalPhysicalIndex = [1,3,6,1,4,1,9,9,109,1,1,1,1,2];
my $cpmCPUTotal5sec = [1,3,6,1,4,1,9,9,109,1,1,1,1,3];
my $cpmCPUTotal1min = [1,3,6,1,4,1,9,9,109,1,1,1,1,4];
my $cpmCPUTotal5min = [1,3,6,1,4,1,9,9,109,1,1,1,1,5];

sub out_cpu_totals {
  my ($index, $phys_index, $cpu_5sec, $cpu_1min, $cpu_5min) = @_;

  grep (defined $_ && ($_=pretty_print $_),
	($phys_index, $cpu_5sec, $cpu_1min, $cpu_5min));
  printf STDOUT ("%2d/%-3d %5.2f %5.2f %5.2f\n",
		 $index, $phys_index,
		 $cpu_5sec,
		 $cpu_1min,
		 $cpu_5min);
}

my $session = SNMP_Session->open ($host, $community, 161)
  || die "Opening SNMP_Session";
printf STDOUT ("Idx/Phy 5sec  1min  5min\n");
print STDOUT "-" x 24,"\n";
$session->map_table ([
		      $cpmCPUTotalPhysicalIndex,
		      $cpmCPUTotal5sec,
		      $cpmCPUTotal1min,
		      $cpmCPUTotal5min],
		     \&out_cpu_totals);
$session->close ();
1;
