Thank you Frank, I had a problem with my agent…
Last question, I am extending BaseAgent for my agent. Currently, I register my MO with : agent.registerManagedObject(new MOScalar(…)); (I am working with snmp v2 this time)
Now, I would like to return a custom dynamic PDU response according to the incoming request
I have seen this post on stackoverflow : java - How to register a listener on a OID / Managed Object using SNMP4J to act on set or get requests the agent receives? - Stack Overflow
But since I am using BaseAgent and not the AgentConfigManager, I don’t know where I can add the
server.addLookupListener(…) in my manager ?
My current manager looks like :
public class SNMPAgent extends BaseAgent {
private String address;
public SNMPAgent(String address) throws IOException {
super(new File("conf.agent"), new File("bootCounter.agent"),
new CommandProcessor(
new OctetString(MPv3.createLocalEngineID())));
this.address = address;
}
@Override
protected void registerManagedObjects() {
}
public void registerManagedObject(ManagedObject mo) {
try {
server.register(mo, null);
} catch (DuplicateRegistrationException ex) {
throw new RuntimeException(ex);
}
**// Maybe call server.addLookupListener(...,mo) here ?**
}
public void unregisterManagedObject(MOGroup moGroup) {
moGroup.unregisterMOs(server, getContext(moGroup));
}
@Override
protected void addNotificationTargets(SnmpTargetMIB targetMIB,
SnmpNotificationMIB notificationMIB) {
}
@Override
protected void addViews(VacmMIB vacm) {
vacm.addGroup(SecurityModel.SECURITY_MODEL_SNMPv2c, new OctetString(
"cpublic"), new OctetString("v1v2group"),
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.addViewTreeFamily(new OctetString("fullReadView"), new OID("1.3"),
new OctetString(), VacmMIB.vacmViewIncluded,
StorageType.nonVolatile);
}
@Override
protected void addUsmUser(USM usm) {
}
@Override
protected void initTransportMappings() throws IOException {
transportMappings = new TransportMapping[1];
Address addr = GenericAddress.parse(address);
TransportMapping tm = TransportMappings.getInstance()
.createTransportMapping(addr);
transportMappings[0] = tm;
}
public void start() throws IOException {
init();
// This method reads some old config from a file and causes
// unexpected behavior.
// loadConfig(ImportModes.REPLACE_CREATE);
addShutdownHook();
getServer().addContext(new OctetString("public"));
finishInit();
run();
sendColdStartNotification();
}
@Override
protected void unregisterManagedObjects() {
// here we should unregister those objects previously registered...
}
@Override
protected void addCommunities(SnmpCommunityMIB communityMIB) {
Variable[] com2sec = new Variable[] { new OctetString("public"), // community
// name
new OctetString("cpublic"), // security name
getAgent().getContextEngineID(), // local engine ID
new OctetString("public"), // default context name
new OctetString(), // transport tag
new Integer32(StorageType.nonVolatile), // storage type
new Integer32(RowStatus.active) // row status
};
MOTableRow row = communityMIB.getSnmpCommunityEntry().createRow(
new OctetString("public2public").toSubIndex(true), com2sec);
communityMIB.getSnmpCommunityEntry().addRow(row);
}
}
Thank you !!