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