📄 snmp.pm
字号:
decimal unsigned integer=item COUNTER64decimal unsigned integer=item GAUGEdecimal unsigned integer=item UINTEGERdecimal unsigned integer=item TICKSdecimal unsigned integer=item OPAQUEperl scalar containing octets=item NULLperl scalar containing nothing=back=item <type>SNMP data type (see list above), this field ispopulated by 'get' and 'getnext' operations. Insome cases the programmer needs to populate thisfield when passing to a 'set' operation. thisfield need not be supplied when the attributeindicated by <tag> is already described by loadedMib modules. for 'set's, if a numeric OID is usedand the object is not currently in the loaded Mib,the <type> field must be supplied=back=item simple stringlight weight form of <var> used to 'set' or 'get' asingle attribute without constructing an SNMP::Varbind.stored in a perl scalar, has the form '<tag>.<iid>',(e.g., 'sysDescr.0'). for 'set' operations the valueis passed as a second arg. Note: This argument form isnot updated in get[next] operations as are the other forms.=back=head1 Acceptable callback formats<callback> may be one of the following forms:=over=item without arguments=over=item \&subname=item sub { ... }=back=item or with arguments=over=item [ \&subname, $arg1, ... ]=item [ sub { ... }, $arg1, ... ]=item [ "method", $obj, $arg1, ... ]=back=backcallback will be called when response is received or timeoutoccurs. the last argument passed to callback will be aSNMP::VarList reference. In case of timeout the last argumentwill be undef.=over=item &SNMP::MainLoop([<timeout>, [<callback>]])to be used with async SNMP::Sessioncalls. MainLoop must be called after initial async callsso return packets from the agent will not be processed.If no args suplied this function enters an infinite loopso program must be exited in a callback or externallyinterupted. If <timeout(sic)=item &SNMP::finish()This function, when called from an SNMP::MainLoop() callbackfunction, will cause the current SNMP::MainLoop() to returnafter the callback is completed. finish() can be used toterminate an otherwise-infinite MainLoop. A new MainLoop()instance can then be started to handle further requests.=back=head1 SNMP package variables and functions=over=item $SNMP::VERSIONthe current version specifier (e.g., 3.1.0)=item $SNMP::auto_init_mibdefault '1', set to 0 to disable automatic readingof the MIB upon session creation. set to non-zeroto call initMib at session creation which will resultin MIB loading according to UCD env. variables (seeman mib_api)=item $SNMP::verbosedefault '0', controls warning/info output ofSNMP module, 0 => no output, 1 => enables warning/infooutput from SNMP module itself (is also controlledby SNMP::debugging - see below)=item $SNMP::use_long_namesdefault '0', set to non-zero to enable the use oflonger Mib identifiers. see translateObj. will alsoinfluence the formatting of <tag> in varbinds returnedfrom 'getnext' operations. Can be set on a per sessionbasis (UseLongNames)=item $SNMP::use_sprint_valuedefault '0', set to non-zero to enable formatting ofresponse values using the snmp libraries sprint_valuefunction. can also be set on a per session basis (seeUseSprintValue) Note: returned values may not besuitable for 'set' operations=item $SNMP::use_enumsdefault '0',set non-zero to return values as enums andallow sets using enums where appropriate. integer datawill still be accepted for set operations. can also beset on a per session basis (see UseEnums)=item $SNMP::use_numericdefault to '0',set to non-zero to have <tags> for 'get'methods returned as numeric OID's rather than descriptions.if UseLongNames is set, returns the entire OID as given,otherwise just the last two octets. setting 'UseLongNames'is highly recommended. Set on a per-session basis (seeUseNumeric).=item $SNMP::timestamp_varsdefaults to 0, set to non-zero to have an additional elementadded to each Varbind containing the time(2) timestamp.Reference the timestamps through the $varbind_ref->stamp()object method.=item $SNMP::save_descriptionsdefault '0',set non-zero to have mib parser saveattribute descriptions. must be set prior to mibinitialization=item $SNMP::debuggingdefault '0', controlls debugging output levelwithin SNMP module and libsnmp=over=item 1enables 'SNMP::verbose' (see above)=item 2level 1 plus snmp_set_do_debugging(1)=item 3level 2 plus snmp_set_dump_packet(1)=back=item $SNMP::dump_packetdefault '0', set [non-]zero to independently setsnmp_set_dump_packet()=back=head1 %SNMP::MIBa tied hash to access parsed MIB information. Afterthe MIB has been loaded this hash allows access toto the parsed in MIB meta-data(the structure of theMIB (i.e., schema)). The hash returns blessedreferences to SNMP::MIB::NODE objects which representa single MIB attribute. The nodes can be fetched withmultiple 'key' formats - the leaf name (e.g.,sysDescr)or fully/partially qualified name (e.g.,system.sysDescr) or fully qualified numeric OID. Thereturned node object supports the following fields:=over=item objectIDdotted decimal fully qualified OID=item labelleaf textual identifier (e.g., 'sysDescr')=item subIDleaf numeric OID component of objectID (e.g., '1')=item moduleIDtextual identifier for module (e.g., 'RFC1213-MIB')=item parentparent node=item childrenarray reference of children nodes=item nextNodenext lexico node B<(BUG!does not return in lexico order)>=item typereturns application type (see getType for values)=item accessreturns ACCESS (ReadOnly, ReadWrite, WriteOnly,NoAccess, Notify, Create)=item statusreturns STATUS (Mandatory, Optional, Obsolete,Deprecated)=item syntaxreturns 'textualConvention' if defined else 'type'=item textualConventionreturns TEXTUAL-CONVENTION=item unitsreturns UNITS=item hintreturns HINT=item enumsreturns hash ref {tag => num, ...}=item rangesreturns array ref of hash ref [{low => num, high => num}, ...]=item descriptionreturns DESCRIPTION ($SNMP::save_descriptions mustbe set prior to MIB initialization/parsing)=back=head1 MIB Functions=over=item &SNMP::setMib(<file>)allows dynamic parsing of the mib and explicitspecification of mib file independent of enviromentvariables. called with no args acts like initMib,loading MIBs indicated by environment variables (seeucd mib_api docs). passing non-zero second argforces previous mib to be freed and replacedB<(Note: second arg not working since freeing previousMib is more involved than before)>.=item &SNMP::initMib()calls library init_mib function if Mib not alreadyloaded - does nothing if Mib already loaded. willparse directories and load modules according toenvironment variables described in UCD documentations.(see man mib_api, MIBDIRS, MIBS, MIBFILE(S), etc.)=item &SNMP::addMibDirs(<dir>,...)calls library add_mibdir for each directorysupplied. will cause directory(s) to be added tointernal list and made available for searching insubsequent loadModules calls=item &SNMP::addMibFiles(<file>,...)calls library read_mib function. The file(s)supplied will be read and all Mib module definitionscontained therein will be added to internal mib treestructure=item &SNMP::loadModules(<mod>,...)calls library read_module function. Themodule(s) supplied will be searched for in thecurrent mibdirs and and added to internal mib treestructure. Passing special <mod>, 'ALL', will causeall known modules to be loaded.=item &SNMP::unloadModules(<mod>,...)B<*Not Implemented*>=item &SNMP::translateObj(<var>[,arg])will convert a text obj tag to an OID andvice-versa. any iid suffix is retained numerically.default behaviour when converting a numeric OIDto text form is to return leaf indentifier only(e.g.,'sysDescr') but when $SNMP::use_long_namesis non-zero or a non-zero second arg is suppliedwill return longer textual identifier. If no Mibis loaded when called and $SNMP::auto_init_mib isenabled then the Mib will be loaded. Will return'undef' upon failure.=item &SNMP::getType(<var>)return SNMP data type for given textual identifierOBJECTID, OCTETSTR, INTEGER, NETADDR, IPADDR, COUNTERGAUGE, TIMETICKS, OPAQUE, or undef=item &SNMP::mapEnum(<var>)converts integer value to enumertion tag definedin Mib or converts tag to integer depending oninput. the function will return the correspondinginteger value *or* tag for a given MIB attributeand value. The function will sense which directionto perform the conversion. Various arg formats aresupported=over=item $val = SNMP::mapEnum($varbind);where $varbind is SNMP::Varbind or equiv.note: $varbind will be updated=item $val = SNMP::mapEnum('ipForwarding', 'forwarding');=item $val = SNMP::mapEnum('ipForwarding', 1);=back=back=head1 Exported SNMP utility functionsNote: utility functions do not support async operation yet.=over=item &snmp_get()takes args of SNMP::Session::new followed by those ofSNMP::Session::get=item &snmp_getnext()takes args of SNMP::Session::new followed by those ofSNMP::Session::getnext=item &snmp_set()takes args of SNMP::Session::new followed by those ofSNMP::Session::set=item &snmp_trap()takes args of SNMP::TrapSession::new followed by those ofSNMP::TrapSession::trap=back=head1 Trouble ShootingIf problems occur there are number areas to look at to narrow down thepossibilities.The first step should be to test the UCD SNMP installationindependently from the Perl5 SNMP interface.Try running the apps from the UCD SNMP distribution.Make sure your agent (snmpd) is running and properly configured withread-write access for the community you are using.Ensure that your MIBs are installed and enviroment variables are setappropriately (see man mib_api)Be sure to remove old ucd-snmp installations and ensure headers andlibraries from old CMU installations are not being used by mistake.If the problem occurs during compilation/linking check that the snmplibrary being linked is actually the UCD SNMP library (there have beenname conflicts with existing snmp libs).Also check that the header files are correct and up to date.Sometimes compiling the UCD SNMP library with'position-independent-code' enabled is required (HPUX specifically).If you cannot resolve the problem you can post tocomp.lang.perl.modules or email me at gmarzot@nortelnetworks.comand/or ucd-snmp-coders@ucd-snmp.ucdavis.edu.please give sufficient information to analyze the problem (OS type,versions for OS/Perl/UCD/compiler, complete error output, etc.)=head1 AcknowledmentsMany thanks to all those who supplied patches, suggestions andfeedback. Wes Hardaker and the ucd-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 Perl5 PortersApologies to any/all who's patch/feature/request was not mentioned orincluded - most likely it was lost when paying work intruded on myfun. Please try again if you do not see a desired feature. This mayactually turn out to be a decent package with such excellent help andthe fact that I have more time to work on it than in the past.=head1 AUTHORbugs, comments, questions to gmarzot@nortelnetworks.com=head1 Copyright 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.=cut
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -