Hovav
Hovav

Reputation: 151

SNMP4J: how to limit received trap by community string or at least know the community string of the trap?

I wrote an application based on SNMP4J for sending SNMP requests and receiving traps. all works fine but I couldn't find how to set the community string for received traps or even how to see the community string for each received trap.

help will be highly appriciated

Upvotes: 1

Views: 1175

Answers (2)

Hovav
Hovav

Reputation: 151

Inside public void processPdu(CommandResponderEvent event), the following will get the community name :

String community = new String(event.getSecurityName());

Upvotes: 1

user5105471
user5105471

Reputation: 11

I'm afraid it's not the true "community name".

The method "event.getSecurityName()" only gives you the "SecurityName" of this trap package. And it is set when you config a trap information on your device.

The true "community name" is used for config the device by SNMPv2 API. For example, the community of device is "public", and you can set a SNMPv2c trap information with security name of "mypublic". Then you will get "mypublic" by calling event.getSecurityName() but not the "public".

Upvotes: 1

Related Questions