How to add managers (trap destination) via code.

I’m facing a little problem sending traps with snmp4j,

Right now my “trap-sending” section is like this:

 String pos = "."+Integer.toString(modules.getBaseMib().addTowerAlarm(ta)); //gets the index (row number)
        if(pos.contains("-2")) return;   // on error get out
        if(pos.contains("-1")) return;   // on delete get out

        VariableBinding vbs[] = {
                new VariableBinding(),
                new VariableBinding(),
                new VariableBinding()

        OID oCode           = new OID(BaseMib.oidCTowerAlarmCode.toString() +pos); //in coda aggiungo l-oid della riga
        OID oSeverity       = new OID(BaseMib.oidTrapVarCTowerPerceivedSeverity.toString()+pos);
        OID oTimestamp  = new OID(BaseMib.oidTrapVarCTowerAlarmTimeStamp.toString()+pos);

        vbs[0].setVariable(new Integer32(ta.getAlarmCode())); 

        vbs[1].setVariable(new Integer32(ta.getSeverityAsInt()));
        vbs[2].setVariable( new OctetString(ta.getTimeStamp().toString()) ); 

                 new OctetString("other"),


But once executed it throws errors like this:

Exception in thread "Thread-0" java.lang.IllegalArgumentException: Illegal index for variable 0 (cTowerAlarmCode)) specified: 1

Also where I have to add the addresses of managers to whom I have to send the traps?
NOTE: The code was generated by agenpro

The error message is generated by the AgenPro generated validation code that should help you to conform to the SNMP standard rules. You have specified a row index that cannot exist due to the MIB definition you are using.

To change the targets of your traps, please configure the SNMPv3 standard MIB SNMP-TARGET-MIB (SnmpTargetMIB) in conjunction with the SNMP-NOTIFICATION-MIB (SnmpNotificationMIB).

1 Like