Search in sources :

Example 11 with SnmpTrapBuilder

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

the class TrapdSinkPatternWiringIT method testWiring.

// The CamelBlueprintTest should have started the bundle and therefore also started
// the TrapListener (see blueprint-trapd-listener.xml), which listens to traps.
@Test
public void testWiring() throws Exception {
    // No traps received or processed
    Assert.assertEquals(1, messageProcessedLatch.getCount());
    // At this point everything should be set up correctly
    final SnmpTrapBuilder builder = SnmpUtils.getV2TrapBuilder();
    builder.addVarBind(SnmpObjId.get(".1.3.6.1.2.1.1.3.0"), SnmpUtils.getValueFactory().getTimeTicks(0));
    builder.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")));
    builder.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")));
    builder.send("localhost", 1162, "public");
    // Wait before continuing
    messageProcessedLatch.await(10, TimeUnit.SECONDS);
    // Trap should be received and processed
    Assert.assertEquals(0, messageProcessedLatch.getCount());
}
Also used : SnmpTrapBuilder(org.opennms.netmgt.snmp.SnmpTrapBuilder) Test(org.junit.Test) CamelBlueprintTest(org.opennms.core.test.camel.CamelBlueprintTest)

Example 12 with SnmpTrapBuilder

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

the class EventdStresser method executeStressTest.

private static void executeStressTest() {
    SnmpTrapBuilder builder = null;
    try {
        builder = createBuilder();
        stressEventd(builder);
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) SQLException(java.sql.SQLException) SnmpTrapBuilder(org.opennms.netmgt.snmp.SnmpTrapBuilder)

Example 13 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 14 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 15 with SnmpTrapBuilder

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

the class SnmpTrapHelper method forwardV2Trap.

/**
     * Create an SNMP V2 trap based on the content of the specified trap configuration, and send it to the appropriate destination.
     *
     * @param trapConfig The trap configuration mapping object
     * @throws SnmpTrapException if any.
     */
private void forwardV2Trap(SnmpTrapConfig trapConfig) throws SnmpTrapException {
    SnmpTrapBuilder trap = SnmpUtils.getV2TrapBuilder();
    populateTrapBuilder(trap, trapConfig);
    try {
        SnmpAgentConfig config = getAgentConfig(trapConfig);
        trap.send(config.getAddress().getHostAddress(), config.getPort(), config.getReadCommunity());
    } catch (Throwable e) {
        throw new SnmpTrapException("Failed to send trap " + e.getMessage(), e);
    }
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) SnmpTrapBuilder(org.opennms.netmgt.snmp.SnmpTrapBuilder)

Aggregations

SnmpTrapBuilder (org.opennms.netmgt.snmp.SnmpTrapBuilder)26 UnknownHostException (java.net.UnknownHostException)15 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)5 SnmpObjId (org.opennms.netmgt.snmp.SnmpObjId)5 SnmpV3TrapBuilder (org.opennms.netmgt.snmp.SnmpV3TrapBuilder)5 Test (org.junit.Test)2 SnmpV2TrapBuilder (org.opennms.netmgt.snmp.SnmpV2TrapBuilder)2 InetAddress (java.net.InetAddress)1 SQLException (java.sql.SQLException)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 CamelBlueprintTest (org.opennms.core.test.camel.CamelBlueprintTest)1 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)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