I have a requirement to handle the snmpset command from the cli to my application running on a specific port and send out a reply back to the snmpset command if it is success/failure.
Here are the steps I am doing
snmpset -v 2c -r 0 -c public 10.193.154.68:11001 test s resync
and I am running the listener in 11001. I am able to get the processPdu() in CommandResponder called successfully. After the Sync process is completed, I need to send a response back to the snmpset. How do I do that?
I tried snmp.send to the ip/port from where the command was received, but did not work.
Any inputs would really be helpful.
....
public synchronized void listen(TransportIpAddress address) throws IOException
{
AbstractTransportMapping transport;
if (address instanceof TcpAddress)
{
transport = new DefaultTcpTransportMapping((TcpAddress) address);
}
else
{
transport = new DefaultUdpTransportMapping((UdpAddress) address);
}
ThreadPool threadPool = ThreadPool.create("DispatcherPool", 30);
MessageDispatcher mtDispatcher = new MultiThreadedMessageDispatcher(threadPool, new MessageDispatcherImpl());
// add message processing models
mtDispatcher.addMessageProcessingModel(new MPv1());
mtDispatcher.addMessageProcessingModel(new MPv2c());
// add all security protocols
SecurityProtocols.getInstance().addDefaultProtocols();
SecurityProtocols.getInstance().addPrivacyProtocol(new Priv3DES());
//Create Target
CommunityTarget target = new CommunityTarget();
target.setCommunity( new OctetString("public"));
snmp = new Snmp(mtDispatcher, transport);
snmp.addCommandResponder(this);
log.info("TrapListener listening on "+address);
transport.listen();
try
{
this.wait();
}
catch (InterruptedException ex)
{
Thread.currentThread().interrupt();
}
}
public synchronized void processPdu(CommandResponderEvent cmdRespEvent)
{
PDU pdu = cmdRespEvent.getPDU();
..
..
// here I want to send a reply back to the snmpset command issued from CLI.
//snmpset -v 2c -r 0 -c public 10.193.154.68:11001 test s resync
// I tried sending it back to the ip/port from which the message was received
..
..
snmp = new Snmp(mtDispatcher, transport);
snmp.addCommandResponder(this);
ResponseEvent response = snmp.send(pdu, target);
}