2013-01-21 130 views
1

V3陷阱3DES,AES192和AES256使用SNMP4J創建陷阱發送發送失敗privProtocol 。發生異常如下:SNMPv3陷阱發送問題

org.snmp4j.MessageException: Message processing model 3 returned error: Unsupported security level 
at org.snmp4j.MessageDispatcherImpl.sendPdu(MessageDispatcherImpl.java:501) 
at org.snmp4j.Snmp.sendMessage(Snmp.java:1005) 
at org.snmp4j.Snmp.send(Snmp.java:885) 
at org.snmp4j.Snmp.send(Snmp.java:878) 
at org.snmp4j.Snmp.send(Snmp.java:843) 

相同的代碼適用於privProtocol DES和AES128以及所有authProtocol。

的代碼如下:

USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(
       MPv3.createLocalEngineID()),0); 
     SecurityModels.getInstance().addSecurityModel(usm); 
     Snmp snmp = new Snmp(transport); 

     //Creating USM user according to Security level 

     //Security Level: noAuthNoPriv 
     if(trapDetails.getSecurityLevel()==1){ 
      snmp.getUSM().addUser(
        new OctetString(trapDetails.getUserName()), 
        new UsmUser(new OctetString(trapDetails.getUserName()), null, null, 
          null,null)); 
      } 

     //Security Level:AuthNoPriv 
     if(trapDetails.getSecurityLevel()==2){ 
      snmp.getUSM().addUser(
        new OctetString(trapDetails.getUserName()), 
        new UsmUser(new OctetString(trapDetails.getUserName()), new OID(
          trapDetails.getAuthProtocol()), new OctetString(trapDetails.getAuthPassword()), 
          null,null)); 
      } 

     //Security Level:AuthPriv 
     if(trapDetails.getSecurityLevel()==3){ 
     snmp.getUSM().addUser(
       new OctetString(trapDetails.getUserName()), 
       new UsmUser(new OctetString(trapDetails.getUserName()), new OID(
         trapDetails.getAuthProtocol()), new OctetString(trapDetails.getAuthPassword()), 
         new OID (trapDetails.getPrivProtocol()),new OctetString(trapDetails.getPrivPassword()))); 
     } 

.........

//Creating PDU 

     ScopedPDU pdu= new ScopedPDU(); 
     pdu.setType(PDU.NOTIFICATION); 
     pdu.setRequestID(new Integer32(200)); 
     pdu.setErrorIndex(0); 
     pdu.setErrorStatus(SnmpConstants.SNMP_ERROR_BAD_VALUE); 
     pdu.add(new VariableBinding(SnmpConstants.sysUpTime,new TimeTicks(255))); 
     pdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, new OID(trapDetails 
       .getTrapOID()))); 
     pdu.add(new VariableBinding(SnmpConstants.snmpTrapEnterprise,new OID(SnmpConstants.snmpTrapEnterprise))); 



//Creating target to send trap 

     UserTarget uTarget= new UserTarget(); 
     ArrayList<String> destinationList = new ArrayList<String>(trapDetails.getDestinationIP()); 
     Iterator<String> itr= destinationList.iterator(); 
     String element; 
     while(itr.hasNext()){ 
     uTarget = new UserTarget(); 
     element= itr.next().toString(); 
     uTarget.setAddress(new UdpAddress(InetAddress.getByName(element),trapDetails.getPort())); 
     uTarget.setRetries(2); 
     uTarget.setTimeout(5000); 
     uTarget.setVersion(SnmpConstants.version3); 
     uTarget.setSecurityLevel(trapDetails.getSecurityLevel()); 
     uTarget.setSecurityName(new OctetString(trapDetails.getUserName())); 
     snmp.send(pdu, uTarget); 

     } 
+0

如果您不共享導致異常的代碼,將很難爲您提供幫助。 – Oren

回答