Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  1. Let AgenPro generate the MIB object stub and agent main code as described in: Generate code for SNMP4J-Agent with AgenPro.
  2. Edit the Agent.java file (or modify the AgenPro template) as follows:
    1. Define the context values you want to support in the agent:

      Code Block
      languagejava
      //|:AgenPro|=members
      OctetString context1 = new OctetString("ctx1");
      OctetString context2 = new OctetString("ctx2");
      //|AgenPro:|
    2. Add the contexts to the MOServer instance(s) you use in the agent:

      Code Block
      languagejava
      public static void main(String[] args) {
         //|:AgenPro|=main
         server.addContext(context1);
         server.addContext(context2);
         defaultMain(args);
         //|AgenPro:|
      }
      
      
    3. Register your MIB object instances for each context separately (as explained above in the Background section):

      Code Block
      languagejava
        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.registerregisterMOs(server, context1);
           	Snmp4jAgentTutorialMib tutorialMibCtx2 = new Snmp4jAgentTutorialMib(getFactory()); 
           	tutorialMibCtx2.registerregisterMOs(server, context2);
           } catch (DuplicateRegistrationException drex) {
        	logger.error("Duplicate registration: "+drex.getMessage()+"."+
                     " MIB object registration may be incomplete!", drex);
           }
      //|AgenPro:|
        ..
      }
  3. 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
    languagejava
      protected void registerMIBs()
      {
       ..
    //|:AgenPro|=registerAfter
         VacmMIB vacm = agent.getAgentConfigManager().getVacmMIB();
         vacm.addAccess(new OctetString("v3group"), context1,
                   SecurityModel.SECURITY_MODEL_ANY,
                   SecurityLevel.AUTH_PRIV,
                   MutableVACM.VACM_MATCH_EXACT,
                   new OctetString("fullReadView"),
                   new OctetString("fullWriteView"),
                   new OctetString("fullNotifyView"),
                   StorageType.nonVolatile);
         vacm.addAccess(new OctetString("v3group"), context2,
                   SecurityModel.SECURITY_MODEL_ANY,
                   SecurityLevel.AUTH_PRIV,
                   MutableVACM.VACM_MATCH_EXACT,
                   new OctetString("fullReadView"),
                   new OctetString("fullWriteView"),
                   new OctetString("fullNotifyView"),
                   StorageType.nonVolatile);
         ..
    //|AgenPro:|

...