This is a followup to
Multiple Different Snmp Agents in Single JVM. I had fixed the initial problem by implementing the following code in the SnmpAgent constructor. I have three SNMP Agents that I need to start up in a single JVM due to a requirement on the software we are designing (thus the simulation manager product recommended in the last post will not work). For purposes of this post I will call them XX1SnmpAgent, XX2SnmpAgent, XX3SnmpAgent.
Each agent is setup using a virtual IP address:
XX1SnmpAgent: 192.168.189.50
XX2SnmpAgent: 192.168.189.71
XX3SnmpAgent: 192.168.189.80
The first thing I did was to setup a new constructor which looks like the code below:
- public XXXSnmpAgent(String[] args, String addr, String dir) {
super(addr, 8001);
// This takes care of the options
this.agentOptions = new AgentParamOptions(args);
AgentUtil.setAgentDir(dir);
AgentUtil.setLoggingParameters(6, "." + File.separator + "logs" + File.separator + "xxx");
XXXSnmpAgent.agentDir = dir;
XXXSnmpAgent.ipAddress = addr;
Thread th = new Thread(this);
th.start();
}
The next think was to setup the TrapListener as such:
- trapListener = SnmpAgentInitializer.getTrapListener();
/* User code starts here */
trapListener.setLocalAddress(ipAddress);
trapListener.setAgentAddr(ipAddress);
trapListener.setUsesSeperateSession(false);
/* User code ends here */
However two issues that need to get fixed and am requesting help on:
- Traps come out from a single IP address, my guess is the last SNMP session intialized. I have tried to set the setUsesSeperateSession to true in the above code, however then the SNMP agents stop responding to requests.
- Logs are output into a single log file after all agents have been initialized.
My guess is the two issues reside from the SnmpAgentToolkit's use of Static Classes and a Cache, but I really need to find away to fix those two things.