Trap Receiver

 

Traps are unsolicited messages sent by the agent to the management applications to report the conditions of the managed node. The trapreceiver example can be used to receive the traps sent by the agents. For example:

 

java trapreceiver

 

The above command waits for the trap in the port 162, the default port for receiving traps, and prints the received traps. In some operating systems, such as Unix, some ports are accessible only for users with root privileges. The following error occurs, if the port is not accessible.

 

Error: com.adventnet.snmp.snmp2.SnmpException: java.net.BindException: Permission denied

 

In such cases, you can specify the port in which the trap can be received as follows.

 

java trapreceiver -p 8001

 

Here, the traps are received in the port 8001. For example, the following v1 trap:

 

java sendtrap -p 8001 -m ../../mibs/RFC1213-MIB remotehost 1.2.0

localhost 0 6 1000 1.5.0 testing

 

gives the following output in the trapreceiver demon.

 

Got a trap from: xx.xx.xx.xx

SNMP Trap PDU

SNMP Version: Version 1

Remote Host: xx.xx.xx.xx

Remote Port: 1430

Community: public

Request ID: 0

Timeout: 0

Retries: 0

Enterprise: .1.3.6.1.2.1.1.2.0

Trap Type: 0

Specific Type: 6

UpTime: 1000

Error Status: no error

SNMP PDU Variable Bindings:

Object ID: .1.3.6.1.2.1.1.5.0

STRING: testing

 

The output of the trapreceiver is different if we send a v2c/v3 trap.

 

java sendv2trap -p 8001 -m ../../mibs/RFC1213-MIB remotehost 5000 1.2.0 1.5.0 test

 

Output of the trapreceiver is:

 

Got a trap from: 192.168.1.40

SNMP V2 Trap PDU

SNMP Version: Version 2C

Remote Host: 192.168.1.40

Remote Port: 1436

Community: public

Request ID: 2

Timeout: 0

Retries: 0

Error Status: no error

SNMP PDU Variable Bindings:

Object ID: .1.3.6.1.2.1.1.3.0

TIMETICKS: 0 hours, 0 minutes, 50 seconds.

Object ID: .1.3.6.1.6.3.1.1.4.1.0

OBJID: .1.3.6.1.2.1.1.2.0

Object ID: .1.3.6.1.2.1.1.5.0

STRING: test

 

Source

 

API Used Available in

High-level API

<examples/applications/trapreceiver.java>

Low-level API

<examples/low_level_api_examples/snmpapps/snmptrapd.java>

MIB Support API

<examples/low_level_api_examples/mibapps/snmptrapd.java>

RMI API

<examples/rmiclient/rmitrapreceiver.java>

CORBA API

<examples/corbaclient/corbatrapreceiver.java>

 

Usage

 

The usage of the trapreceiver utility is provided below.

 

java snmptrapd [-v version(v1,v2)] [-m MIB_files] [-c community] [-p port]

 

java rmitrapreceiver [-SnmpServer hostname] [-m MIB_files] [-c community] [-p port] [-u user] [-e engineID] [-a authProtocol] [-w auth_password] [-pp privProtocol(DES/AES-128/AES-192/AES-256/3DES)] [-s priv_password]



Copyright © 2012, ZOHO Corp. All Rights Reserved.