1

How can I set a trap severity?

Code below

TransportMapping transport = new DefaultUdpTransportMapping();
    Snmp snmp = new Snmp(transport);

    CommunityTarget localtarget = new CommunityTarget();
    localtarget.setCommunity(new OctetString("public"));
    localtarget.setAddress(new UdpAddress(managerIpAdd + "/162"));
    localtarget.setVersion(SnmpConstants.version2c);
    localtarget.setRetries(3);
    localtarget.setTimeout(2000);

    PDU pdu = new PDU();

    // need to specify the system up time
    pdu.add(new VariableBinding(SnmpConstants.sysUpTime, new OctetString(new Date().toString())));
    pdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, targetOID));
    pdu.add(new VariableBinding(SnmpConstants.snmpTrapAddress, new IpAddress(ApplicationUtil.getMachineIpAddress())));

    // variable binding for Enterprise Specific objects, Severity (should be defined in MIB file)
    pdu.add(new VariableBinding(targetOID, new OctetString(message)));        

    pdu.setType(PDU.TRAP);

    snmp.send(pdu, localtarget);

    snmp.close();

Thanks,

Jin
  • 77
  • 1
  • 6

1 Answers1

3

There is no standard way to specify the severity for a trap. Most agents that send "alarm" traps will define a proprietary MIB that includes a varbind for severity.

hallidave
  • 9,579
  • 6
  • 31
  • 27
  • Thanks for the reply. So what's your saying is that every SNMP manager has their own MIB to specify the severity of the traps? – Jin Aug 12 '10 at 07:45
  • 1
    I was talking about the agent, not the manager. The agent can either have a proprietary MIB or not support the idea of severity at all. The manager can choose to accept the severity assigned by the agent, assign it's own, or ignore it altogether. There are no standards for how it's done. – hallidave Aug 12 '10 at 17:21
  • In addition to traps discussed above, often the agent provides a way to GET the currently active alarms (including a severity field). But as @hallidave mentions, normally this is all propriety unfortunately. – k1eran Sep 16 '14 at 12:51