.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "SNMP 3pm" .TH SNMP 3pm "2021-01-28" "perl v5.28.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" SNMP \- The Perl5 'SNMP' Extension Module for the Net\-SNMP SNMP package. .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 10 \& use SNMP; \& ... \& $sess = new SNMP::Session(DestHost => localhost, Community => public); \& $val = $sess\->get(\*(AqsysDescr.0\*(Aq); \& ... \& $vars = new SNMP::VarList([sysDescr,0], [sysContact,0], [sysLocation,0]); \& @vals = $sess\->get($vars); \& ... \& $vb = new SNMP::Varbind(); \& do { \& $val = $sess\->getnext($vb); \& print "@{$vb}\en"; \& } until ($sess\->{ErrorNum}); \& ... \& $SNMP::save_descriptions = 1; \& SNMP::initMib(); # assuming mib is not already loaded \& print "$SNMP::MIB{sysDescr}{description}\en"; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Note: The perl \s-1SNMP 5.0\s0 module which comes with net-snmp 5.0 and higher is different than previous versions in a number of ways. Most importantly, it behaves like a proper net-snmp application and calls init_snmp properly, which means it will read configuration files and use those defaults where appropriate automatically parse \s-1MIB\s0 files, etc. This will likely affect your perl applications if you have, for instance, default values set up in your snmp.conf file (as the perl module will now make use of those defaults). The documentation, however, has sadly not been updated yet (aside from this note), nor is the read_config default usage implementation fully complete. .PP The basic operations of the \s-1SNMP\s0 protocol are provided by this module through an object oriented interface for modularity and ease of use. The primary class is SNMP::Session which encapsulates the persistent aspects of a connection between the management application and the managed agent. Internally the class is implemented as a blessed hash reference. This class supplies 'get', 'getnext', 'set', 'fget', and \&'fgetnext' method calls. The methods take a variety of input argument formats and support both synchronous and asynchronous operation through a polymorphic \s-1API\s0 (i.e., method behaviour varies dependent on args passed \- see below). .SH "SNMP::Session" .IX Header "SNMP::Session" \&\f(CW$sess\fR = new SNMP::Session(DestHost => 'host', ...) .PP The following arguments may be passed to new as a hash. .SS "Basic Options" .IX Subsection "Basic Options" .IP "DestHost" 4 .IX Item "DestHost" Hostname or \s-1IP\s0 address of the \s-1SNMP\s0 agent you want to talk to. Specified in Net-SNMP formatted agent addresses. These addresses typically look like one of the following: .Sp .Vb 6 \& localhost \& tcp:localhost \& tls:localhost \& tls:localhost:9876 \& udp6:[::1]:9876 \& unix:/some/path/to/file/socket .Ve .Sp Defaults to 'localhost'. .IP "Version" 4 .IX Item "Version" \&\s-1SNMP\s0 version to use. .Sp The default is taken from library configuration \- probably 3 [1, 2 (same as 2c), 2c, 3]. .IP "Timeout" 4 .IX Item "Timeout" The number of micro-seconds to wait before resending a request. .Sp The default is '1000000' .IP "Retries" 4 .IX Item "Retries" The number of times to retry a request. .Sp The default is '5' .IP "RetryNoSuch" 4 .IX Item "RetryNoSuch" If enabled \s-1NOSUCH\s0 errors in 'get' pdus will be repaired, removing the varbind in error, and resent \- undef will be returned for all \s-1NOSUCH\s0 varbinds, when set to '0' this feature is disabled and the entire get request will fail on any \s-1NOSUCH\s0 error (applies to v1 only) .Sp The default is '0'. .SS "SNMPv3/TLS Options" .IX Subsection "SNMPv3/TLS Options" .IP "OurIdentity" 4 .IX Item "OurIdentity" Our X.509 identity to use, which should either be a fingerprint or the filename that holds the certificate. .IP "TheirIdentity" 4 .IX Item "TheirIdentity" The remote server's identity to connect to, specified as eihter a fingerprint or a file name. Either this must be specified, or the hostname below along with a trust anchor. .IP "TheirHostname" 4 .IX Item "TheirHostname" The remote server's hostname that is expected. If their certificate was signed by a \s-1CA\s0 then their hostname presented in the certificate must match this value or the connection fails to be established (to avoid man-in-the-middle attacks). .IP "TrustCert" 4 .IX Item "TrustCert" A trusted certificate to use a trust anchor (like a \s-1CA\s0 certificate) for verifying a remote server's certificate. If a \s-1CA\s0 certificate is used to validate a certificate then the TheirHostname parameter must also be specified to ensure their presente hostname in the certificate matches. .SS "SNMPv3/USM Options" .IX Subsection "SNMPv3/USM Options" .IP "SecName" 4 .IX Item "SecName" The SNMPv3 security name to use (most for SNMPv3 with \s-1USM\s0). .Sp The default is 'initial'. .IP "SecLevel" 4 .IX Item "SecLevel" The SNMPv3 security level to use [noAuthNoPriv, authNoPriv, authPriv] (v3) .Sp The default is 'noAuthNoPriv'. .IP "SecEngineId" 4 .IX Item "SecEngineId" The SNMPv3 security engineID to use (if the snmpv3 security model needs it; for example \s-1USM\s0). .Sp The default is , security engineID and it will be probed if not supplied (v3) .IP "ContextEngineId" 4 .IX Item "ContextEngineId" The SNMPv3 context engineID to use. .Sp The default is the and will be set either to the SecEngineId value if set or discovered or will be discovered in other ways if using \s-1TLS\s0 (\s-1RFC5343\s0 based discovery). .IP "Context" 4 .IX Item "Context" The SNMPv3 context name to use. .Sp The default is '' (an empty string) .IP "AuthProto" 4 .IX Item "AuthProto" The SNMPv3/USM authentication protocol to use [\s-1MD5, SHA\s0]. .Sp The default is '\s-1MD5\s0'. .IP "AuthPass" 4 .IX Item "AuthPass" The SNMPv3/USM authentication passphrase to use. .Sp default , authentication passphrase .IP "PrivProto" 4 .IX Item "PrivProto" The SNMPv3/USM privacy protocol to use [\s-1DES, AES\s0]. .Sp The default is '\s-1DES\s0'. .IP "PrivPass" 4 .IX Item "PrivPass" The SNMPv3/USM privacy passphrase to use. .Sp default , privacy passphrase (v3) .IP "AuthMasterKey" 4 .IX Item "AuthMasterKey" .PD 0 .IP "PrivMasterKey" 4 .IX Item "PrivMasterKey" .IP "AuthLocalizedKey" 4 .IX Item "AuthLocalizedKey" .IP "PrivLocalizedKey" 4 .IX Item "PrivLocalizedKey" .PD Directly specified SNMPv3 \s-1USM\s0 user keys (used if you want to specify the keys instead of deriving them from a password as above). .SS "SNMPv1 and SNMPv2c Options" .IX Subsection "SNMPv1 and SNMPv2c Options" .IP "Community" 4 .IX Item "Community" For SNMPv1 and SNMPv2c, the clear-text community name to use. .Sp The default is 'public'. .SS "Other Configuration Options" .IX Subsection "Other Configuration Options" .IP "VarFormats" 4 .IX Item "VarFormats" default 'undef', used by 'fget[next]', holds an hash reference of output value formatters, (e.g., { => , ... }, must match the and format used in the get operation. A special , '*', may be used to apply all s, the supplied sub is called to translate the value to a new format. The sub is called passing the Varbind as the arg .IP "TypeFormats" 4 .IX Item "TypeFormats" default 'undef', used by 'fget[next]', holds an hash reference of output value formatters, (e.g., { => , ... }, the supplied sub is called to translate the value to a new format, unless a VarFormat mathces first (e.g., \f(CW$sess\fR\->{TypeFormats}{\s-1INTEGER\s0} = \e&\fBmapEnum()\fR; although this can be done more efficiently by enabling \&\f(CW$SNMP::use_enums\fR or session creation param 'UseEnums') .IP "UseLongNames" 4 .IX Item "UseLongNames" defaults to the value of SNMP::use_long_names at time of session creation. set to non-zero to have for 'getnext' methods generated preferring longer Mib name convention (e.g., system.sysDescr vs just sysDescr) .IP "UseSprintValue" 4 .IX Item "UseSprintValue" defaults to the value of SNMP::use_sprint_value at time of session creation. set to non-zero to have return values for 'get' and 'getnext' methods formatted with the libraries snprint_value function. This will result in certain data types being returned in non-canonical format Note: values returned with this option set may not be appropriate for 'set' operations (see discussion of value formats in description section) .IP "UseEnums" 4 .IX Item "UseEnums" defaults to the value of SNMP::use_enums at time of session creation. set to non-zero to have integer return values converted to enumeration identifiers if possible, these values will also be acceptable when supplied to 'set' operations .IP "UseNumeric" 4 .IX Item "UseNumeric" defaults to the value of SNMP::use_numeric at time of session creation. set to non-zero to have for get methods returned as numeric \s-1OID\s0's rather than descriptions. UseLongNames will be set so that the full \s-1OID\s0 is returned to the caller. .IP "BestGuess" 4 .IX Item "BestGuess" defaults to the value of SNMP::best_guess at time of session creation. this setting controls how are parsed. setting to 0 causes a regular lookup. setting to 1 causes a regular expression match (defined as \-Ib in snmpcmd) and setting to 2 causes a random access lookup (defined as \-IR in snmpcmd). .IP "NonIncreasing" 4 .IX Item "NonIncreasing" defaults to the value of SNMP::non_increasing at time of session creation. this setting controls if a non-increasing \s-1OID\s0 during bulkwalk will causes an error. setting to 0 causes the default behaviour (which may, in very badly performing agents, result in a never-ending loop). setting to 1 causes an error (\s-1OID\s0 not increasing) when this error occur. .IP "ErrorStr" 4 .IX Item "ErrorStr" read-only, holds the error message assoc. w/ last request .IP "ErrorNum" 4 .IX Item "ErrorNum" read-only, holds the snmp_err or staus of last request .IP "ErrorInd" 4 .IX Item "ErrorInd" read-only, holds the snmp_err_index when appropriate .PP Private variables: .IP "DestAddr" 4 .IX Item "DestAddr" internal field used to hold the translated DestHost field .IP "SessPtr" 4 .IX Item "SessPtr" internal field used to cache a created session structure .IP "RemotePort" 4 .IX Item "RemotePort" Obsolete. Please use the DestHost specifier to indicate the hostname and port combination instead of this paramet. .SS "SNMP::Session methods" .IX Subsection "SNMP::Session methods" .ie n .IP "$sess\->update()" 4 .el .IP "\f(CW$sess\fR\->update()" 4 .IX Item "$sess->update()" Updates the SNMP::Session object with the values fields passed in as a hash list (similar to new()) \&\fB(\s-1WARNING\s0! not fully implemented)\fR .ie n .IP "$sess\->get( [,])" 4 .el .IP "\f(CW$sess\fR\->get( [,])" 4 .IX Item "$sess->get( [,])" do \s-1SNMP GET,\s0 multiple formats accepted. for syncronous operation will be updated with value(s) and type(s) and will also return retrieved value(s). If supplied method will operate asynchronously .ie n .IP "$sess\->fget( [,])" 4 .el .IP "\f(CW$sess\fR\->fget( [,])" 4 .IX Item "$sess->fget( [,])" do \s-1SNMP GET\s0 like 'get' and format the values according the handlers specified in \f(CW$sess\fR\->{VarFormats} and \&\f(CW$sess\fR\->{TypeFormats} .ie n .IP "$sess\->getnext( [,])" 4 .el .IP "\f(CW$sess\fR\->getnext( [,])" 4 .IX Item "$sess->getnext( [,])" do \s-1SNMP GETNEXT,\s0 multiple formats accepted, returns retrieved value(s), passed as arguments are updated to indicate next lexicographical ,,, and .Sp Note: simple string ,(e.g., 'sysDescr.0') form is not updated. If supplied method will operate asynchronously .ie n .IP "$sess\->fgetnext( [,])" 4 .el .IP "\f(CW$sess\fR\->fgetnext( [,])" 4 .IX Item "$sess->fgetnext( [,])" do \s-1SNMP GETNEXT\s0 like getnext and format the values according the handlers specified in \f(CW$sess\fR\->{VarFormats} and \&\f(CW$sess\fR\->{TypeFormats} .ie n .IP "$sess\->set( [,])" 4 .el .IP "\f(CW$sess\fR\->set( [,])" 4 .IX Item "$sess->set( [,])" do \s-1SNMP SET,\s0 multiple formats accepted. the value field in all formats must be in a canonical format (i.e., well known format) to ensure unambiguous translation to \s-1SNMP MIB\s0 data value (see discussion of canonical value format description section), returns snmp_errno. If supplied method will operate asynchronously .ie n .IP "$sess\->getbulk(, , )" 4 .el .IP "\f(CW$sess\fR\->getbulk(, , )" 4 .IX Item "$sess->getbulk(, , )" do an \s-1SNMP GETBULK,\s0 from the list of Varbinds, the single next lexico instance is fetched for the first n Varbinds as defined by . For remaining Varbinds, the m lexico instances are retrieved each of the remaining Varbinds, where m is . .ie n .IP "$sess\->bulkwalk(, , [,])" 4 .el .IP "\f(CW$sess\fR\->bulkwalk(, , [,])" 4 .IX Item "$sess->bulkwalk(, , [,])" Do a \*(L"bulkwalk\*(R" of the list of Varbinds. This is done by sending a \s-1GETBULK\s0 request (see \fBgetbulk()\fR above) for the Varbinds. For each requested variable, the response is examined to see if the next lexico instance has left the requested sub-tree. Any further instances returned for this variable are ignored, and the walk for that sub-tree is considered complete. .Sp If any sub-trees were not completed when the end of the responses is reached, another request is composed, consisting of the remaining variables. This process is repeated until all sub-trees have been completed, or too many packets have been exchanged (to avoid loops). .Sp The \fBbulkwalk()\fR method returns an array containing an array of Varbinds, one for each requested variable, in the order of the variable requests. Upon error, \fBbulkwalk()\fR returns undef and sets \f(CW$sess\fR\->ErrorStr and \f(CW$sess\fR\->ErrorNum. If a callback is supplied, \fBbulkwalk()\fR returns the \s-1SNMP\s0 request id, and returns immediately. The callback will be called with the supplied argument list and the returned variables list. .Sp Note: Because the client must \*(L"discover\*(R" that the tree is complete by comparing the returned variables with those that were requested, there is a potential \*(L"gotcha\*(R" when using the max-repeaters value. Consider the following code to print a list of interfaces and byte counts: .Sp .Vb 3 \& $numInts = $sess\->get(\*(AqifNumber.0\*(Aq); \& ($desc, $in, $out) = $sess\->bulkwalk(0, $numInts, \& [[\*(AqifDescr\*(Aq], [\*(AqifInOctets\*(Aq], [\*(AqifOutOctets\*(Aq]]); \& \& for $i (0..($numInts \- 1)) { \& printf "Interface %4s: %s inOctets, %s outOctets\en", \& $$desc[$i]\->val, $$in[$i]\->val, $$out[$i]\->val; \& } .Ve .Sp This code will produce *two* requests to the agent \*(-- the first to get the interface values, and the second to discover that all the information was in the first packet. To get around this, use '$numInts + 1' for the max_repeaters value. This asks the agent to include one additional (unrelated) variable that signals the end of the sub-tree, allowing \fBbulkwalk()\fR to determine that the request is complete. .ie n .IP "$results = $sess\->gettable(<\s-1TABLE OID\s0>, gettable(<\s-1TABLE OID\s0>, gettable(, \*(Aqlocalhost\*(Aq); \& \& print Dumper($s\->gettable(\*(AqifTable\*(Aq)); .Ve .Sp On my machine produces: .Sp .Vb 10 \& $VAR1 = { \& \*(Aq6\*(Aq => { \& \*(AqifMtu\*(Aq => \*(Aq1500\*(Aq, \& \*(AqifPhysAddress\*(Aq => \*(AqPV\*(Aq, \& # ... \& \*(AqifInUnknownProtos\*(Aq => \*(Aq0\*(Aq \& }, \& \*(Aq4\*(Aq => { \& \*(AqifMtu\*(Aq => \*(Aq1480\*(Aq, \& \*(AqifPhysAddress\*(Aq => \*(Aq\*(Aq, \& # ... \& \*(AqifInUnknownProtos\*(Aq => \*(Aq0\*(Aq \& }, \& # ... \& }; .Ve .Sp By default, it will try to do as optimized retrieval as possible. It'll request multiple columns at once, and use \s-1GETBULK\s0 if possible. A few options may be specified by passing in an \fI\s-1OPTIONS\s0\fR hash containing various parameters: .RS 4 .IP "noindexes => 1" 4 .IX Item "noindexes => 1" Instructs the code not to parse the indexes and place the results in the second hash. If you don't need the index data, this will be faster. .IP "columns => [ colname1, ... ]" 4 .IX Item "columns => [ colname1, ... ]" This specifies which columns to collect. By default, it will try to collect all the columns defined in the \s-1MIB\s0 table. .IP "repeat => \fI\s-1COUNT\s0\fR" 4 .IX Item "repeat => COUNT" Specifies a \s-1GETBULK\s0 repeat \fI\s-1COUNT\s0\fR. \s-1IE,\s0 it will request this many varbinds back per column when using the \s-1GETBULK\s0 operation. Shortening this will mean smaller packets which may help going through some systems. By default, this value is calculated and attempts to guess at what will fit all the results into 1000 bytes. This calculation is fairly safe, hopefully, but you can either raise or lower the number using this option if desired. In lossy networks, you want to make sure that the packets don't get fragmented and lowering this value is one way to help that. .IP "nogetbulk => 1" 4 .IX Item "nogetbulk => 1" Force the use of \s-1GETNEXT\s0 rather than \s-1GETBULK.\s0 (always true for SNMPv1, as it doesn't have \s-1GETBULK\s0 anyway). Some agents are great implementers of \s-1GETBULK\s0 and this allows you to force the use of \&\s-1GETNEXT\s0 operations instead. .IP "callback => \e&subroutine" 4 .IX Item "callback => &subroutine" .PD 0 .IP "callback => [\e&subroutine, optarg1, optarg2, ...]" 4 .IX Item "callback => [&subroutine, optarg1, optarg2, ...]" .PD If a callback is specified, gettable will return quickly without returning results. When the results are finally retrieved the callback subroutine will be called (see the other sections defining callback behaviour and how to make use of SNMP::MainLoop which is required fro this to work). An additional argument of the normal hash result will be added to the callback subroutine arguments. .Sp Note 1: internally, the gettable function uses it's own callbacks which are passed to getnext/getbulk as appropriate. .Sp Note 2: callback support is only available in the \s-1SNMP\s0 module version 5.04 and above. To test for this in code intending to support both versions prior to 5.04 and 5.04 and up, the following should work: .Sp .Vb 5 \& if ($response = $sess\->gettable(\*(AqifTable\*(Aq, callback => \e&my_sub)) { \& # got a response, gettable doesn\*(Aqt support callback \& my_sub($response); \& $no_mainloop = 1; \& } .Ve .Sp Deciding on whether to use SNMP::MainLoop is left as an exercise to the reader since it depends on whether your code uses other callbacks as well. .RE .RS 4 .RE .ie n .IP "$sess\->get_sec_engine_id" 4 .el .IP "\f(CW$sess\fR\->get_sec_engine_id" 4 .IX Item "$sess->get_sec_engine_id" Returns the security engine \s-1ID\s0 for the current session, whether probed or provided by the client, in hex format suitable for the SecEngineId parameter when creating a session in the future. Returns undef if we have not had not had any contact with the remote agent yet. .ie n .IP "$sess\->get_context_engine_id" 4 .el .IP "\f(CW$sess\fR\->get_context_engine_id" 4 .IX Item "$sess->get_context_engine_id" Like get_sec_engine_id, but for the context engine \s-1ID\s0 (ContextEngineId). .SH "SNMP::TrapSession" .IX Header "SNMP::TrapSession" \&\f(CW$sess\fR = new SNMP::Session(DestHost => 'host', ...) .PP supports all applicable fields from SNMP::Session (see above) .SS "SNMP::TrapSession methods" .IX Subsection "SNMP::TrapSession methods" .ie n .IP "$sess\->trap(enterprise, agent, generic, specific, uptime, )" 4 .el .IP "\f(CW$sess\fR\->trap(enterprise, agent, generic, specific, uptime, )" 4 .IX Item "$sess->trap(enterprise, agent, generic, specific, uptime, )" .Vb 7 \& $sess\->trap(enterprise=>\*(Aq.1.3.6.1.4.1.2021\*(Aq, # or \*(Aqucdavis\*(Aq [default] \& agent => \*(Aq127.0.0.1\*(Aq, # or \*(Aqlocalhost\*(Aq,[dflt 1st intf on host] \& generic => specific, # can be omitted if \*(Aqspecific\*(Aq supplied \& specific => 5, # can be omitted if \*(Aqgeneric\*(Aq supplied \& uptime => 1234, # dflt to localhost uptime (0 on win32) \& [[ifIndex, 1, 1],[sysLocation, 0, "here"]]); # optional vars \& # always last .Ve .IP "trap(oid, uptime, ) \- v2 format" 4 .IX Item "trap(oid, uptime, ) - v2 format" .Vb 4 \& $sess\->trap(oid => \*(AqsnmpRisingAlarm\*(Aq, \& uptime => 1234, \& [[ifIndex, 1, 1],[sysLocation, 0, "here"]]); # optional vars \& # always last .Ve .SH "Acceptable variable formats:" .IX Header "Acceptable variable formats:" may be one of the following forms: .IP "SNMP::VarList" 4 .IX Item "SNMP::VarList" represents an array of \s-1MIB\s0 objects to get or set, implemented as a blessed reference to an array of SNMP::Varbinds, (e.g., [, , ...]) .IP "SNMP::Varbind" 4 .IX Item "SNMP::Varbind" represents a single \s-1MIB\s0 object to get or set, implemented as a blessed reference to a 4 element array; [, , , ]. .RS 4 .IP "" 4 .IX Item "" one of the following forms: .RS 4 .IP "1)" 4 .IX Item "1)" leaf identifier (e.g., 'sysDescr') assumed to be unique for practical purposes .IP "2)" 4 .IX Item "2)" fully qualified identifier (e.g., \&'.iso.org.dod.internet.mgmt.mib\-2.system.sysDescr') .IP "3)" 4 .IX Item "3)" fully qualified, dotted-decimal, numeric \s-1OID\s0 (e.g., \&'.1.3.6.1.2.1.1.1') .RE .RS 4 .RE .IP "" 4 .IX Item "" the dotted-decimal, instance identifier. for scalar \s-1MIB\s0 objects use '0' .IP "" 4 .IX Item "" the \s-1SNMP\s0 data value retrieved from or being set to the agents \s-1MIB.\s0 for (f)get(next) operations may have a variety of formats as determined by session and package settings. However for set operations the format must be canonical to ensure unambiguous translation. The canonical forms are as follows: .RS 4 .IP "\s-1OBJECTID\s0" 4 .IX Item "OBJECTID" dotted-decimal (e.g., .1.3.6.1.2.1.1.1) .IP "\s-1OCTETSTR\s0" 4 .IX Item "OCTETSTR" perl scalar containing octets .IP "\s-1INTEGER\s0" 4 .IX Item "INTEGER" decimal signed integer (or enum) .IP "\s-1NETADDR\s0" 4 .IX Item "NETADDR" dotted-decimal .IP "\s-1IPADDR\s0" 4 .IX Item "IPADDR" dotted-decimal .IP "\s-1COUNTER\s0" 4 .IX Item "COUNTER" decimal unsigned integer .IP "\s-1COUNTER64\s0" 4 .IX Item "COUNTER64" decimal unsigned integer .IP "\s-1GAUGE\s0" 4 .IX Item "GAUGE" decimal unsigned integer .IP "\s-1UINTEGER\s0" 4 .IX Item "UINTEGER" decimal unsigned integer .IP "\s-1TICKS\s0" 4 .IX Item "TICKS" decimal unsigned integer .IP "\s-1OPAQUE\s0" 4 .IX Item "OPAQUE" perl scalar containing octets .IP "\s-1NULL\s0" 4 .IX Item "NULL" perl scalar containing nothing .RE .RS 4 .RE .IP "" 4 .IX Item "" \&\s-1SNMP\s0 data type (see list above), this field is populated by 'get' and 'getnext' operations. In some cases the programmer needs to populate this field when passing to a 'set' operation. this field need not be supplied when the attribute indicated by is already described by loaded Mib modules. for 'set's, if a numeric \s-1OID\s0 is used and the object is not currently in the loaded Mib, the field must be supplied .RE .RS 4 .RE .IP "simple string" 4 .IX Item "simple string" light weight form of used to 'set' or 'get' a single attribute without constructing an SNMP::Varbind. stored in a perl scalar, has the form '.', (e.g., 'sysDescr.0'). for 'set' operations the value is passed as a second arg. Note: This argument form is not updated in get[next] operations as are the other forms. .SH "Acceptable callback formats" .IX Header "Acceptable callback formats" may be one of the following forms: .IP "without arguments" 4 .IX Item "without arguments" .RS 4 .PD 0 .IP "\e&subname" 4 .IX Item "&subname" .IP "sub { ... }" 4 .IX Item "sub { ... }" .RE .RS 4 .RE .IP "or with arguments" 4 .IX Item "or with arguments" .RS 4 .ie n .IP "[ \e&subname, $arg1, ... ]" 4 .el .IP "[ \e&subname, \f(CW$arg1\fR, ... ]" 4 .IX Item "[ &subname, $arg1, ... ]" .ie n .IP "[ sub { ... }, $arg1, ... ]" 4 .el .IP "[ sub { ... }, \f(CW$arg1\fR, ... ]" 4 .IX Item "[ sub { ... }, $arg1, ... ]" .ie n .IP "[ ""method"", $obj, $arg1, ... ]" 4 .el .IP "[ ``method'', \f(CW$obj\fR, \f(CW$arg1\fR, ... ]" 4 .IX Item "[ method, $obj, $arg1, ... ]" .RE .RS 4 .RE .PD .PP callback will be called when response is received or timeout occurs. the last argument passed to callback will be a SNMP::VarList reference. In case of timeout the last argument will be undef. .IP "&SNMP::MainLoop([, []])" 4 .IX Item "&SNMP::MainLoop([, []])" to be used with async SNMP::Session calls. MainLoop must be called after initial async calls so return packets from the agent will not be processed. If no args supplied this function enters an infinite loop so program must be exited in a callback or externally interrupted. If no output, 1 => enables warning/info output from \s-1SNMP\s0 module itself (is also controlled by SNMP::debugging \- see below) .ie n .IP "$SNMP::use_long_names" 4 .el .IP "\f(CW$SNMP::use_long_names\fR" 4 .IX Item "$SNMP::use_long_names" default '0', set to non-zero to enable the use of longer Mib identifiers. see translateObj. will also influence the formatting of in varbinds returned from 'getnext' operations. Can be set on a per session basis (UseLongNames) .ie n .IP "$SNMP::use_sprint_value" 4 .el .IP "\f(CW$SNMP::use_sprint_value\fR" 4 .IX Item "$SNMP::use_sprint_value" default '0', set to non-zero to enable formatting of response values using the snmp libraries snprint_value function. can also be set on a per session basis (see UseSprintValue) Note: returned values may not be suitable for 'set' operations .ie n .IP "$SNMP::use_enums" 4 .el .IP "\f(CW$SNMP::use_enums\fR" 4 .IX Item "$SNMP::use_enums" default '0',set non-zero to return values as enums and allow sets using enums where appropriate. integer data will still be accepted for set operations. can also be set on a per session basis (see UseEnums) .ie n .IP "$SNMP::use_numeric" 4 .el .IP "\f(CW$SNMP::use_numeric\fR" 4 .IX Item "$SNMP::use_numeric" default to '0',set to non-zero to have for 'get' methods returned as numeric \s-1OID\s0's rather than descriptions. UseLongNames will be set so that the entire \s-1OID\s0 will be returned. Set on a per-session basis (see UseNumeric). .ie n .IP "$SNMP::best_guess" 4 .el .IP "\f(CW$SNMP::best_guess\fR" 4 .IX Item "$SNMP::best_guess" default '0'. This setting controls how are parsed. Setting to 0 causes a regular lookup. Setting to 1 causes a regular expression match (defined as \-Ib in snmpcmd) and setting to 2 causes a random access lookup (defined as \-IR in snmpcmd). Can also be set on a per session basis (see BestGuess) .ie n .IP "$SNMP::save_descriptions" 4 .el .IP "\f(CW$SNMP::save_descriptions\fR" 4 .IX Item "$SNMP::save_descriptions" default '0',set non-zero to have mib parser save attribute descriptions. must be set prior to mib initialization .ie n .IP "$SNMP::debugging" 4 .el .IP "\f(CW$SNMP::debugging\fR" 4 .IX Item "$SNMP::debugging" default '0', controls debugging output level within \s-1SNMP\s0 module and libsnmp .RS 4 .IP "1." 4 enables 'SNMP::verbose' (see above) .IP "2." 4 level 1 plus \fBsnmp_set_do_debugging\fR\|(1) .IP "3." 4 level 2 plus \fBsnmp_set_dump_packet\fR\|(1) .RE .RS 4 .RE .ie n .IP "$SNMP::dump_packet" 4 .el .IP "\f(CW$SNMP::dump_packet\fR" 4 .IX Item "$SNMP::dump_packet" default '0', set [non\-]zero to independently set \&\fBsnmp_set_dump_packet()\fR .IP "\fBSNMP::register_debug_tokens()\fR" 4 .IX Item "SNMP::register_debug_tokens()" Allows to register one or more debug tokens, just like the \-D option of snmpd. Each debug token enables a group of debug statements. An example: SNMP::register_debug_tokens(\*(L"tdomain,netsnmp_unix\*(R"); .ie n .SH "%SNMP::MIB" .el .SH "\f(CW%SNMP::MIB\fP" .IX Header "%SNMP::MIB" a tied hash to access parsed \s-1MIB\s0 information. After the \s-1MIB\s0 has been loaded this hash allows access to to the parsed in \s-1MIB\s0 meta\-data(the structure of the \&\s-1MIB\s0 (i.e., schema)). The hash returns blessed references to \s-1SNMP::MIB::NODE\s0 objects which represent a single \s-1MIB\s0 attribute. The nodes can be fetched with multiple 'key' formats \- the leaf name (e.g.,sysDescr) or fully/partially qualified name (e.g., system.sysDescr) or fully qualified numeric \s-1OID.\s0 The returned node object supports the following fields: .IP "objectID" 4 .IX Item "objectID" dotted decimal fully qualified \s-1OID\s0 .IP "label" 4 .IX Item "label" leaf textual identifier (e.g., 'sysDescr') .IP "subID" 4 .IX Item "subID" leaf numeric \s-1OID\s0 component of objectID (e.g., '1') .IP "moduleID" 4 .IX Item "moduleID" textual identifier for module (e.g., '\s-1RFC1213\-MIB\s0') .IP "parent" 4 .IX Item "parent" parent node .IP "children" 4 .IX Item "children" array reference of children nodes .IP "nextNode" 4 .IX Item "nextNode" next lexico node \fB(\s-1BUG\s0!does not return in lexico order)\fR .IP "type" 4 .IX Item "type" returns application type (see getType for values) .IP "access" 4 .IX Item "access" returns \s-1ACCESS\s0 (ReadOnly, ReadWrite, WriteOnly, NoAccess, Notify, Create) .IP "status" 4 .IX Item "status" returns \s-1STATUS\s0 (Mandatory, Optional, Obsolete, Deprecated) .IP "syntax" 4 .IX Item "syntax" returns 'textualConvention' if defined else 'type' .IP "textualConvention" 4 .IX Item "textualConvention" returns TEXTUAL-CONVENTION .IP "TCDescription" 4 .IX Item "TCDescription" returns the TEXTUAL-CONVENTION's \s-1DESCRIPTION\s0 field. .IP "units" 4 .IX Item "units" returns \s-1UNITS\s0 .IP "hint" 4 .IX Item "hint" returns \s-1HINT\s0 .IP "enums" 4 .IX Item "enums" returns hash ref {tag => num, ...} .IP "ranges" 4 .IX Item "ranges" returns array ref of hash ref [{low => num, high => num}, ...] .IP "description" 4 .IX Item "description" returns \s-1DESCRIPTION\s0 ($SNMP::save_descriptions must be set prior to \s-1MIB\s0 initialization/parsing) .IP "reference" 4 .IX Item "reference" returns the \s-1REFERENCE\s0 clause .IP "indexes" 4 .IX Item "indexes" returns the objects in the \s-1INDEX\s0 clause .IP "implied" 4 .IX Item "implied" returns true if the last object in the \s-1INDEX\s0 is \s-1IMPLIED\s0 .SH "MIB Functions" .IX Header "MIB Functions" .IP "&SNMP::setMib()" 4 .IX Item "&SNMP::setMib()" allows dynamic parsing of the mib and explicit specification of mib file independent of environment variables. called with no args acts like initMib, loading MIBs indicated by environment variables (see Net-SNMP mib_api docs). passing non-zero second arg forces previous mib to be freed and replaced \&\fB(Note: second arg not working since freeing previous Mib is more involved than before)\fR. .IP "&\fBSNMP::initMib()\fR" 4 .IX Item "&SNMP::initMib()" calls library init_mib function if Mib not already loaded \- does nothing if Mib already loaded. will parse directories and load modules according to environment variables described in Net-SNMP documentations. (see man mib_api, \s-1MIBDIRS, MIBS, MIBFILE\s0(S), etc.) .IP "&SNMP::addMibDirs(,...)" 4 .IX Item "&SNMP::addMibDirs(,...)" calls library add_mibdir for each directory supplied. will cause directory(s) to be added to internal list and made available for searching in subsequent loadModules calls .IP "&SNMP::addMibFiles(,...)" 4 .IX Item "&SNMP::addMibFiles(,...)" calls library read_mib function. The file(s) supplied will be read and all Mib module definitions contained therein will be added to internal mib tree structure .IP "&SNMP::loadModules(,...)" 4 .IX Item "&SNMP::loadModules(,...)" calls library read_module function. The module(s) supplied will be searched for in the current mibdirs and and added to internal mib tree structure. Passing special , '\s-1ALL\s0', will cause all known modules to be loaded. .IP "&SNMP::unloadModules(,...)" 4 .IX Item "&SNMP::unloadModules(,...)" \&\fB*Not Implemented*\fR .IP "&SNMP::translateObj([,arg,[arg]])" 4 .IX Item "&SNMP::translateObj([,arg,[arg]])" will convert a text obj tag to an \s-1OID\s0 and vice-versa. Any iid suffix is retained numerically. Default behaviour when converting a numeric \s-1OID\s0 to text form is to return leaf identifier only (e.g.,'sysDescr') but when \f(CW$SNMP::use_long_names\fR is non-zero or a non-zero second arg is supplied it will return a longer textual identifier. An optional third argument of non-zero will cause the module name to be prepended to the text name (e.g. \&'SNMPv2\-MIB::sysDescr'). When converting a text obj, the \f(CW$SNMP::best_guess\fR option is used. If no Mib is loaded when called and \f(CW$SNMP::auto_init_mib\fR is enabled then the Mib will be loaded. Will return 'undef' upon failure. .IP "&SNMP::getType()" 4 .IX Item "&SNMP::getType()" return \s-1SNMP\s0 data type for given textual identifier \&\s-1OBJECTID, OCTETSTR, INTEGER, NETADDR, IPADDR, COUNTER GAUGE, TIMETICKS, OPAQUE,\s0 or undef .IP "&SNMP::mapEnum()" 4 .IX Item "&SNMP::mapEnum()" converts integer value to enumertion tag defined in Mib or converts tag to integer depending on input. the function will return the corresponding integer value *or* tag for a given \s-1MIB\s0 attribute and value. The function will sense which direction to perform the conversion. Various arg formats are supported .RS 4 .ie n .IP "$val = SNMP::mapEnum($varbind);" 4 .el .IP "\f(CW$val\fR = SNMP::mapEnum($varbind);" 4 .IX Item "$val = SNMP::mapEnum($varbind);" where \f(CW$varbind\fR is SNMP::Varbind or equiv. note: \f(CW$varbind\fR will be updated .ie n .IP "$val = SNMP::mapEnum('ipForwarding', 'forwarding');" 4 .el .IP "\f(CW$val\fR = SNMP::mapEnum('ipForwarding', 'forwarding');" 4 .IX Item "$val = SNMP::mapEnum('ipForwarding', 'forwarding');" .PD 0 .ie n .IP "$val = SNMP::mapEnum('ipForwarding', 1);" 4 .el .IP "\f(CW$val\fR = SNMP::mapEnum('ipForwarding', 1);" 4 .IX Item "$val = SNMP::mapEnum('ipForwarding', 1);" .RE .RS 4 .RE .PD .SH "Exported SNMP utility functions" .IX Header "Exported SNMP utility functions" Note: utility functions do not support async operation yet. .IP "&\fBsnmp_get()\fR" 4 .IX Item "&snmp_get()" takes args of SNMP::Session::new followed by those of SNMP::Session::get .IP "&\fBsnmp_getnext()\fR" 4 .IX Item "&snmp_getnext()" takes args of SNMP::Session::new followed by those of SNMP::Session::getnext .IP "&\fBsnmp_set()\fR" 4 .IX Item "&snmp_set()" takes args of SNMP::Session::new followed by those of SNMP::Session::set .IP "&\fBsnmp_trap()\fR" 4 .IX Item "&snmp_trap()" takes args of SNMP::TrapSession::new followed by those of SNMP::TrapSession::trap .SH "Trouble Shooting" .IX Header "Trouble Shooting" If problems occur there are number areas to look at to narrow down the possibilities. .PP The first step should be to test the Net-SNMP installation independently from the Perl5 \s-1SNMP\s0 interface. .PP Try running the apps from the Net-SNMP distribution. .PP Make sure your agent (snmpd) is running and properly configured with read-write access for the community you are using. .PP Ensure that your MIBs are installed and enviroment variables are set appropriately (see man mib_api) .PP Be sure to remove old net-snmp installations and ensure headers and libraries from old \s-1CMU\s0 installations are not being used by mistake. .PP If the problem occurs during compilation/linking check that the snmp library being linked is actually the Net-SNMP library (there have been name conflicts with existing snmp libs). .PP Also check that the header files are correct and up to date. .PP Sometimes compiling the Net-SNMP library with \&'position\-independent\-code' enabled is required (\s-1HPUX\s0 specifically). .PP If you cannot resolve the problem you can post to comp.lang.perl.modules or net\-snmp\-users@net\-snmp\-users@lists.sourceforge.net .PP please give sufficient information to analyze the problem (\s-1OS\s0 type, versions for OS/Perl/Net\-SNMP/compiler, complete error output, etc.) .SH "Acknowledgements" .IX Header "Acknowledgements" Many thanks to all those who supplied patches, suggestions and feedback. .PP .Vb 10 \& Joe Marzot (the original author) \& Wes Hardaker and the net\-snmp\-coders \& Dave Perkins \& Marcel Wiget \& David Blackburn \& John Stofell \& Gary Hayward \& Claire Harrison \& Achim Bohnet \& Doug Kingston \& Jacques Vidrine \& Carl Jacobsen \& Wayne Marquette \& Scott Schumate \& Michael Slifcak \& Srivathsan Srinivasagopalan \& Bill Fenner \& Jef Peeraer \& Daniel Hagerty \& Karl "Rat" Schilke and Electric Lightwave, Inc. \& Perl5 Porters \& Alex Burger .Ve .PP Apologies to any/all who's patch/feature/request was not mentioned or included \- most likely it was lost when paying work intruded on my fun. Please try again if you do not see a desired feature. This may actually turn out to be a decent package with such excellent help and the fact that I have more time to work on it than in the past. .SH "AUTHOR" .IX Header "AUTHOR" bugs, comments, questions to net\-snmp\-users@lists.sourceforge.net .SH "Copyright" .IX Header "Copyright" .Vb 3 \& Copyright (c) 1995\-2000 G. S. Marzot. All rights reserved. \& This program is free software; you can redistribute it and/or \& modify it under the same terms as Perl itself. \& \& Copyright (c) 2001\-2002 Networks Associates Technology, Inc. All \& Rights Reserved. This program is free software; you can \& redistribute it and/or modify it under the same terms as Perl \& itself. .Ve .SH "POD ERRORS" .IX Header "POD ERRORS" Hey! \fBThe above document had some coding errors, which are explained below:\fR .IP "Around line 1727:" 4 .IX Item "Around line 1727:" \&'=item' outside of any '=over' .IP "Around line 1733:" 4 .IX Item "Around line 1733:" You forgot a '=back' before '=head2'