Alien-SNMP
view release on metacpan or search on metacpan
lib/Alien/SNMP.pm view on Meta::CPAN
resolve normally, in both directions, once a collection is on the search path.
Put one there with the C<-M> option or the C<MIBDIRS> environment variable, or
place files in F<~/.snmp/mibs>, which is on the default path:
$ MIBDIRS=/path/to/mibs snmptranslate .1.3.6.1.2.1.1.3.0
SNMPv2-MIB::sysUpTime.0
From Perl, C<SNMP::addMibDirs> and C<SNMP::loadModules> do the same job. Either
way that covers the modules Net-SNMP loads by default; anything outside that
list also needs naming, with C<-m> or the C<MIBS> environment variable.
=head2 The MIB index files are gone
Net-SNMP 5.9 removed the on-disk MIB index cache. It no longer writes or reads
the C<.index> files older versions left inside MIB directories, nor the numbered
files under C<SNMP_PERSISTENT_DIR>, and that variable now has no bearing on MIB
indexing at all. Parsing is unaffected: C<snmptranslate>, C<SNMP::addMibDirs>
and C<SNMP::loadModules> behave as they always did, and directories are simply
rescanned each run instead of being read from a cache.
What is gone is any way to ask Net-SNMP B<which file defines a given module>.
It still tracks that internally but exposes no accessor, so code that located a
module's file by reading an index directory will find nothing there. Derive the
mapping from the files instead, following Net-SNMP's own rule from
C<add_mibfile()> in F<snmplib/parse.c>: a file defines a module when its first
token is a label and its second is C<DEFINITIONS>, and that first token is the
module name. Reading the head of each candidate file until C<DEFINITIONS>
appears is enough to build the map.
Two things trip up a hand-rolled version. Strip C<--> comments before looking
for C<DEFINITIONS>, or a mention of it in a file's comment header ends the read
early; note too that an ASN.1 comment ends at a second C<--> as well as at end
of line. And do not derive the module from the file name: F<SNMPv2-MIB.txt> does
contain C<SNMPv2-MIB>, so that shortcut passes on the common case and then fails
on vendor MIBs, where F<CISCO-90-MIB.my> defines C<Cisco90Series-MIB>.
Building the map opens every file in the collection, so cache it if you need it
often.
=head1 COMMAND LINE UTILITIES
The build also produces the Net-SNMP client tools, C<snmpget>, C<snmpwalk>,
C<snmpbulkwalk>, C<snmptranslate>, C<snmptable> and the rest, from the same
pinned source as the library and the Perl modules. C<--disable-agent> means
there is no C<snmpd>; these are the client side. L</bin_dir> returns the
directory holding them, so a program that shells out can use them in preference
to whatever the operating system ships, or on a host that ships none:
use Alien::SNMP;
use Env qw( @PATH );
unshift @PATH, Alien::SNMP->bin_dir;
my $uptime = `snmpget -v2c -c public $host 1.3.6.1.2.1.1.3.0`;
They read MIBs and F<snmp.conf> from this distribution's own directories rather
than from F</usr/share/snmp/mibs> and F</etc/snmp>, so putting L</bin_dir> first
on C<PATH> changes both for anything that runs from there. See
L</Shadowing an operating system packaged SNMP.pm>.
Their options and output formats are Net-SNMP's own and are documented at
L<http://www.net-snmp.org/docs/man/>. This distribution builds with
C<--disable-manuals>, so it installs no man pages of its own for them.
=head2 Which libnetsnmp the utilities load
Each utility records this distribution's share directory as its run-path, so it
finds our C<libnetsnmp> without any help from you, and coexists with a system
Net-SNMP package. The one thing that overrides a run-path is
C<LD_LIBRARY_PATH>, an environment variable that is unset on most systems and
that C<echo $LD_LIBRARY_PATH> will show you. If it is set, and names a directory
holding another C<libnetsnmp> of the same major version, that copy is loaded
instead of ours. C<delete local $ENV{LD_LIBRARY_PATH};> around the call rules
that out.
=head1 METHODS
=head2 bin_dir
my $bin_dir = Alien::SNMP->bin_dir;
Returns the location of the net-snmp apps (snmptranslate, etc).
See L</COMMAND LINE UTILITIES>.
=head2 cflags
my $cflags = Alien::SNMP->cflags;
Returns the C compiler flags.
=head2 libs
my $libs = Alien::SNMP->libs;
Returns the linker flags.
=head1 SEE ALSO
=over 4
=item L<Alien>
=item L<Alien::Base>
=item L<SNMP>
The Perl5 'SNMP' Extension Module for the Net-SNMP SNMP package. Depends on
libnetsnmp and the corresponding version is installed along with the C
library.
=back
=head1 AUTHOR
Eric A. Miller, C<< <emiller at cpan.org> >>
=head1 LICENSE AND COPYRIGHT
Copyright 2026 Eric A. Miller.
This program is distributed under the (Revised) BSD License:
L<http://www.opensource.org/licenses/BSD-3-Clause>
( run in 1.218 second using v1.01-cache-2.11-cpan-4e7a2411597 )