snmp4j警告日志级别

时间:2014-01-15 10:19:13

标签: java snmp snmp4j

我的问题是这个snmp4j陷阱发送者的警告日志级别是作为次要日志级别接收但我需要收到警告日志级别消息,如果我要使用coldstart或warnstart pdu通知,可以任何人帮助有这个错误?

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");
    }
}

1 个答案:

答案 0 :(得分:0)

首先,OID以而不是以点开头。您应该删除它以避免错误并提高程序性能。

关于您的问题:SNMP没有为陷阱/通知指定类似“严重性类”的概念。因此,它需要是供应商特定的TRAP-TYPE或NOTIFICATION-TYPE的MIB规范的一部分。在SNMP标准中没有严重性的想法是接收器应该能够决定事件是否严重。

因此,在您的情况下,我认为您需要在陷阱接收器应用程序中指定“日志级别”,而不是在发件人代码中。

相关问题