Name | Last modified | Size | Description | |
---|---|---|---|---|
Parent Directory | - | |||
old/ | 2014-05-25 12:01 | - | ||
ReadMe | 1999-01-27 17:16 | 769 | ||
Altoids1.017.tar.gz | 1999-01-28 17:04 | 48K | ||
use Altoids;
$snmp = Altoids->new(\%hints, @oid_files); $snmp->open($gateway, $community, $port); %retblock = $snmp->get($name, $index); %retblock = $snmp->walk($name); $snmp->close();
get
and walk
, which are the roughly equivalent to the correspondingly named snmpget and snmpwalk commands of the CMU SNMP package. Additionally, it is able to assimilate
information from SunNet Manager
file.oid files so that short alpha names (eg. ``sysName'') are used rather than
having to use the cumbersome dotted-decimal OIDs (eg. ``1.3.6.1.2.1.1.5'').
(It does this as an alternative to a full-blown MIB compiler to translate
OIDs - hence the name Altoids.)
An example hints_hashref is defined in the file altoids.pl that will be installed with this package. This example is used by the altwalk and altget utilities, also supplied. If you find the need to write your own ``hints'', or to augment that example, the following discussion is an attempt to explain this feature.
hints_hashref is a reference to a hash containing entries of this form:
shortname => { attribute => value(s), },
where shortname is the short name by which you'd like to refer to a given OID. attribute is an attribute of this entry. The possible attributes are: oid, humanoid, lhs, rhs, rhstrans.
oid => '1.3.6.1.2.1.2.2.1.7',
Definition of this attribute is not necessary if you have specified an appropriate oid file, which contains this definition, as an argument to the constructor.
humanoid => 'iso.org.dod.internet.mgmt.mib-2.interfaces.ifTable.ifEntry.ifAdminStatus',
Definition of this attribute is not necessary if you have specified an appropriate oid file, which contains this definition, as an argument to the constructor.
type(s)
of information that is encoded as a suffix within the OID. It is an array
reference. This SNMP feature is sometimes referred to as ``conceptual
rows''. For example for lesMacRegEntry:
lhs => [ 'nstring', 'index', 'macaddr' ],
Possible values for the elements of this array are atmaddr, ipaddr, macaddr, nstring, string, and ushort:
rhstrans => { 1 => 'up(1)', 2 => 'down(2)', 3 => 'testing(3)' }
ifAdminStatus => { humanoid => 'iso.org.dod.internet.mgmt.mib-2.interfaces.ifTable.ifEntry.ifAdminStatus', oid => '1.3.6.1.2.1.2.2.1.7', rhstrans => { 1 => 'up(1)', 2 => 'down(2)', 3 => 'testing(3)' } },
sysDescr => { rhs => 'string' # sysDescr is a printable ASCII string },
# ...
If a hash reference is passed as the last argument, the referenced hash will also be populated with the returned values.
If no name can be translated to an OID or the named variables are not available returns an empty hash. Returns (-1, -1) on other errors.
number(s)
and returns a hash
where the human-readable OID segments are the keys and either hashes or,
ultimately, the OID values is the value. That is, it is a hash of a hash of
a value in the simplest case. In a scalar context, returns just the value.
If a hash reference is passed as the last argument, the referenced hash will also be populated with the returned values.
If the name can't be translated to an OID or the named variable is not available returns an empty hash. Returns (-1, -1) on other errors.
use Altoids;
$hints = { sysDescr => { # from "RFC1213-MIB" humanoid => 'iso.org.dod.internet.mgmt.mib-2.system.sysDescr', oid => '1.3.6.1.2.1.1.1', rhs => 'string', }, };
$snmp = Altoids->new($hints); $snmp->open('localhost', 'public', 161); %retblock = $snmp->get('sysDescr', 0); die "get failed.\n" if (-1 == $retblock{-1}); print $retblock{sysDescr}{0}, "\n"; $snmp->close();
exit
example2.pl:
use Altoids;
$snmp = Altoids->new('oids/RFC1213-MIB.oid'); $snmp->open('localhost', 'public', 161); %retblock = $snmp->walk('system'); die "walk failed.\n" if (-1 == $retblock{-1}); hashprint('', %retblock); $snmp->close();
exit;
sub hashprint { my $prefix = shift @_; my %hash = @_; my ($val, $key);
while (($key, $val) = each(%hash)) { if ('HASH' eq ref($val)) { hashprint($prefix? $prefix . '.' . $key : $key, %{$val}) } else { print $prefix, '.', "$key = $val\n" } } }
STDERR
) by:
$Altoids::verbose = 1;
This package sometimes die
s when bad things happen.