Versions Compared

Key

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

...

  1. Generate the MIB module instrumentation code with AgenPro and activate factoryColumn property (set its value to yes) for your entire MIB module (or all affected tables). This will create the code to create MOColumn instances for read-only columns using the MOFactory provided to your MIB module.
    This step is important, because we will create our own MOFactory implementation to create our own MOColumn subclasses. 
    The generated code for each table will look like (sample taken from the NotificationLogMib.java):

    Code Block
    languagejava
      @SuppressWarnings(value={"unchecked"})
      private void createNlmConfigLogEntrycreateSnmp4jAgentTutorialFileTreeEUEntry(MOFactory moFactory) {
        // Index definition
        nlmConfigLogEntryIndexessnmp4jAgentTutorialFileTreeEUEntryIndexes = 
          new MOTableSubIndex[] {
          moFactory.createSubIndex(oidNlmLogNameoidSnmp4jAgentTutorialFileTreeEUIndex, 
                                   SMIConstants.SYNTAX_OCTETOBJECT_STRINGIDENTIFIER, 0, 32128)
        };
    
        nlmConfigLogEntryIndexsnmp4jAgentTutorialFileTreeEUEntryIndex = 
          moFactory.createIndex(nlmConfigLogEntryIndexessnmp4jAgentTutorialFileTreeEUEntryIndexes,
                                false,
                                new MOTableIndexValidator() {
          public boolean isValidIndex(OID index) {
            boolean isValidIndex = true;
         //--AgentGen BEGIN=snmp4jAgentTutorialFileTreeEUEntry::isValidIndex
         //--AgentGen END
            return isValidIndex;
          }
        });
        // Columns
        MOColumn[] nlmConfigLogEntryColumnssnmp4jAgentTutorialFileTreeEUEntryColumns = new MOColumn[610];
        nlmConfigLogEntryColumnssnmp4jAgentTutorialFileTreeEUEntryColumns[idxNlmConfigLogFilterNameidxSnmp4jAgentTutorialFileTreeEUPath] = 
         new MOMutableColumnmoFactory.createColumn(colNlmConfigLogFilterNamecolSnmp4jAgentTutorialFileTreeEUPath, 
                                 SMIConstants.SYNTAX_OCTET_STRING,
                                 moFactory.createAccess(MOAccessImpl.ACCESSIBLE_FOR_READ_CREATEONLY),
                            new OctetString(new byte[] {  }));tcModuleSNMPv2Tc,
      ValueConstraint nlmConfigLogFilterNameVC = new ConstraintsImpl();
      ((ConstraintsImpl)nlmConfigLogFilterNameVC).add(new Constraint(0L, 32L));
      ((MOMutableColumn)nlmConfigLogEntryColumns[idxNlmConfigLogFilterName]).
        addMOValueValidationListener(new ValueConstraintValidator(nlmConfigLogFilterNameVC));
      ((MOMutableColumn)nlmConfigLogEntryColumns[idxNlmConfigLogFilterName]).
        addMOValueValidationListener(new NlmConfigLogFilterNameValidator(                           tcDefDisplayString);
        snmp4jAgentTutorialFileTreeEUEntryColumns[idxSnmp4jAgentTutorialFileTreeEUType] = 
          moFactory.createColumn(colSnmp4jAgentTutorialFileTreeEUType, 
                                 SMIConstants.SYNTAX_INTEGER,
                                 moFactory.createAccess(MOAccessImpl.ACCESSIBLE_FOR_READ_ONLY));
      nlmConfigLogEntryColumns  snmp4jAgentTutorialFileTreeEUEntryColumns[idxNlmConfigLogEntryLimitidxSnmp4jAgentTutorialFileTreeEUCreationTime] = 
         new MOMutableColumnmoFactory.createColumn(colNlmConfigLogEntryLimitcolSnmp4jAgentTutorialFileTreeEUCreationTime, 
                                 SMIConstants.SYNTAX_OCTET_GAUGE32STRING,
                                 moFactory.createAccess(MOAccessImpl.ACCESSIBLE_FOR_READ_CREATE),
    ONLY),
                                 tcModuleSNMPv2Tc,
                                new UnsignedInteger32(0)tcDefDateAndTime);
      nlmConfigLogEntryColumns  snmp4jAgentTutorialFileTreeEUEntryColumns[idxNlmConfigLogAdminStatusidxSnmp4jAgentTutorialFileTreeEULastModified] = 
         new Enumerated<Integer32>moFactory.createColumn(colNlmConfigLogAdminStatuscolSnmp4jAgentTutorialFileTreeEULastModified, 
                                 SMIConstants.SYNTAX_OCTET_INTEGER32STRING,
                                 moFactory.createAccess(MOAccessImpl.ACCESSIBLE_FOR_READ_CREATEONLY),
                                 tcModuleSNMPv2Tc,
                new Integer32(1)                 tcDefDateAndTime);
       ValueConstraint nlmConfigLogAdminStatusVCsnmp4jAgentTutorialFileTreeEUEntryColumns[idxSnmp4jAgentTutorialFileTreeEULastAccessed] = new EnumerationConstraint(
    
    moFactory.createColumn(colSnmp4jAgentTutorialFileTreeEULastAccessed, 
               new int[] { NlmConfigLogAdminStatusEnum.enabled,
                      SMIConstants.SYNTAX_OCTET_STRING,
                       NlmConfigLogAdminStatusEnum.disabled });
      ((MOMutableColumn)nlmConfigLogEntryColumns[idxNlmConfigLogAdminStatus]).
        addMOValueValidationListener(new ValueConstraintValidator(nlmConfigLogAdminStatusVC));
      nlmConfigLogEntryColumns[idxNlmConfigLogOperStatus] =
        moFactory.createColumn(colNlmConfigLogOperStatus,
              moFactory.createAccess(MOAccessImpl.ACCESSIBLE_FOR_READ_ONLY),
                                 tcModuleSNMPv2Tc,
                                 tcDefDateAndTime);
        snmp4jAgentTutorialFileTreeEUEntryColumns[idxSnmp4jAgentTutorialFileTreeEUSizeInBytes] = 
    moFactory.createColumn(colSnmp4jAgentTutorialFileTreeEUSizeInBytes, 
                                 SMIConstants.SYNTAX_INTEGERGAUGE32,
                                 moFactory.createAccess(MOAccessImpl.ACCESSIBLE_FOR_READ_ONLY));
    
    ...
    }
  2. As you can see in the above code, the moFactory member of the generated MIB module class is used to create the actual MOColumn instances. To create our custom MOColumn instances we need our own MOFactory instance first:

    Code Block
    languagejava
    myMOFactory = new DefaultMOFactory() {
     
    	@Override
    	public <V extends Variable> MOColumn<V> createColumn(int columnID, int syntax, MOAccess access,
                                                         V defaultValue, boolean mutableInService) {
      		return new MOMutableColumn<V>(columnID, syntax, access, defaultValue, mutableInService) {
    			@Override
    			public V getValue(MOTableRow row, int column, SubRequest subRequest) {
    				if (subRequest.getScope() instanceof MOContextScope) {
    					MOContextScope moContextScope = (MOContextScope)subRequest.getScope();
      					if ("myContext".equals(moContextScope.getContext())) {
        					...
      					}
    				}
    }
    }
    
    
    }

 

Content by Label
showLabelsfalse
max5
spacesSNMP4J
sortmodified
showSpacefalse
reversetrue
typepage
labelsMOTable MOColumn MOFactory custom column table

...