...
For each context create a separate
ManagedObject
instance and register it with the target context usingMOServer.register
.Code Block language java MOScalar myScalarObjAContext1 = new MyScalarObjA(..); MOScalar myScalarObjAContext2 = new MyScalarObjA(..); MOServer server = ..; server.register(myScalarObjAContext1, new OctetString("context1")); server.register(myScalarObjAContext2, new OctetString("context2"));
Use the same
ManagedObject
instance for all target contexts by callingMOServer.register
repeatedly for each context with the same instance. The single instance is then responsible to deliver and update its content (MIB data) based on the context information given in theManagedObject.get
,.next
,.prepare
,.commit
,.undo
, and.cleanup
SubRequest
parameter in theMOScope
(in fact it is then aMOContextScope
) member.Code Block language java OctetString context1 = new OctetString("context1"); OctetString context2 = new OctetString("context2"); MOScalar myScalarObjA = new MyScalarObjA(..) { public void get(SubRequest request) { if (request.gewtScopegetScope() instanceof MOContextScope) { MOContextScope scope = (MOContextScope)request.gewtScopegetScope(); if (context1.equals(scope.getContext()) { // return value from context1 .. } else if (context2.equals(scope.getContext()) { // return value from context2 .. } else { // cannot be reached } } } } MOServer server = ..; server.register(myScalarObjA, context1); server.register(myScalarObjA, context2));
- Any combination of the above two approaches will work too.
...
- Let AgenPro generate the MIB object stub and agent main code as described in: Generate code for SNMP4J-Agent with AgenPro.
- Edit the Agent.java file (or modify the AgenPro template) as follows:
Define the context values you want to support in the agent:
Code Block language java //|:AgenPro|=members OctetString context1 = new OctetString("ctx1"); OctetString context2 = new OctetString("ctx2"); //|AgenPro:|
Add the contexts to the MOServer instance(s) you use in the agent:
Code Block language java public static void main(String[] args) { //|:AgenPro|=main server.addContext(context1); server.addContext(context2); defaultMain(args); //|AgenPro:| }
Register your MIB object instances for each context separately (as explained above in the Background section):
Code Block language java protected void registerMIBs() { //|:AgenPro|=registerBefore try { // Create a new instance per generated MIB module (you can use different MOFactory instances per context if needed): Snmp4jAgentTutorialMib tutorialMibCtx1 = new Snmp4jAgentTutorialMib(getFactory()); tutorialMibCtx1.registerMOs(server, context1); Snmp4jAgentTutorialMib tutorialMibCtx2 = new Snmp4jAgentTutorialMib(getFactory()); tutorialMibCtx2.registerMOs(server, context2); } catch (DuplicateRegistrationException drex) { logger.error("Duplicate registration: "+drex.getMessage()+"."+ " MIB object registration may be incomplete!", drex); } //|AgenPro:| .. }
Configure the SNMPv3 View-based Access Control Model (VACM) MIB to allow SNMPv3 (and/or SNMPv1/2vc) users to access the new non-default contexts:
Code Block language java public void run() { // initialize agent before registering our own modules agent.initialize(); // this requires sysUpTime to be protectedavailable. void registerMIBs(); {// add proxy forwarder agent.setupProxyForwarder(); // now continue agent setup and launch it. agent.run(); //|:AgenPro|=registerAfterrun VacmMIB vacm = agent.getAgentConfigManager().getVacmMIB(); vacm.addAccess(new OctetString("v3group"), context1, SecurityModel.SECURITY_MODEL_ANY, SecurityLevel.AUTH_PRIV, MutableVACM.VACM_MATCH_EXACT, new OctetString("fullReadViewunrestrictedReadView"), new OctetString("fullWriteViewunrestrictedWriteView"), new OctetString("fullNotifyViewunrestrictedNotifyView"), StorageType.nonVolatile); vacm.addAccess(new OctetString("v3group"), context2, SecurityModel.SECURITY_MODEL_ANY, SecurityLevel.AUTH_PRIV, MutableVACM.VACM_MATCH_EXACT, new OctetString("fullReadViewunrestrictedReadView"), new OctetString("fullWriteViewunrestrictedWriteView"), new OctetString("fullNotifyViewunrestrictedNotifyView"), StorageType.nonVolatile); .. //|AgenPro:| }
Related articles
Content by Label | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
...