My use case is:-
- I will have an snmpv3 agent running.
- The snmp manager will fire a snmpget command with proper creds and auth
- Application should accpt the get command and return appropriate value
I have tried a lotm but I can’t connect the agent using snmpget command. Please help what I am missing,
Agent is running. sudo nc -v -u -w 3 172.24.80.1 161
gives me following output
Connection to 127.0.0.1 161 port [udp/snmp] succeeded!
Here is my relevant piece of code:
SNMPV3UserInfo userInfo = new SNMPV3UserInfo();
userInfo.setUsername("usr_1");
userInfo.setAddress("100.94.135.193");
userInfo.setAuthPswd("temp_password");
userInfo.setPrivPswd("temp_password");
MPv3 mp = new MPv3();
mp.setLocalEngineID(LOCAL_ENGINE_ID.getValue());
ThreadPool threadPool = ThreadPool.create("SnmpGet", 10);
MessageDispatcher dispatcher = new MultiThreadedMessageDispatcher(threadPool, new MessageDispatcherImpl());
CommandResponder cr = new CommandResponder() {
@Override
public void processPdu(CommandResponderEvent commandResponderEvent) {
System.out.println("..............1Anirban1...........");
}
};
//byte[] egineId = MPv3.createLocalEngineID(new OctetString(hostIpAddress + UUID.randomUUID().toString()));
Address address = new UdpAddress(InetAddress.getLocalHost(), 161);
TransportMappings transportMappings = TransportMappings.getInstance();
TransportMapping tm = transportMappings.createTransportMapping(address);
this.userInfo = userInfo;
snmp = new Snmp(dispatcher, tm);
snmp.getMessageDispatcher().addMessageProcessingModel(mp);
USM usm = new USM(SecurityProtocols.getInstance(), LOCAL_ENGINE_ID, 0);
SecurityModels.getInstance().addSecurityModel(usm);
snmp.getMessageDispatcher().addMessageProcessingModel(mp);
snmp.getMessageDispatcher().addCommandResponder(cr);
UsmUser user = new UsmUser(
new OctetString(userInfo.getUsername()),
getAuthProtocol(userInfo.getAythType()), new OctetString(userInfo.getAuthPswd()),
getPrivProtocol(userInfo.getPrivType()), new OctetString(userInfo.getPrivPswd()));
// Very important to add snmp as command responder which will finally process the PDU:
snmp.getMessageDispatcher().addCommandResponder(snmp);
snmp.getUSM().addUser(new OctetString(userInfo.getUsername()), user);
snmp.listen();
Here is the snmpget command I am using:-
sudo snmpget -u usr_1 -l authPriv -a MD5 -x DES -A temp_password -X temp_password -L eo 127.0.0.1 1.3.6.1.4.1.27675.20.10.1.2.0