Search in sources :

Example 6 with SnmpTrapBuilder

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

the class SnmpTrapForwarderHelper method sendV3AlarmTrap.

public void sendV3AlarmTrap(Event event, boolean sync) throws UnknownHostException, SnmpTrapHelperException {
    long trapTimeStamp = 0;
    SnmpTrapBuilder trap = snmpTrapHelper.createV3Trap(".1.3.6.1.4.1.5813.1.3", Long.toString(trapTimeStamp));
    trap = buildAlarmTrap(event, sync, trap);
    SnmpV3TrapBuilder v3trap = (SnmpV3TrapBuilder) trap;
    try {
        v3trap.send(getIp(), getPort(), 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 7 with SnmpTrapBuilder

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

the class SnmpTrapForwarderHelper method sendV2StartSyncTrap.

public void sendV2StartSyncTrap() {
    long trapTimeStamp = 0;
    try {
        SnmpTrapBuilder trap = snmpTrapHelper.createV2Trap(".1.3.6.1.4.1.5813.1.5", 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)

Example 8 with SnmpTrapBuilder

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

the class SnmpTrapForwarderHelper method sendV1AlarmTrap.

public void sendV1AlarmTrap(Event event, boolean sync) throws UnknownHostException {
    SnmpTrapBuilder trap = snmpTrapHelper.createV1Trap(".1.3.6.1.4.1.5813.1", getSource_ip(), 6, 3, 0);
    trap = buildAlarmTrap(event, sync, trap);
    try {
        trap.send(getIp(), getPort(), getCommunity());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) SnmpTrapBuilder(org.opennms.netmgt.snmp.SnmpTrapBuilder)

Example 9 with SnmpTrapBuilder

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

the class SnmpTrapForwarderHelper method sendV1EventTrap.

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

Example 10 with SnmpTrapBuilder

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

the class TrapdIT method testSnmpV2cTrapWithAddressFromVarbind.

/**
 * Verifies that we can pull the agent address from the snmpTrapAddress
 * varbind in a SNMPv2 trap.
 */
@Test
public void testSnmpV2cTrapWithAddressFromVarbind() throws Exception {
    // Enable the feature (disabled by default)
    m_trapdConfig.getConfig().setUseAddressFromVarbind(true);
    String localhost = "127.0.0.1";
    InetAddress remoteAddr = InetAddress.getByName("10.255.1.1");
    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));
    // The varbind with the address
    pdu.addVarBind(TrapUtils.SNMP_TRAP_ADDRESS_OID, SnmpUtils.getValueFactory().getIpAddress(InetAddress.getByName("10.255.1.1")));
    EventBuilder defaultTrapBuilder = new EventBuilder("uei.opennms.org/default/trap", "trapd");
    defaultTrapBuilder.setInterface(remoteAddr);
    defaultTrapBuilder.setSnmpVersion("v2c");
    m_mockEventIpcManager.getEventAnticipator().anticipateEvent(defaultTrapBuilder.getEvent());
    EventBuilder newSuspectBuilder = new EventBuilder(EventConstants.NEW_SUSPECT_INTERFACE_EVENT_UEI, "trapd");
    // The address in the newSuspect event should match the one specified in the varbind
    newSuspectBuilder.setInterface(remoteAddr);
    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)

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