use of org.opennms.netmgt.snmp.SnmpTrapBuilder in project opennms by OpenNMS.
the class SnmpTrapHelper method createV2Trap.
/**
* Create an SNMP V2 trap with the specified trap object ID, and sysUpTime
* value.
*
* @param trapOid
* The trap object id.
* @param sysUpTime
* The system up time.
* @return The newly-created trap.
* @exception Throws
* SnmpTrapHelperException if the trap cannot be created for
* any reason.
* @throws org.opennms.netmgt.scriptd.helper.SnmpTrapHelperException if any.
*/
public SnmpTrapBuilder createV2Trap(String trapOid, String sysUpTime) throws SnmpTrapHelperException {
SnmpTrapBuilder packet = SnmpUtils.getV2TrapBuilder();
addVarBinding(packet, SNMP_SYSUPTIME_OID, EventConstants.TYPE_SNMP_TIMETICKS, sysUpTime);
addVarBinding(packet, SNMP_TRAP_OID, EventConstants.TYPE_SNMP_OBJECT_IDENTIFIER, trapOid);
return packet;
}
use of org.opennms.netmgt.snmp.SnmpTrapBuilder in project opennms by OpenNMS.
the class TrapIT method sendTrap.
private void sendTrap(final InetSocketAddress trapAddr) {
LOG.info("Sending trap");
try {
SnmpTrapBuilder pdu = SnmpUtils.getV2TrapBuilder();
pdu.addVarBind(SnmpObjId.get(".1.3.6.1.2.1.1.3.0"), SnmpUtils.getValueFactory().getTimeTicks(0));
// warmStart
pdu.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")));
pdu.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")));
pdu.send(InetAddressUtils.str(trapAddr.getAddress()), trapAddr.getPort(), "public");
} catch (Throwable e) {
LOG.error(e.getMessage(), e);
}
LOG.info("Trap has been sent");
}
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 Snmp4jTrapReceiverIT method sendTraps.
private void sendTraps(final Snmp4JStrategy strategy, final int v3Level) throws Exception {
final String hostAddress = str(getAgentAddress());
LOG.debug("Sending V2 Trap");
SnmpObjId enterpriseId = SnmpObjId.get(".0.0");
SnmpObjId trapOID = SnmpObjId.get(enterpriseId, new SnmpInstId(1));
SnmpTrapBuilder pdu = strategy.getV2TrapBuilder();
pdu.addVarBind(SnmpObjId.get(".1.3.6.1.2.1.1.3.0"), strategy.getValueFactory().getTimeTicks(0));
pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.1.0"), strategy.getValueFactory().getObjectId(trapOID));
pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.3.0"), strategy.getValueFactory().getObjectId(enterpriseId));
pdu.send(hostAddress, 9162, "public");
LOG.debug("Sending V3 Trap");
SnmpV3TrapBuilder pduv3 = strategy.getV3TrapBuilder();
pduv3.addVarBind(SnmpObjId.get(".1.3.6.1.2.1.1.3.0"), strategy.getValueFactory().getTimeTicks(0));
pduv3.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.1.0"), strategy.getValueFactory().getObjectId(trapOID));
pduv3.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.3.0"), strategy.getValueFactory().getObjectId(enterpriseId));
switch(v3Level) {
case SnmpConfiguration.NOAUTH_NOPRIV:
pduv3.send(hostAddress, 9162, SnmpConfiguration.NOAUTH_NOPRIV, "noAuthUser", null, null, null, null);
break;
case SnmpConfiguration.AUTH_PRIV:
pduv3.send(hostAddress, 9162, SnmpConfiguration.AUTH_PRIV, "opennmsUser", "0p3nNMSv3", SnmpConfiguration.DEFAULT_AUTH_PROTOCOL, "0p3nNMSv3", SnmpConfiguration.DEFAULT_PRIV_PROTOCOL);
break;
default:
}
}
Aggregations