You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

This page describes how the SNMP4J-Agent MOFactory concept can be used to apply customised columnar objects to SNMP table implementations.

Step-by-step guide

This guide assumes that you have generated your MIB instrumentation code with AgenPro, but you can do the same with manual written code too.

  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):

      @SuppressWarnings(value={"unchecked"})
      private void createSnmp4jAgentTutorialFileTreeEUEntry(MOFactory moFactory) {
        // Index definition
        snmp4jAgentTutorialFileTreeEUEntryIndexes = 
          new MOTableSubIndex[] {
          moFactory.createSubIndex(oidSnmp4jAgentTutorialFileTreeEUIndex, 
                                   SMIConstants.SYNTAX_OBJECT_IDENTIFIER, 0, 128)    };
        snmp4jAgentTutorialFileTreeEUEntryIndex = 
          moFactory.createIndex(snmp4jAgentTutorialFileTreeEUEntryIndexes,
                                false,
                                new MOTableIndexValidator() {
          public boolean isValidIndex(OID index) {
            boolean isValidIndex = true;
         //--AgentGen BEGIN=snmp4jAgentTutorialFileTreeEUEntry::isValidIndex
         //--AgentGen END
            return isValidIndex;
          }
        });
        // Columns
        MOColumn[] snmp4jAgentTutorialFileTreeEUEntryColumns = new MOColumn[10];
        snmp4jAgentTutorialFileTreeEUEntryColumns[idxSnmp4jAgentTutorialFileTreeEUPath] = 
          moFactory.createColumn(colSnmp4jAgentTutorialFileTreeEUPath, 
                                 SMIConstants.SYNTAX_OCTET_STRING,
                                 moFactory.createAccess(MOAccessImpl.ACCESSIBLE_FOR_READ_ONLY),
                                 tcModuleSNMPv2Tc,
                                 tcDefDisplayString);
        snmp4jAgentTutorialFileTreeEUEntryColumns[idxSnmp4jAgentTutorialFileTreeEUType] = 
          moFactory.createColumn(colSnmp4jAgentTutorialFileTreeEUType, 
                                 SMIConstants.SYNTAX_INTEGER,
                                 moFactory.createAccess(MOAccessImpl.ACCESSIBLE_FOR_READ_ONLY));
        snmp4jAgentTutorialFileTreeEUEntryColumns[idxSnmp4jAgentTutorialFileTreeEUCreationTime] = 
          moFactory.createColumn(colSnmp4jAgentTutorialFileTreeEUCreationTime, 
                                 SMIConstants.SYNTAX_OCTET_STRING,
                                 moFactory.createAccess(MOAccessImpl.ACCESSIBLE_FOR_READ_ONLY),
                                 tcModuleSNMPv2Tc,
                                 tcDefDateAndTime);
        snmp4jAgentTutorialFileTreeEUEntryColumns[idxSnmp4jAgentTutorialFileTreeEULastModified] = 
          moFactory.createColumn(colSnmp4jAgentTutorialFileTreeEULastModified, 
                                 SMIConstants.SYNTAX_OCTET_STRING,
                                 moFactory.createAccess(MOAccessImpl.ACCESSIBLE_FOR_READ_ONLY),
                                 tcModuleSNMPv2Tc,
                                 tcDefDateAndTime);
        snmp4jAgentTutorialFileTreeEUEntryColumns[idxSnmp4jAgentTutorialFileTreeEULastAccessed] = 
    moFactory.createColumn(colSnmp4jAgentTutorialFileTreeEULastAccessed, 
                                 SMIConstants.SYNTAX_OCTET_STRING,
                                 moFactory.createAccess(MOAccessImpl.ACCESSIBLE_FOR_READ_ONLY),
                                 tcModuleSNMPv2Tc,
                                 tcDefDateAndTime);
        snmp4jAgentTutorialFileTreeEUEntryColumns[idxSnmp4jAgentTutorialFileTreeEUSizeInBytes] = 
    moFactory.createColumn(colSnmp4jAgentTutorialFileTreeEUSizeInBytes, 
                                 SMIConstants.SYNTAX_GAUGE32,
                                 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:

    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())) {
        					...
      					}
    				}
    }
    }
    
    
    }

 

  • No labels