O'Reilly logo

Essential SNMP by Kevin Schmidt, Douglas Mauro

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

SNMP Operations

The routines for performing SNMP operations correspond to the standard SNMP Version 1 operations[78] and have the following parameters in common:

community (optional)

The community string. If no community string is specified, public is used.

host (required)

The hostname or IP address of the device you want to query.

port (optional)

The port number to which to send the query or trap. The default for all routines except snmptrap() is 161. The default for snmptrap() is 162.

timeout (optional)

The timeout in seconds; if no response is received within this period, the operation is considered to have failed and is retried. The default is 2 seconds.

retries (optional)

The number of retries before the routine returns failure. The default is 5.

backoff (optional)

The backoff value; for each successive retry, the new timeout period is obtained by multiplying the current timeout with the backoff. The default is 1.

OID (required)

The object ID or textual name of the object you are querying.

snmpget( )

The syntax of the snmpget() routine is:

snmpget(community@host:port:timeout:retries:backoff, OID, [OID...])

If snmpget() fails, it returns undef.

Recall that all the MIB-II objects are preloaded into this Perl module, so the following code is legal:

@sysDescr = snmpget("public\@cisco.ora.com", "sysDescr");

We did not specify any of the optional parameters (timeout, backoff, etc.); the default values will be used. This routine lets us request "sysDescr" as shorthand for sysDescr.0. When ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required