|->version||Returns the numeric SNMP version: 1, 2, or 3. (Note that 1 is encoded as 0 in the packet, and 2 is encoded as 1, etc., but this method returns the human-readable number, not the weird encoding in the packet.)|
|->community||Returns the community string.|
|->type||Returns the type tag of the PDU, such as NSNMP::GET_REQUEST, NSNMP::GET_RESPONSE, NSNMP::SET_REQUEST, etc. (See Constants.)|
|->request_id||Returns the bytes representing the request ID in the SNMP message. (This may seem perverse, but often, you dont have to decode them --- you can simply reuse them in a reply packet, or look them up in a hash of outstanding requests. Of course, in the latter case, you might have to decode them anyway, if the agent was perverse and re-encoded them in a different way than you sent them out.)|
|->error_status, ->error_index||Return the numeric error-status and error-index from the SNMP packet. In non-error cases, these will be 0.|
|->varbindlist||Returns a list of [$oid, $type, $value] triples. The type is a BER type, normally equal to NSNMP::OCTET_STRING or one of the other constants for BER types. (See Constants.) The OIDs are still encoded in BER; you can use ->decode_oid to get human-readable versions, as documented below.|
This method produces the BER-encoded version of the ASCII-represented OID $oid, which must be a sequence of decimal numbers separated by periods. Leading periods are allowed.
Given the BER encoding of an OID in $bytestring, this method produces the OIDs ASCII representation, as a sequence of decimal numbers separated by periods, without a leading period.
Returns a string containing an encoded SNMP message, according to the args specified. Available args correspond one for one to the NSNMP::Message methods defined above under decode; they include the following:
request_id => $req_id_str Request ID as a string (not an integer). Mandatory. varbindlist => [[$oid, $type, $value], [$oid, $type, $value]...] Varbindlist as an ARRAY ref containing (oid, type, value) tuples, represented also as ARRAY refs. OIDs, types, and values are assumed to already be BER-encoded. You can sensibly pass the results of the ->varbindlist method from a decoded message in here, just wrap it in an ARRAY ref: varbindlist => [$msg->varbindlist]. Mandatory. type => $type PDU type --- normally NSNMP::GET_REQUEST, NSNMP::GET_RESPONSE, etc. (See Constants.) Mandatory. community => $community Community string. Default is public. error_status => $error error_index => $index Error-status and error-index, as integers. Only meaningful on response messages. Default 0. version => $ver Human-readable version of SNMP: 1, 2, or 3, default 1. Presently 2 and 3 have features this library doesnt support.
Example usage of the main entry points, encode, decode, encode_oid, and decode_oid, follows:
my $bytes = NSNMP->encode( type => NSNMP::GET_REQUEST, request_id => (pack "N", 38202), varbindlist => [ [NSNMP->encode_oid(.22.214.171.124.126.96.36.199.0), NSNMP::NULL, ], ], ); $socket->send($bytes); my $decoded = NSNMP->decode($bytes); # prints "111111\n" print( ($decoded->version==1), ($decoded->community eq public), ($decoded->type eq NSNMP::GET_REQUEST), ($decoded->request_id eq pack "N", 38202), ($decoded->error_status == 0), ($decoded->error_index == 0), "\n" ); my @varbinds = $decoded->varbindlist; # prints "111\n" print( (NSNMP->decode_oid($varbinds) eq 188.8.131.52.184.108.40.206.0), ($varbinds eq NSNMP::NULL), ($varbinds eq ), "\n", );
Kragen Sitaker <email@example.com>
This documentation does not adequately express the stupidity and rottenness of the SNMP protocol design.
The ASN.1 BER, in which SNMP packets are encoded, allow the sender lots of latitude in deciding how to encode things. This module doesnt have to deal with that very often, but it does have to deal with the version, error-status, and error-index fields of SNMP messages, which are generally encoded in a single byte each. If the sender of an SNMP packet encodes them in multiple bytes instead, this module will fail to decode them, or worse, produce nonsense output. It should instead handle these packets correctly.
Malformed VarBindLists can cause the ->varbindlist method to die with an unhelpful error message. It should instead return a helpful error indication of some kind.
It doesnt do much yet; in particular, it doesnt do SNMPv1 traps or anything from SNMPv2 or v3.
It doesnt even consider doing any of the following: decoding BER values found in varbind values, understanding MIBs, or anything that involves sending or receiving packets. These jobs belong to other modules, most of which havent been written yet.
|perl v5.20.3||NSNMP (3)||2004-01-25|