Search in sources :

Example 6 with SnmpV3TrapBuilder

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

the class SnmpTrapForwarderHelper method sendV3StartSyncTrap.

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

Example 7 with SnmpV3TrapBuilder

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

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

the class SnmpTrapForwarderHelper method sendV3EndSyncInform.

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

Example 9 with SnmpV3TrapBuilder

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

the class SnmpTrapHelper method forwardV3Inform.

/**
     * Create an SNMP V3 inform 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 forwardV3Inform(SnmpTrapConfig trapConfig) throws SnmpTrapException {
    SnmpV3TrapBuilder trap = SnmpUtils.getV3InformBuilder();
    populateTrapBuilder(trap, trapConfig);
    try {
        SnmpAgentConfig config = getAgentConfig(trapConfig);
        trap.sendInform(config.getAddress().getHostAddress(), config.getPort(), config.getTimeout(), config.getTimeout(), 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 10 with SnmpV3TrapBuilder

use of org.opennms.netmgt.snmp.SnmpV3TrapBuilder 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:
    }
}
Also used : SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) SnmpV3TrapBuilder(org.opennms.netmgt.snmp.SnmpV3TrapBuilder) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) OctetString(org.snmp4j.smi.OctetString) SnmpTrapBuilder(org.opennms.netmgt.snmp.SnmpTrapBuilder)

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