[SNMP4J] TestAgent property file

Eugene R. Snider gene at cvtt.net
Tue Aug 5 03:54:40 CEST 2008


Jeff,

In my recent UDP agent release I set the community name with the 
following code that seems to work okay. I believe I did a copy and 
modify on the code of the most excellent SNMP4J test agent.

It's best  to keep in mind when working with SNMP4J that V1 and V2C are 
supported but in the context of V3. In particular many folks have had 
problems with v2c notifications and I wrote a V2CNotifier class for the 
UDP agent.

Gene

In the main routine of the SNMP agent I use this call ( after reading 
the default context from the preferences ).

snmpDefaultContext = Activator.getDefault().getPreferenceStore()
        .getString(PreferenceConstants.P_DEFAULT_CONTEXT);
        if (snmpDefaultContext == null) {
            snmpDefaultContext = Activator.getDefault().getPreferenceStore()
                    
.getDefaultString(PreferenceConstants.P_DEFAULT_CONTEXT);
        }

blah, blah, blah...

 testAgent1.getServer().addContext(new OctetString(snmpDefaultContext));


I also use it in addCommunities where it seems to work okay:

  protected void addCommunities(SnmpCommunityMIB communityMIB) {
        Variable[] com2sec = new Variable[] { new 
OctetString(snmpDefaultContext), // community
                // name
                new OctetString("cpublic"), // security name
                getAgent().getContextEngineID(), // local engine ID
                new OctetString(snmpDefaultContext), // 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);
        // snmpCommunityMIB.setSourceAddressFiltering(true);
        /*
         * CommunityTarget target = new CommunityTarget();
         * target.setCommunity(new OctetString(snmpDefaultContext)); 
target.setAddress(new
         * UdpAddress(trapDestination.toString() + "/" + 
trapDestinationPort));
         * target.setVersion(SnmpConstants.version2c);
         */
    }





More information about the SNMP4J mailing list