Search in sources :

Example 16 with SnmpTrapBuilder

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

the class SnmpTrapHelper method createV2Trap.

/**
 * Create an SNMP V2 trap with the specified trap object ID, and sysUpTime
 * value.
 *
 * @param trapOid
 *            The trap object id.
 * @param sysUpTime
 *            The system up time.
 * @return The newly-created trap.
 * @exception Throws
 *                SnmpTrapHelperException if the trap cannot be created for
 *                any reason.
 * @throws org.opennms.netmgt.scriptd.helper.SnmpTrapHelperException if any.
 */
public SnmpTrapBuilder createV2Trap(String trapOid, String sysUpTime) throws SnmpTrapHelperException {
    SnmpTrapBuilder packet = SnmpUtils.getV2TrapBuilder();
    addVarBinding(packet, SNMP_SYSUPTIME_OID, EventConstants.TYPE_SNMP_TIMETICKS, sysUpTime);
    addVarBinding(packet, SNMP_TRAP_OID, EventConstants.TYPE_SNMP_OBJECT_IDENTIFIER, trapOid);
    return packet;
}
Also used : SnmpTrapBuilder(org.opennms.netmgt.snmp.SnmpTrapBuilder)

Example 17 with SnmpTrapBuilder

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

the class TrapIT method sendTrap.

private void sendTrap(final InetSocketAddress trapAddr) {
    LOG.info("Sending trap");
    try {
        SnmpTrapBuilder pdu = SnmpUtils.getV2TrapBuilder();
        pdu.addVarBind(SnmpObjId.get(".1.3.6.1.2.1.1.3.0"), SnmpUtils.getValueFactory().getTimeTicks(0));
        // warmStart
        pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.1.0"), SnmpUtils.getValueFactory().getObjectId(SnmpObjId.get(".1.3.6.1.6.3.1.1.5.2")));
        pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.3.0"), SnmpUtils.getValueFactory().getObjectId(SnmpObjId.get(".1.3.6.1.4.1.5813")));
        pdu.send(InetAddressUtils.str(trapAddr.getAddress()), trapAddr.getPort(), "public");
    } catch (Throwable e) {
        LOG.error(e.getMessage(), e);
    }
    LOG.info("Trap has been sent");
}
Also used : SnmpTrapBuilder(org.opennms.netmgt.snmp.SnmpTrapBuilder)

Example 18 with SnmpTrapBuilder

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

the class TrapHandlerITCase method sendV2Trap.

public void sendV2Trap(String enterprise, int specific, LinkedHashMap<String, SnmpValue> varbinds) throws Exception {
    SnmpObjId enterpriseId = SnmpObjId.get(enterprise);
    boolean isGeneric = false;
    SnmpObjId trapOID;
    if (SnmpObjId.get(".1.3.6.1.6.3.1.1.5").isPrefixOf(enterpriseId)) {
        isGeneric = true;
        trapOID = enterpriseId;
    } else {
        trapOID = SnmpObjId.get(enterpriseId, new SnmpInstId(specific));
    // XXX or should it be this
    // trap OID = enterprise + ".0." + specific;
    }
    SnmpTrapBuilder pdu = SnmpUtils.getV2TrapBuilder();
    pdu.addVarBind(SnmpObjId.get(".1.3.6.1.2.1.1.3.0"), SnmpUtils.getValueFactory().getTimeTicks(0));
    pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.1.0"), SnmpUtils.getValueFactory().getObjectId(trapOID));
    if (isGeneric) {
        pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.3.0"), SnmpUtils.getValueFactory().getObjectId(enterpriseId));
    }
    for (Map.Entry<String, SnmpValue> entry : varbinds.entrySet()) {
        pdu.addVarBind(SnmpObjId.get(entry.getKey()), entry.getValue());
    }
    pdu.send(getHostAddress(), m_trapdConfig.getSnmpTrapPort(), "public");
}
Also used : SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) SnmpTrapBuilder(org.opennms.netmgt.snmp.SnmpTrapBuilder)

Example 19 with SnmpTrapBuilder

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

the class TrapHandlerITCase method sendV2Trap.

public void sendV2Trap(String enterprise, int specific) throws Exception {
    SnmpObjId enterpriseId = SnmpObjId.get(enterprise);
    boolean isGeneric = false;
    SnmpObjId trapOID;
    if (SnmpObjId.get(".1.3.6.1.6.3.1.1.5").isPrefixOf(enterpriseId)) {
        isGeneric = true;
        trapOID = enterpriseId;
    } else {
        trapOID = SnmpObjId.get(enterpriseId, new SnmpInstId(specific));
    // XXX or should it be this
    // trap OID = enterprise + ".0." + specific;
    }
    SnmpTrapBuilder pdu = SnmpUtils.getV2TrapBuilder();
    pdu.addVarBind(SnmpObjId.get(".1.3.6.1.2.1.1.3.0"), SnmpUtils.getValueFactory().getTimeTicks(0));
    pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.1.0"), SnmpUtils.getValueFactory().getObjectId(trapOID));
    if (isGeneric) {
        pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.3.0"), SnmpUtils.getValueFactory().getObjectId(enterpriseId));
    }
    pdu.send(getHostAddress(), m_trapdConfig.getSnmpTrapPort(), "public");
}
Also used : SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) SnmpTrapBuilder(org.opennms.netmgt.snmp.SnmpTrapBuilder)

Example 20 with SnmpTrapBuilder

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

the class Snmp4jTrapReceiverIT method sendTraps.

private void sendTraps(final Snmp4JStrategy strategy, final int v3Level) throws Exception {
    final String hostAddress = str(getAgentAddress());
    LOG.debug("Sending V2 Trap");
    SnmpObjId enterpriseId = SnmpObjId.get(".0.0");
    SnmpObjId trapOID = SnmpObjId.get(enterpriseId, new SnmpInstId(1));
    SnmpTrapBuilder pdu = strategy.getV2TrapBuilder();
    pdu.addVarBind(SnmpObjId.get(".1.3.6.1.2.1.1.3.0"), strategy.getValueFactory().getTimeTicks(0));
    pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.1.0"), strategy.getValueFactory().getObjectId(trapOID));
    pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.3.0"), strategy.getValueFactory().getObjectId(enterpriseId));
    pdu.send(hostAddress, 9162, "public");
    LOG.debug("Sending V3 Trap");
    SnmpV3TrapBuilder pduv3 = strategy.getV3TrapBuilder();
    pduv3.addVarBind(SnmpObjId.get(".1.3.6.1.2.1.1.3.0"), strategy.getValueFactory().getTimeTicks(0));
    pduv3.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.1.0"), strategy.getValueFactory().getObjectId(trapOID));
    pduv3.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.3.0"), strategy.getValueFactory().getObjectId(enterpriseId));
    switch(v3Level) {
        case SnmpConfiguration.NOAUTH_NOPRIV:
            pduv3.send(hostAddress, 9162, SnmpConfiguration.NOAUTH_NOPRIV, "noAuthUser", null, null, null, null);
            break;
        case SnmpConfiguration.AUTH_PRIV:
            pduv3.send(hostAddress, 9162, SnmpConfiguration.AUTH_PRIV, "opennmsUser", "0p3nNMSv3", SnmpConfiguration.DEFAULT_AUTH_PROTOCOL, "0p3nNMSv3", SnmpConfiguration.DEFAULT_PRIV_PROTOCOL);
            break;
        default:
    }
}
Also used : SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) SnmpV3TrapBuilder(org.opennms.netmgt.snmp.SnmpV3TrapBuilder) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) OctetString(org.snmp4j.smi.OctetString) SnmpTrapBuilder(org.opennms.netmgt.snmp.SnmpTrapBuilder)

Aggregations

SnmpTrapBuilder (org.opennms.netmgt.snmp.SnmpTrapBuilder)27 UnknownHostException (java.net.UnknownHostException)15 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)6 SnmpObjId (org.opennms.netmgt.snmp.SnmpObjId)6 SnmpV3TrapBuilder (org.opennms.netmgt.snmp.SnmpV3TrapBuilder)5 Test (org.junit.Test)3 InetAddress (java.net.InetAddress)2 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)2 SnmpV2TrapBuilder (org.opennms.netmgt.snmp.SnmpV2TrapBuilder)2 SQLException (java.sql.SQLException)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 CamelBlueprintTest (org.opennms.core.test.camel.CamelBlueprintTest)1 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)1 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)1 Parm (org.opennms.netmgt.xml.event.Parm)1 Snmp (org.opennms.netmgt.xml.event.Snmp)1 Value (org.opennms.netmgt.xml.event.Value)1 OctetString (org.snmp4j.smi.OctetString)1