Hi,
I am using SNMP-4J agent library(SNMP4j-2.7.0) for running my agent. I have implemented my agent in a runnable thread and invoking this thread from another startup bean.
My agent thread starts perfectly on the given port 20100 but returns error when make discovery of the same on agents returns error “RFC3414 §3.2.4 Unknown security name:” same code runs absolutely fine when running in a stand alone package but throws error when running in EJB container.
One more observation after shutting down the agent I am unable to locate file “AgentConfig.cfg” .
Please help me out
Thanks and regards
//Startup bean code
@Singleton
@Startup
public class StartupBean {
TestAgentWithRunThread snmpAgentConsumerThread;
Thread snmpagentthread;
@PostConstruct
public void onStartup() {
File bootCounterFile = null; File configfile = null;
try {
snmpAgentConsumerThread = new TestAgentWithRunThread(bootCounterFile, configfile);
} catch (IOException e) {
// TODO Auto-generated catch block
}
snmpagentthread = new Thread(snmpAgentConsumerThread, "snmpAgentThread");
snmpagentthread.start(); //<<<<--Starting thread
}
//Below is the code snippet of my agent implementation
public class TestAgentWithRunThread extends BaseAgent implements Runnable{
protected String address;
private Snmp4jHeartbeatMib heartbeatMIB;
private AgentppSimulationMib agentppSimulationMIB;
private Snmp4jDemoMib snmp4jDemoMib;
private SortedMap<OID, List> sparseTableData = new TreeMap<OID, List>();
private static String cAGENTIP=“”;
private static String cSNMPPORT=“20100”;
private static String cSNMPSECLEVEL=“AuthNoPriv”;
private static String cSNMPUSERNAME=“authUser”;
private static String cSNMPAUTHPROTOCOL=“MD5”;
private static String cSNMPAUTHPASSWD=“authUser”;
private static String cSNMPCONTEXTNAME=“auth”;
private static String cENGINEID=“”;
private static int mysecuritylevel=SecurityLevel.AUTH_NOPRIV; //Default
/**
- Creates the test agent with a file to read and store the boot counter and
- a file to read and store its configuration.
- @param bootCounterFile
- a file containing the boot counter in serialized form (as expected by
- BaseAgent).
- @param configFile
- a configuration file with serialized management information.
- @throws IOException
- if the boot counter or config file cannot be read properly.
*/
public TestAgentWithRunThread(File bootCounterFile, File configFile) throws IOException {
super(bootCounterFile, configFile,
new CommandProcessor(new OctetString(OctetString.fromHexString(cENGINEID, ‘:’))));
agent.setWorkerPool(ThreadPool.create("RequestPool", 4));
// Uncomment the following if you want to use AES 192 or 256 with 3DES like key extension.
SecurityProtocols.getInstance().addPrivacyProtocol(new PrivAES256With3DESKeyExtension());
}
protected void registerManagedObjects() {
try {
// server.register(createStaticIfTable(), null);
agentppSimulationMIB.registerMOs(server, null);
heartbeatMIB.registerMOs(server, null);
snmp4jDemoMib.registerMOs(server, null);
}
catch (DuplicateRegistrationException ex) {
ex.printStackTrace();
}
}
protected void addNotificationTargets(SnmpTargetMIB targetMIB,
SnmpNotificationMIB notificationMIB) {
targetMIB.addDefaultTDomains();
targetMIB.addTargetAddress(new OctetString("notificationV2c"),
TransportDomains.transportDomainUdpIpv4,
new OctetString(new UdpAddress("127.0.0.1/162").getValue()),
200, 1,
new OctetString("notify"),
new OctetString("v2c"),
StorageType.permanent);
targetMIB.addTargetAddress(new OctetString("notificationV3"),
TransportDomains.transportDomainUdpIpv4,
new OctetString(new UdpAddress("127.0.0.1/1162").getValue()),
200, 1,
new OctetString("notify"),
new OctetString("v3notify"),
StorageType.permanent);
targetMIB.addTargetParams(new OctetString("v2c"),
MessageProcessingModel.MPv2c,
SecurityModel.SECURITY_MODEL_SNMPv2c,
new OctetString("cpublic"),
SecurityLevel.AUTH_PRIV,
StorageType.permanent);
targetMIB.addTargetParams(new OctetString("v3notify"),
MessageProcessingModel.MPv3,
SecurityModel.SECURITY_MODEL_USM,
new OctetString("v3notify"),
SecurityLevel.NOAUTH_NOPRIV,
StorageType.permanent);
notificationMIB.addNotifyEntry(new OctetString("default"),
new OctetString("notify"),
SnmpNotificationMIB.SnmpNotifyTypeEnum.inform,
StorageType.permanent);
}
protected void addViews(VacmMIB vacm) {
vacm.addGroup(SecurityModel.SECURITY_MODEL_SNMPv1,
new OctetString(“cpublic”),
new OctetString(“v1v2group”),
StorageType.nonVolatile);
vacm.addGroup(SecurityModel.SECURITY_MODEL_SNMPv2c,
new OctetString(“cpublic”),
new OctetString(“v1v2group”),
StorageType.nonVolatile);
vacm.addGroup(SecurityModel.SECURITY_MODEL_USM,
new OctetString(“MD5DES”),
new OctetString(“v3group”),
StorageType.nonVolatile);
vacm.addGroup(SecurityModel.SECURITY_MODEL_USM,
new OctetString(cSNMPUSERNAME),
new OctetString(“v3group”),
StorageType.nonVolatile);
vacm.addGroup(SecurityModel.SECURITY_MODEL_USM,
new OctetString("v3notify"),
new OctetString("v3group"),
StorageType.nonVolatile);
vacm.addAccess(new OctetString("v1v2group"), new OctetString("public"),
SecurityModel.SECURITY_MODEL_ANY,
SecurityLevel.NOAUTH_NOPRIV,
MutableVACM.VACM_MATCH_EXACT,
new OctetString("fullReadView"),
new OctetString("fullWriteView"),
new OctetString("fullNotifyView"),
StorageType.nonVolatile);
vacm.addAccess(new OctetString("v3group"), new OctetString(cSNMPCONTEXTNAME),
SecurityModel.SECURITY_MODEL_USM,
mysecuritylevel,
MutableVACM.VACM_MATCH_EXACT,
new OctetString("fullReadView"),
new OctetString("fullWriteView"),
new OctetString("fullNotifyView"),
StorageType.nonVolatile);
vacm.addViewTreeFamily(new OctetString("fullReadView"), new OID("1.3"),
new OctetString(), VacmMIB.vacmViewIncluded,
StorageType.nonVolatile);
vacm.addViewTreeFamily(new OctetString("fullWriteView"), new OID("1.3"),
new OctetString(), VacmMIB.vacmViewIncluded,
StorageType.nonVolatile);
vacm.addViewTreeFamily(new OctetString("fullNotifyView"), new OID("1.3"),
new OctetString(), VacmMIB.vacmViewIncluded,
StorageType.nonVolatile);
}
protected void addUsmUser(USM usm) {
usm.setEngineDiscoveryEnabled(true);
UsmUser user = new UsmUser(new OctetString(“MD5DES”),
AuthMD5.ID,
new OctetString(“MD5DESAuthPassword”),
PrivDES.ID,
new OctetString(“MD5DESPrivPassword”));
usm.addUser(user.getSecurityName(), usm.getLocalEngineID(), user);
user = new UsmUser(new OctetString(cSNMPUSERNAME),
AuthMD5.ID,
new OctetString(cSNMPAUTHPASSWD),
PrivDES.ID,
new OctetString(cSNMPAUTHPASSWD));
usm.addUser(user.getSecurityName(), usm.getLocalEngineID(), user);
usm.getUserTable();
user = new UsmUser(new OctetString("v3notify"),
null,
null,
null,
null);
usm.addUser(user.getSecurityName(), null, user);
}
protected void initTransportMappings() throws IOException {
transportMappings = new TransportMapping<?>[1];
Address addr = GenericAddress.parse(address);
TransportMapping<? extends Address> tm =
TransportMappings.getInstance().createTransportMapping(addr);
transportMappings[0] = tm;
}
@Override
public void run() {
//LogFactory.setLogFactory(new ConsoleLogFactory());
//ConsoleLogAdapter.setDebugEnabled(true);
// readServerinfo();
cAGENTIP="182.4.1.221";
cSNMPPORT="20100";
cSNMPSECLEVEL="AuthNoPriv";
cSNMPUSERNAME="myUser";
cSNMPAUTHPROTOCOL="MD5";
cSNMPAUTHPASSWD="myUser";
cSNMPCONTEXTNAME="auth";
cENGINEID="31:36:38:2e:34:2e:38:35:23:32:30:31:30:30";
if(cSNMPSECLEVEL.equalsIgnoreCase("NoAuthNoPriv"))
{
mysecuritylevel = SecurityLevel.NOAUTH_NOPRIV;
}
if(cSNMPSECLEVEL.equalsIgnoreCase("AuthNoPriv"))
{
mysecuritylevel = SecurityLevel.AUTH_NOPRIV;
}
if(cSNMPSECLEVEL.equalsIgnoreCase("AuthPriv"))
{
mysecuritylevel = SecurityLevel.AUTH_PRIV;
}
String address;
address = cAGENTIP+"/"+cSNMPPORT;
BasicConfigurator.configure();
try {
TestAgentWithRunThread testAgent1 = new TestAgentWithRunThread(new File("BC.cfg"),
new File("AgentConfig.cfg"));
testAgent1.address = address;
testAgent1.init();
testAgent1.loadConfig(ImportModes.REPLACE_CREATE);
testAgent1.addShutdownHook();
testAgent1.getServer().addContext(new OctetString(cSNMPCONTEXTNAME));
testAgent1.finishInit();
testAgent1.running();
testAgent1.sendColdStartNotification();
while (true) {
try {
Thread.sleep(1);
//LOGGER.log(Level.DEBUG, "TestAgent.main() sleep");
//myprintf();
}
catch (InterruptedException ex1) {
break;
}
}
}
catch (IOException ex) {
ex.printStackTrace();
}
}
protected void unregisterManagedObjects() {
// here we should unregister those objects previously registered…
}
protected void addCommunities(SnmpCommunityMIB communityMIB) {
Variable[] com2sec = new Variable[] {
new OctetString(cSNMPCONTEXTNAME), // community name
new OctetString(“cpublic”), // security name
getAgent().getContextEngineID(), // local engine ID
new OctetString(cSNMPCONTEXTNAME), // default context name
new OctetString(), // transport tag
new Integer32(StorageType.nonVolatile), // storage type
new Integer32(RowStatus.active) // row status
};
SnmpCommunityMIB.SnmpCommunityEntryRow row =
communityMIB.getSnmpCommunityEntry().createRow(
new OctetString(“public2public”).toSubIndex(true), com2sec);
communityMIB.getSnmpCommunityEntry().addRow(row);
// snmpCommunityMIB.setSourceAddressFiltering(true);
}
protected void registerSnmpMIBs() {
heartbeatMIB = new Snmp4jHeartbeatMib(super.getNotificationOriginator(),
new OctetString(),
super.snmpv2MIB.getSysUpTime());
agentppSimulationMIB = new AgentppSimulationMib();
snmp4jDemoMib = new Snmp4jDemoMib(DefaultMOFactory.getInstance());
/*
*/
super.registerSnmpMIBs();
}
}