Search in sources :

Example 1 with TrapIdentity

use of org.opennms.netmgt.snmp.TrapIdentity in project opennms by OpenNMS.

the class TrapUtils method getTrapData.

/**
 * Gets the trap identity.
 *
 * @param trapNotification the trap notification
 * @return the identity
 */
public static TrapData getTrapData(TrapInformation trapNotification) {
    if (trapNotification instanceof Snmp4JV1TrapInformation) {
        Snmp4JV1TrapInformation info = (Snmp4JV1TrapInformation) trapNotification;
        TrapIdentity identity = info.getTrapIdentity();
        TrapData data = new TrapData(identity.getEnterpriseId(), identity.getGeneric(), identity.getSpecific());
        for (int i = 0; i < info.getPduLength(); i++) {
            VariableBinding v = info.getVarBindAt(i);
            SnmpValue value = new Snmp4JValue(v.getVariable());
            data.addParameter("." + v.getOid().toString(), value.toDisplayString());
        }
        return data;
    } else if (trapNotification instanceof Snmp4JV2TrapInformation) {
        Snmp4JV2TrapInformation info = (Snmp4JV2TrapInformation) trapNotification;
        TrapIdentity identity = info.getTrapIdentity();
        TrapData data = new TrapData(identity.getEnterpriseId(), identity.getGeneric(), identity.getSpecific());
        for (int i = 0; i < info.getPduLength(); i++) {
            VariableBinding v = info.getVarBindAt(i);
            SnmpValue value = new Snmp4JValue(v.getVariable());
            data.addParameter("." + v.getOid().toString(), value.toDisplayString());
        }
        return data;
    }
    return null;
}
Also used : Snmp4JV2TrapInformation(org.opennms.netmgt.snmp.snmp4j.Snmp4JTrapNotifier.Snmp4JV2TrapInformation) TrapIdentity(org.opennms.netmgt.snmp.TrapIdentity) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) Snmp4JV1TrapInformation(org.opennms.netmgt.snmp.snmp4j.Snmp4JTrapNotifier.Snmp4JV1TrapInformation) VariableBinding(org.snmp4j.smi.VariableBinding) TrapData(org.opennms.netmgt.alarmd.northbounder.snmptrap.TrapData)

Example 2 with TrapIdentity

use of org.opennms.netmgt.snmp.TrapIdentity in project opennms by OpenNMS.

the class V2TrapInformation method getTrapIdentity.

@Override
public TrapIdentity getTrapIdentity() {
    // Get the value for the snmpTrapOID
    SnmpObjectId snmpTrapOid = (SnmpObjectId) m_pdu.getVarBindAt(V2TrapInformation.SNMP_TRAP_OID_INDEX).getValue();
    SnmpObjectId lastVarBindOid = m_pdu.getVarBindAt(getPduLength() - 1).getName();
    SnmpSyntax lastVarBindValue = m_pdu.getVarBindAt(getPduLength() - 1).getValue();
    return new TrapIdentity(SnmpObjId.get(snmpTrapOid.getIdentifiers()), SnmpObjId.get(lastVarBindOid.getIdentifiers()), new JoeSnmpValue(lastVarBindValue));
}
Also used : SnmpSyntax(org.opennms.protocols.snmp.SnmpSyntax) TrapIdentity(org.opennms.netmgt.snmp.TrapIdentity) SnmpObjectId(org.opennms.protocols.snmp.SnmpObjectId)

Aggregations

TrapIdentity (org.opennms.netmgt.snmp.TrapIdentity)2 TrapData (org.opennms.netmgt.alarmd.northbounder.snmptrap.TrapData)1 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)1 Snmp4JV1TrapInformation (org.opennms.netmgt.snmp.snmp4j.Snmp4JTrapNotifier.Snmp4JV1TrapInformation)1 Snmp4JV2TrapInformation (org.opennms.netmgt.snmp.snmp4j.Snmp4JTrapNotifier.Snmp4JV2TrapInformation)1 SnmpObjectId (org.opennms.protocols.snmp.SnmpObjectId)1 SnmpSyntax (org.opennms.protocols.snmp.SnmpSyntax)1 VariableBinding (org.snmp4j.smi.VariableBinding)1