Search in sources :

Example 1 with SnmpTrapBuilder

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

the class TrapdIT method testSnmpV2cTrapSend.

@Test
public void testSnmpV2cTrapSend() throws Exception {
    String localhost = "127.0.0.1";
    InetAddress localAddr = InetAddressUtils.addr(localhost);
    SnmpObjId enterpriseId = SnmpObjId.get(".1.3.6.1.4.1.5813");
    SnmpObjId trapOID = SnmpObjId.get(enterpriseId, new SnmpInstId(1));
    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));
    pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.3.0"), SnmpUtils.getValueFactory().getObjectId(enterpriseId));
    EventBuilder defaultTrapBuilder = new EventBuilder("uei.opennms.org/default/trap", "trapd");
    defaultTrapBuilder.setInterface(localAddr);
    defaultTrapBuilder.setSnmpVersion("v2c");
    m_mockEventIpcManager.getEventAnticipator().anticipateEvent(defaultTrapBuilder.getEvent());
    EventBuilder newSuspectBuilder = new EventBuilder(EventConstants.NEW_SUSPECT_INTERFACE_EVENT_UEI, "trapd");
    newSuspectBuilder.setInterface(localAddr);
    m_mockEventIpcManager.getEventAnticipator().anticipateEvent(newSuspectBuilder.getEvent());
    pdu.send(localhost, m_trapdConfig.getSnmpTrapPort(), "public");
    // Allow time for Trapd and Eventd to do their magic
    Thread.sleep(5000);
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) InetAddress(java.net.InetAddress) SnmpTrapBuilder(org.opennms.netmgt.snmp.SnmpTrapBuilder) Test(org.junit.Test)

Example 2 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 3 with SnmpTrapBuilder

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

the class SnmpTrapForwarderHelper method sendV3AlarmInform.

public void sendV3AlarmInform(Event event, boolean sync) throws UnknownHostException, SnmpTrapHelperException {
    long trapTimeStamp = 0;
    SnmpTrapBuilder trap = snmpTrapHelper.createV3Inform(".1.3.6.1.4.1.5813.1.3", Long.toString(trapTimeStamp));
    trap = buildAlarmTrap(event, sync, trap);
    SnmpV3TrapBuilder inform = (SnmpV3TrapBuilder) trap;
    try {
        inform.sendInform(getIp(), getPort(), getTimeout(), getRetries(), getSecurityLevel(), getSecurityname(), getAuthPassPhrase(), getAuthProtocol(), getPrivPassPhrase(), getPrivprotocol());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : SnmpV3TrapBuilder(org.opennms.netmgt.snmp.SnmpV3TrapBuilder) UnknownHostException(java.net.UnknownHostException) SnmpTrapBuilder(org.opennms.netmgt.snmp.SnmpTrapBuilder)

Example 4 with SnmpTrapBuilder

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

the class SnmpTrapForwarderHelper method sendV1StartSyncTrap.

public void sendV1StartSyncTrap() {
    try {
        SnmpTrapBuilder trap = snmpTrapHelper.createV1Trap(".1.3.6.1.4.1.5813.1", getSource_ip(), 6, 5, 0);
        trap.send(getIp(), getPort(), getCommunity());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) SnmpTrapBuilder(org.opennms.netmgt.snmp.SnmpTrapBuilder)

Example 5 with SnmpTrapBuilder

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

the class SnmpTrapForwarderHelper method sendV2EndSyncTrap.

public void sendV2EndSyncTrap() {
    long trapTimeStamp = 0;
    try {
        SnmpTrapBuilder trap = snmpTrapHelper.createV2Trap(".1.3.6.1.4.1.5813.1.6", Long.toString(trapTimeStamp));
        trap.send(getIp(), getPort(), getCommunity());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) 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