|
The snmpget example is used to query SNMP information in a remote host in which the agent runs. The following command can be used to perform an SNMP query.
|
java snmpget localhost 1.1.0 |
The above command performs a GET operation on the SNMP agent running on localhost to get the value of the variable 1.1 (sysDescr) and display the results. Depending on whether the localhost has an SNMP agent installed, you get sysDescr or time out message. It takes several seconds for either result.
By default, it uses the UDP port 161, SNMP version 1, and the community name public. Other options, such as timeout, retries, setting the debug on, etc. can also be set in the command line.
For example we can give the following command for a v2c request in the port (8001) with community name private.
|
java snmpget -v v2 -c private -p 8001 localhost 1.1.0 |
Note that the given OID 1.1.0 does not start with a dot (.). OIDs not starting with a dot are prefixed by .1.3.6.1.2.1. Therefore, the entire OID of 1.1.0 becomes .1.3.6.1.2.1.1.1.0. We can also give the entire OID for the request. The OID can also be given in the String format instead of the numeric format if we load the corresponding MIB file. For example,
|
java snmpget -m ../../mibs/RFC1213-MIB localhost ysDescr.0 java snmpget -m ../../mibs/RFC1213-MIB localhost .iso.org.dod.internet.mgmt.mib-2.system.sysDescr.0 |
We can also make multiple OID queries in a single request as follows.
|
java snmpget localhost 1.1.0 1.2.0 1.3.0 |
To query an SNMPv3 agent running on a system v3agenthost, listening for SNMPv3 requests on port v3port, we need to know the users configured on the agent and their security configuration. Let us assume that the following USM configuration exist for v3agenthost.
|
S.No. |
UserName |
SecurityLevel |
authProtocol |
authPassword | privPassword |
|---|---|---|---|---|---|
|
1 |
initial |
NoAuthNoPriv |
none |
none |
none |
|
2 |
initial_a |
AuthNoPriv |
MD5 |
initialPass |
none |
|
3 |
initial_ap |
AuthPriv |
SHA |
initialPass |
initialPass |
Let us look at how this SNMPv3 agent can be queried using the snmpget application available with this package. To query the same information with this SNMPv3 agent without using authentication and privacy (NoAuthNoPriv profile), use the following command.
|
java snmpget -v v3 -p v3port -u initial v3agenthost 1.1.0 |
To query using authentication and no privacy (AuthNoPriv profile), the following command is used.
|
java snmpget -v v3 -p v3port -u initial_a -a MD5 -w initialPass v3agenthost 1.2.0 |
To query using authentication and privacy (AuthPriv profile), use the following command.
|
java snmpget -v v3 -p v3port -u initial_ap -a MD5 -w initialPass -s initialPass v3agenthost 1.2.0 |
One of the common errors that are made during the snmpget request is to query the agent without giving the instance value of the object. To specify an object to an SNMP agent, both the Object ID (which defines the type of object) and the instance (the specific object of the given type) need to be provided. For non-tabular or scalar objects, this is simply an instance of 0 (e.g. sysDescr.0). For example, if we make the following request without giving the instance value,
|
java snmpget localhost 1.1 |
we get the following error:
|
Request failed or timed out. Error Indication in response: There is no such variable name in this MIB. Errindex: 1 |
Therefore, we need to make sure that we completely specify the OID plus instance as follows.
|
java snmpget localhost 1.1.0 |
Source
| API Used | Available In |
|---|---|
|
High-level API |
|
|
Low-level API |
|
|
MIB support API |
|
|
RMI API |
|
|
CORBA API |
|
|
EJB API |
Usage
The usage of the snmpget is provided below. The "-d" option enables the debug and prints the packet dumps. The "host" and the "OID" arguments are mandatory and the rest are optional.
java snmpget [-d] [-v version(v1,v2,v3)] [-c community] [-p port] [-t timeout] [-r retries] [-u user] [-a auth_protocol] [-w auth_password] [-pp privProtocol(DES/AES-128/AES-192/AES-256/3DES)] [-s priv_password] [-i context_id] host OID [OID] ...
java ejbget [-EJBServer hostName] [-v version(v1,v2,v3)] [-m MIB_files] [-c community] [-p port] [-t timeout] [-r retries] [-u user] [-a auth_protocol] [-w auth_password] [-s priv_password] [-i contextID] [-n contextName] host OID [OID] ......
java rmiget [-SnmpServer hostName] [-v version(v1,v2,v3)] [-m MIB_files] [-c community] [-p port] [-t timeout] [-r retries] [-u user] [-a auth_protocol] [-w auth_password] [-s priv_password] [-i contextID] [-n contextName] host OID [OID] ...
java corbaget [-SnmpServer hostName] [-ORBInitialPort orbPort] [-ORBInitialHost orbHost] [-v version(v1,v2,v3)] [-m MIB_files] [-c community] [-p port] [-t timeout] [-r retries] [-u user] [-a auth_protocol] [-w auth_password] [-s priv_password] [-i context_id] [-n contextName] host OID [OID] ...
|