Alien-SNMP

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN


     $ MIBDIRS=/path/to/mibs snmptranslate .1.3.6.1.2.1.1.3.0
     SNMPv2-MIB::sysUpTime.0

    From Perl, "SNMP::addMibDirs" and "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 "-m" or the "MIBS" environment
    variable.

  The MIB index files are gone
    Net-SNMP 5.9 removed the on-disk MIB index cache. It no longer writes or
    reads the ".index" files older versions left inside MIB directories, nor
    the numbered files under "SNMP_PERSISTENT_DIR", and that variable now
    has no bearing on MIB indexing at all. Parsing is unaffected:
    "snmptranslate", "SNMP::addMibDirs" and "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 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 add_mibfile() in snmplib/parse.c: a file
    defines a module when its first token is a label and its second is
    "DEFINITIONS", and that first token is the module name. Reading the head
    of each candidate file until "DEFINITIONS" appears is enough to build
    the map.

    Two things trip up a hand-rolled version. Strip "--" comments before
    looking for "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
    "--" as well as at end of line. And do not derive the module from the
    file name: SNMPv2-MIB.txt does contain "SNMPv2-MIB", so that shortcut
    passes on the common case and then fails on vendor MIBs, where
    CISCO-90-MIB.my defines "Cisco90Series-MIB".

    Building the map opens every file in the collection, so cache it if you
    need it often.

COMMAND LINE UTILITIES
    The build also produces the Net-SNMP client tools, "snmpget",
    "snmpwalk", "snmpbulkwalk", "snmptranslate", "snmptable" and the rest,
    from the same pinned source as the library and the Perl modules.
    "--disable-agent" means there is no "snmpd"; these are the client side.
    "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 snmp.conf from this distribution's own directories
    rather than from /usr/share/snmp/mibs and /etc/snmp, so putting
    "bin_dir" first on "PATH" changes both for anything that runs from
    there. See "Shadowing an operating system packaged SNMP.pm".

    Their options and output formats are Net-SNMP's own and are documented
    at <http://www.net-snmp.org/docs/man/>. This distribution builds with
    "--disable-manuals", so it installs no man pages of its own for them.

  Which libnetsnmp the utilities load
    Each utility records this distribution's share directory as its
    run-path, so it finds our "libnetsnmp" without any help from you, and
    coexists with a system Net-SNMP package. The one thing that overrides a
    run-path is "LD_LIBRARY_PATH", an environment variable that is unset on
    most systems and that "echo $LD_LIBRARY_PATH" will show you. If it is
    set, and names a directory holding another "libnetsnmp" of the same
    major version, that copy is loaded instead of ours. "delete local
    $ENV{LD_LIBRARY_PATH};" around the call rules that out.

METHODS
  bin_dir
     my $bin_dir = Alien::SNMP->bin_dir;

    Returns the location of the net-snmp apps (snmptranslate, etc). See
    "COMMAND LINE UTILITIES".

  cflags
     my $cflags = Alien::SNMP->cflags;

    Returns the C compiler flags.

  libs
     my $libs = Alien::SNMP->libs;

    Returns the linker flags.

SEE ALSO
    Alien
    Alien::Base
    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.

AUTHOR
    Eric A. Miller, "<emiller at cpan.org>"

LICENSE AND COPYRIGHT
    Copyright 2026 Eric A. Miller.

    This program is distributed under the (Revised) BSD License:
    <http://www.opensource.org/licenses/BSD-3-Clause>

    Redistribution and use in source and binary forms, with or without
    modification, are permitted provided that the following conditions are
    met:

    * Redistributions of source code must retain the above copyright notice,
    this list of conditions and the following disclaimer.

    * Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.

    * Neither the name of Eric A. Miller's Organization nor the names of its
    contributors may be used to endorse or promote products derived from
    this software without specific prior written permission.



( run in 0.780 second using v1.01-cache-2.11-cpan-4e7a2411597 )