org.opennms.test
Class snmpwalk

java.lang.Object
  |
  +--org.opennms.test.snmpwalk
All Implemented Interfaces:
SnmpHandler

public class snmpwalk
extends Object
implements SnmpHandler

This class is designed to provide an example of how to use the JoeSNMP libraries from OpenNMS. This example illustrates the code required to walk an SNMP tree of an individual agent on a remote host.

The class will walk the entire agent tree, or a subsection, as defined by the command line arguments. Through the command line options it is possible to set the community string, timeouts, retries, and other options used by the JoeSNMP library.

Usage: java org.opennms.test.snmpwalk [options] remote-host [object-id]

The command line options are as follows:
-v 1 || 2 || 2c Sets the SNMP protocol version. 2 & 2c are identical and stand for SNMPv2 community string based.
-c community Sets the community string used to authenticate
-r retries Sets the number of time the SNMP message is retransmitted before the communication times out.
-t timeout (seconds) Sets the timeout value. Fraction of a second is acceptable, but a millisecond resolution is the smallest supported. For example: .8 is equalivant to 800 milliseconds.
-p port The remote port to communicate with the remote agent on.

Version:
$Revision: 1.4 $
Author:
Brian Weaver, OpenNMS

Field Summary
(package private)  String m_community
          The community string used to "authenticate" the request.
(package private)  String m_host
          The remote agent to communicate with.
(package private)  int m_port
          The port where request are sent & received from.
(package private)  int m_retries
          The number of retries to use.
(package private)  String m_startOid
          The default location to start querying the table.
(package private)  SnmpObjectId m_stopAt
          The object identifier where the walk of the tree should stop.
(package private)  int m_timeout
          The time period to wait before considering the last transmission a failure.
(package private)  int m_version
          The version of the SNMP protocol used to communicate
 
Constructor Summary
snmpwalk()
           
 
Method Summary
static void main(String[] args)
          The main routine.
(package private)  void parseOptions(String[] args)
          Parse the command line options.
 void snmpInternalError(SnmpSession session, int err, SnmpSyntax pdu)
          Defined by the SnmpHandler interface.
 void snmpReceivedPdu(SnmpSession session, int cmd, SnmpPduPacket pdu)
          This method is defined by the SnmpHandler interface and invoked when the agent responds to the management application.
 void snmpTimeoutError(SnmpSession session, SnmpSyntax pdu)
          This method is define by the SnmpHandler interface and invoked if an agent fails to respond.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

m_version

int m_version
The version of the SNMP protocol used to communicate

m_community

String m_community
The community string used to "authenticate" the request.

m_retries

int m_retries
The number of retries to use.

m_timeout

int m_timeout
The time period to wait before considering the last transmission a failure. This should be in milliseconds.

m_port

int m_port
The port where request are sent & received from.

m_host

String m_host
The remote agent to communicate with.

m_startOid

String m_startOid
The default location to start querying the table. This is the entire iso(1).org(3) tree by default.

m_stopAt

SnmpObjectId m_stopAt
The object identifier where the walk of the tree should stop.
Constructor Detail

snmpwalk

public snmpwalk()
Method Detail

parseOptions

void parseOptions(String[] args)
            throws IllegalArgumentException

Parse the command line options. If there is an illegal option then an exception is thrown.

The command line options are as follows:
-v 1 || 2 || 2c Sets the SNMP protocol version. 2 & 2c are identical and stand for SNMPv2 community string based.
-c community Sets the community string used to authenticate
-r retries Sets the number of time the SNMP message is retransmitted before the communication times out.
-t timeout (seconds) Sets the timeout value. Fraction of a second is acceptable, but a millisecond resolution is the smallest supported. For example: .8 is equalivant to 800 milliseconds.
-p port The remote port to communicate with the remote agent on.


snmpInternalError

public void snmpInternalError(SnmpSession session,
                              int err,
                              SnmpSyntax pdu)
Defined by the SnmpHandler interface. Used to process internal session errors.
Specified by:
snmpInternalError in interface SnmpHandler
Parameters:
session - The SNMP session in error.
err - The Error condition
pdu - The pdu associated with this error condition

snmpTimeoutError

public void snmpTimeoutError(SnmpSession session,
                             SnmpSyntax pdu)
This method is define by the SnmpHandler interface and invoked if an agent fails to respond.
Specified by:
snmpTimeoutError in interface SnmpHandler
Parameters:
session - The SNMP session in error.
pdu - The PDU that timedout.

snmpReceivedPdu

public void snmpReceivedPdu(SnmpSession session,
                            int cmd,
                            SnmpPduPacket pdu)
This method is defined by the SnmpHandler interface and invoked when the agent responds to the management application.
Specified by:
snmpReceivedPdu in interface SnmpHandler
Parameters:
session - The session receiving the pdu.
cmd - The command from the pdu.
pdu - The received pdu.
See Also:
SnmpPduPacket.getCommand()

main

public static void main(String[] args)
The main routine.