Search in sources :

Example 1 with SnmpV3TrapBuilder

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

the class SnmpTrapHelper method forwardV3Trap.

/**
     * Create an SNMP V3 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 forwardV3Trap(SnmpTrapConfig trapConfig) throws SnmpTrapException {
    SnmpV3TrapBuilder trap = SnmpUtils.getV3TrapBuilder();
    populateTrapBuilder(trap, trapConfig);
    try {
        SnmpAgentConfig config = getAgentConfig(trapConfig);
        trap.send(config.getAddress().getHostAddress(), config.getPort(), config.getSecurityLevel(), config.getSecurityName(), config.getAuthPassPhrase(), config.getAuthProtocol(), config.getPrivPassPhrase(), config.getPrivProtocol());
    } catch (Throwable e) {
        throw new SnmpTrapException("Failed to send trap " + e.getMessage(), e);
    }
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) SnmpV3TrapBuilder(org.opennms.netmgt.snmp.SnmpV3TrapBuilder)

Example 2 with SnmpV3TrapBuilder

use of org.opennms.netmgt.snmp.SnmpV3TrapBuilder 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 3 with SnmpV3TrapBuilder

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

the class SnmpTrapHelper method createV3Trap.

/**
     * Create an SNMP V3 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 SnmpV3TrapBuilder createV3Trap(String trapOid, String sysUpTime) throws SnmpTrapHelperException {
    SnmpV3TrapBuilder packet = SnmpUtils.getV3TrapBuilder();
    addVarBinding(packet, SNMP_SYSUPTIME_OID, EventConstants.TYPE_SNMP_TIMETICKS, sysUpTime);
    addVarBinding(packet, SNMP_TRAP_OID, EventConstants.TYPE_SNMP_OBJECT_IDENTIFIER, trapOid);
    return packet;
}
Also used : SnmpV3TrapBuilder(org.opennms.netmgt.snmp.SnmpV3TrapBuilder)

Example 4 with SnmpV3TrapBuilder

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

the class SnmpTrapHelper method createV3Inform.

/**
     * Create an SNMP V3 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 SnmpV3TrapBuilder createV3Inform(String trapOid, String sysUpTime) throws SnmpTrapHelperException {
    SnmpV3TrapBuilder packet = SnmpUtils.getV3InformBuilder();
    addVarBinding(packet, SNMP_SYSUPTIME_OID, EventConstants.TYPE_SNMP_TIMETICKS, sysUpTime);
    addVarBinding(packet, SNMP_TRAP_OID, EventConstants.TYPE_SNMP_OBJECT_IDENTIFIER, trapOid);
    return packet;
}
Also used : SnmpV3TrapBuilder(org.opennms.netmgt.snmp.SnmpV3TrapBuilder)

Example 5 with SnmpV3TrapBuilder

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

the class SnmpTrapForwarderHelper method sendV3StartSyncInform.

public void sendV3StartSyncInform() {
    long trapTimeStamp = 0;
    try {
        SnmpV3TrapBuilder inform = snmpTrapHelper.createV3Inform(".1.3.6.1.4.1.5813.1.5", Long.toString(trapTimeStamp));
        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)

Aggregations

SnmpV3TrapBuilder (org.opennms.netmgt.snmp.SnmpV3TrapBuilder)13 UnknownHostException (java.net.UnknownHostException)8 SnmpTrapBuilder (org.opennms.netmgt.snmp.SnmpTrapBuilder)5 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)2 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)1 SnmpObjId (org.opennms.netmgt.snmp.SnmpObjId)1 OctetString (org.snmp4j.smi.OctetString)1