Blame contrib/TCH/dualt1.pl

Packit 667938
#!c:\perl\bin
Packit 667938

Packit 667938
# dualt1.pl
Packit 667938
#
Packit 667938

Packit 667938
#
Packit 667938
# Created by  Eric Billeter 
Packit 667938
# returns:
Packit 667938
# Modems in use (value1)
Packit 667938
# Chassis capacity (value2)
Packit 667938

Packit 667938
use SNMP_Session;
Packit 667938
use BER;
Packit 667938
use Socket;
Packit 667938
use strict;
Packit 667938

Packit 667938
%snmpget::OIDS = (  'value1' =>  '1.3.6.1.4.1.429.1.5.4.1.3',
Packit 667938
                 );
Packit 667938

Packit 667938
my($community,$router) = split /\@/, $ARGV[0];
Packit 667938
die <
Packit 667938

Packit 667938
USAGE: hiperdsp.pl 'SNMP_community'\@'aaa.bbb.ccc.ddd'
Packit 667938

Packit 667938
Where 'aaa.bbb.ccc.ddd' is the ip address for the Network Management Card.
Packit 667938

Packit 667938
USAGE
Packit 667938

Packit 667938

Packit 667938
my($sysName,$sysUptime,$interfaces,$value1,$value2) =
Packit 667938
    snmpgettable($router,$community,'value1');
Packit 667938

Packit 667938
exit(0);
Packit 667938

Packit 667938
sub snmpgettable{
Packit 667938
  my($host,$community,$var) = @_;
Packit 667938
  my($next_oid,$enoid,$orig_oid, 
Packit 667938
     $response, $bindings, $binding, $value, $inoid,$outoid,
Packit 667938
     $upoid,$oid,@table,$tempo);
Packit 667938
  die "Unknown SNMP var $var\n" 
Packit 667938
    unless $snmpget::OIDS{$var};
Packit 667938
  
Packit 667938
  $orig_oid = encode_oid(split /\./, $snmpget::OIDS{$var});
Packit 667938
  $enoid=$orig_oid;
Packit 667938
  srand();
Packit 667938
  my $session = SNMP_Session->open ($host ,
Packit 667938
                                 $community, 
Packit 667938
                                 161);
Packit 667938
  for(;;)  {
Packit 667938
    if ($session->getnext_request_response(($enoid))) {
Packit 667938
      $response = $session->pdu_buffer;
Packit 667938
	
Packit 667938
      ($bindings) = $session->decode_get_response ($response);
Packit 667938
      ($binding,$bindings) = decode_sequence ($bindings);
Packit 667938
      ($next_oid,$value) = decode_by_template ($binding, "%O%@");
Packit 667938
      # quit once we are outside the table
Packit 667938
      last unless BER::encoded_oid_prefix_p($orig_oid,$next_oid);
Packit 667938

Packit 667938
        my $bulkindex = 2;
Packit 667938
        while( $bulkindex < "50" ){     
Packit 667938

Packit 667938
        $tempo = substr ($value,$bulkindex,1);
Packit 667938

Packit 667938
	$bulkindex=$bulkindex+2;
Packit 667938
        if( ord($tempo) eq '5' or ord($tempo) eq '3' or ord($tempo) eq '22' ){$value1=$value1 + 1 ;
Packit 667938
                }
Packit 667938
        if( ord($tempo) eq '2' or ord($tempo) eq '5' or ord($tempo) eq '3' or ord($tempo) eq '22' ){$value2=$value2 + 1 ;
Packit 667938
                }
Packit 667938
        }
Packit 667938
      push @table, $tempo;
Packit 667938
    } else {
Packit 667938
      die "No answer from $ARGV[0]\n";
Packit 667938
    }
Packit 667938
    $enoid=$next_oid;
Packit 667938
  }
Packit 667938
  $session->close (); 
Packit 667938
if( $value1 eq ''){$value1 = 0 };
Packit 667938
if( $value2 eq ''){$value2 = 0 };
Packit 667938
     print "$value1\n";
Packit 667938
     print "$value2\n";
Packit 667938
  return (@table);
Packit 667938
}