Java Dynamic Management Kit 5.0 Tutorial

Sending an Inform Request (SNMPv3)

This example shows how to build an SNMPv3 manager that sends and/or receives SNMPv3 requests. It initializes an SNMPv3 USM peer and an SNMP session, and then sends an inform request to a second SNMP manager.

Example 19–10 Sending an SNMPv3 Inform Request in SimpleManager1V3

			//	When calling the program, specify the hostname of the  
			// SNMP manager to send the inform to
			final String host = argv[0];
        // Initialize the port number to send inform PDUs on port 8085.
        final int port = 8085;

	    	// Create an SnmpUSMPeer object for representing the entity 
	    	// to communicate with. 
        final SnmpUsmPeer peer = new SnmpUsmPeer(session.getEngine(),
        // Create parameters to associate to the entity to 
	      // communicate with.
       // When creating the parameter object, you specify the necessary 
	      // security related parameters.
        final SnmpUsmParameters params = 
			new SnmpUsmParameters(session.getEngine());

	    	// Set the parameters
	   		// First a principal
	      // A security level. Authentication is applied.
	      // Add a contextEngineId. The context engine Id is the 
	      // manager's engine ID and not the adaptor's.

	      // Add a context name.
       // The newly created parameter must be associated to the peer.

	      // The inform is authenticated, so the timeliness 
	      // discovery must be processed.

       // A default peer (listener manager) can be associated to an 
	      // SnmpSession. When invoking a service provided by the 
	      // SnmpSession, if the peer is not specified, the session 
	      // will perform the service using the default one as the 
	      // target of the service
       println("\nNOTE: SNMP V3 simple manager 1 initialized");
       // Make the SNMP inform request and wait for the result.
       println("\n>> Press Enter to send the inform request on " + 
		  host + " at port " + port + "...");
        try {
            } catch (IOException e) {

            final SnmpRequest request = 
		 session.snmpInformRequest(null, new SnmpOid(""), 

            println("NOTE: Inform request sent to SNMP manager on " + 
		    host + " at port " + port);

            final boolean completed = request.waitForCompletion(10000);
         // Check for a timeout of the request.
         if (completed == false) {
                println("\nSimpleManager1::main: Request timed out." +
			" Check reachability of agent");
                // Print request.
                println("Request: " + request.toString());
         // Check if the response contains an error
         final int errorStatus = request.getErrorStatus();
         if (errorStatus != SnmpDefinitions.snmpRspNoError) {
                println("Error status = " +
                println("Error index = " + request.getErrorIndex());
            // Display the content of the result.
            final SnmpVarBindList result = request.getResponseVarBindList();
            println("\nNOTE: Response received:\n" + result);
            // End the session
            println("\nNOTE: SNMP V3 simple manager 1 stopped...");


As you can see, once the SNMPv3 session has been instantiated and the SNMPv3 USM peer has been created and configured, the inform request is sent in exactly the same way as under SNMPv2. The only difference is the additional SNMPv3 security.