简体   繁体   中英

snmp4j warning log level

My problem is the warning log level of this snmp4j trap sender is received as a minor log level but i need a warning log level message to be received ,something like if i was to use coldstart or warnstart pdu notifications ,can anyone help with this error ?

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

First of all, OIDs do not start with a dot. You should remove it to avoid errors and to improve your programs performance.

Regarding your question: SNMP do not specify a concept like a "severity class" for traps/notifications. Thus, it needs to be part of the MIB specification of the vendor-specific TRAP-TYPE or NOTIFICATION-TYPE. The idea of not-having a severity in the SNMP standard was that the receiver should be able to decide if an event is severe or not.

So, in your case I would think that you need to specify the "log level" in the trap receiver application and not in the sender code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM