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();
}
}
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();
}
}
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();
}
}
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();
}
}
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);
}
Aggregations