### -*- mode: Perl -*-
######################################################################
# 10/01/98 rcc
# Mods for code organization changes for new server
#
### SNMP_mib - MIB utilities
######################################################################
# Rough implementation of generalized SNMP utility subroutines.
# Uses MIB definitions in MOSY format. MOSY format MIBs can be created
# from ASN.1 MIBs using AIX's 'mosy' compiler ('mosy -o hpnp.def -s hpnp.mib').
# The resulting files can be concatenated to form 'mib.defs' (usually in /etc).
######################################################################
### Created by: Rick Cochran 07/28/98
###
### 08/11/98 rcc
### insert 'use lib'
######################################################################
package SNMP_mib;
require 5.002;
use strict;
use vars qw(@ISA @EXPORT $VERSION);
use Exporter;
use lib qw(. /usr/local/netprint/lib);
use BER;
$VERSION = '1.00';
@ISA = qw(Exporter);
@EXPORT = qw(snmp_initmib snmp_get);
### Prototypes
sub snmp_initmib ();
sub snmp_get ($@);
sub snmp_trans ($);
# Read in MOSY format MIB definitions
sub snmp_initmib ()
{
# Once is enough
return if $mibinit;
# print "Initializing MIB data\n";
srand();
my ($name, $ref, @rest);
open(F, $mibfile) or die "Unable to open $mibfile $!\n";
$miblist{'iso'} = '.1';
while ( <F> ) {
s/\s*--.*//;
next if /^$/;
($name, $ref, @rest) = split;
$miblist{$name} = $ref;
}
close(F);
$mibinit++;
return 1;
}
# Given a session ID and an array of alphanumeric OIDs, query the SNMP
# agent and return an array of values. We are assuming that the values
# come back in the same order as the OIDs.
sub snmp_get ($@)
{
my($session, @oids) = @_;
my(@eoids, $tmp, $response, $bindings, $binding, $value, $oid, @values);
# Translate alphanumeric OIDs into numeric OIDs, and thence into encoded
# OIDs, suitable for transmission to the SNMP agent. Each translation
# is 'remembered'.
sub snmp_trans ($)
{
my($oidname) = @_;