2014-01-15 44 views
0

我的問題是此snmp4j陷阱發送者的警告日誌級別作爲次級日誌級別收到,但我需要收到警告日誌級別的消息,如果我要使用coldstart或warnstart pdu通知,任何人都可以幫助這個錯誤?snmp4j警告日誌級別

public TrapSenderVersion2(String trapIpDestination, int trapPort, 
      String message) { 
     try { 
      String aMessage = message; 
      // Create PDU 
      PDU trap = new PDU(); 
      trap.setType(PDU.NOTIFICATION); 
      // trap.setType(PDU.REPORT); 

      String baseString = ".1.3.6.1.4.1.6400."; 

      OID oid = new OID(baseString); 
      trap.add(new VariableBinding(SnmpConstants.sysUpTime, 
        new TimeTicks(5000))); // put your uptime here 
      trap.add(new VariableBinding(SnmpConstants.snmpTrapOID, 
        SnmpConstants.coldStart)); 
      trap.add(new VariableBinding(SnmpConstants.sysDescr, 
        new OctetString("Monitor app"))); 
      // Add Payload 
      Variable messaage = new OctetString(aMessage); 
      trap.add(new VariableBinding(oid, messaage)); 

      // need to specify the system up time 
      // trap.add(new VariableBinding(SnmpConstants.sysUpTime, 
      // new OctetString(new Date().toString()))); 
      // trap.add(new VariableBinding(SnmpConstants.snmpTrapOID, new OID(
      // Oid))); 
      // trap.add(new VariableBinding(SnmpConstants.snmpTrapAddress, 
      // new IpAddress(ipAddress))); 

      // trap.add(new VariableBinding(new OID(oid), new OctetString(
      // "Major"))); 
      // trap.setType(PDU.NOTIFICATION); 

      // Specify receiver 
      Address targetaddress = new UdpAddress(trapIpDestination + "/" 
        + trapPort); 
      CommunityTarget target = new CommunityTarget(); 
      target.setCommunity(new OctetString("public")); 
      target.setVersion(SnmpConstants.version2c); 
      target.setAddress(targetaddress); 

      // Send 
      Snmp snmp = new Snmp(new DefaultUdpTransportMapping()); 
      snmp.send(trap, target, null, null); 
     } catch (IOException e) { 
      System.out.println("Error Sending Trap: " + e.getMessage()); 
      e.printStackTrace(); 
     } 
    } 

    public static void main(String[] args) throws Exception { 
     new TrapSenderVersion2("192.168.1.31", Integer.parseInt("162"), 
       "Test Trap Message"); 
    } 
} 

回答

0

首先要做的OID不開始以一個點。您應該將其刪除以避免錯誤並提高程序性能。

關於你的問題:SNMP沒有爲陷阱/通知指定一個像「嚴重等級」的概念。因此,它需要成爲特定於供應商的TRAP-TYPE或NOTIFICATION-TYPE的MIB規範的一部分。在SNMP標準中不具有嚴重性的想法是接收者應該能夠確定事件是否嚴重。

因此,在你的情況下,我會認爲你需要在陷阱接收器應用程序中指定「日誌級別」,而不是在發送者代碼中。