Search in sources :

Example 11 with USM

use of org.snmp4j.security.USM in project camel by apache.

the class SnmpOIDPoller method doStart.

@Override
protected void doStart() throws Exception {
    super.doStart();
    this.targetAddress = GenericAddress.parse(this.endpoint.getAddress());
    // either tcp or udp
    if ("tcp".equals(endpoint.getProtocol())) {
        this.transport = new DefaultTcpTransportMapping();
    } else if ("udp".equals(endpoint.getProtocol())) {
        this.transport = new DefaultUdpTransportMapping();
    } else {
        throw new IllegalArgumentException("Unknown protocol: " + endpoint.getProtocol());
    }
    this.snmp = new Snmp(this.transport);
    if (SnmpConstants.version3 == endpoint.getSnmpVersion()) {
        UserTarget userTarget = new UserTarget();
        userTarget.setSecurityLevel(endpoint.getSecurityLevel());
        userTarget.setSecurityName(convertToOctetString(endpoint.getSecurityName()));
        userTarget.setAddress(targetAddress);
        userTarget.setRetries(endpoint.getRetries());
        userTarget.setTimeout(endpoint.getTimeout());
        userTarget.setVersion(endpoint.getSnmpVersion());
        this.target = userTarget;
        USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
        SecurityModels.getInstance().addSecurityModel(usm);
        OID authProtocol = convertAuthenticationProtocol(endpoint.getAuthenticationProtocol());
        OctetString authPwd = convertToOctetString(endpoint.getAuthenticationPassphrase());
        OID privProtocol = convertPrivacyProtocol(endpoint.getPrivacyProtocol());
        OctetString privPwd = convertToOctetString(endpoint.getPrivacyPassphrase());
        UsmUser user = new UsmUser(convertToOctetString(endpoint.getSecurityName()), authProtocol, authPwd, privProtocol, privPwd);
        usm.addUser(convertToOctetString(endpoint.getSecurityName()), user);
        ScopedPDU scopedPDU = new ScopedPDU();
        if (endpoint.getSnmpContextEngineId() != null) {
            scopedPDU.setContextEngineID(new OctetString(endpoint.getSnmpContextEngineId()));
        }
        if (endpoint.getSnmpContextName() != null) {
            scopedPDU.setContextName(new OctetString(endpoint.getSnmpContextName()));
        }
        this.pdu = scopedPDU;
    } else {
        CommunityTarget communityTarget = new CommunityTarget();
        communityTarget.setCommunity(convertToOctetString(endpoint.getSnmpCommunity()));
        communityTarget.setAddress(targetAddress);
        communityTarget.setRetries(endpoint.getRetries());
        communityTarget.setTimeout(endpoint.getTimeout());
        communityTarget.setVersion(endpoint.getSnmpVersion());
        this.target = communityTarget;
        this.pdu = new PDU();
    }
    // listen to the transport
    if (LOG.isDebugEnabled()) {
        LOG.debug("Starting OID poller on {} using {} protocol", endpoint.getAddress(), endpoint.getProtocol());
    }
    this.transport.listen();
    if (LOG.isInfoEnabled()) {
        LOG.info("Started OID poller on {} using {} protocol", endpoint.getAddress(), endpoint.getProtocol());
    }
}
Also used : OctetString(org.snmp4j.smi.OctetString) ScopedPDU(org.snmp4j.ScopedPDU) PDU(org.snmp4j.PDU) ScopedPDU(org.snmp4j.ScopedPDU) DefaultTcpTransportMapping(org.snmp4j.transport.DefaultTcpTransportMapping) Snmp(org.snmp4j.Snmp) DefaultUdpTransportMapping(org.snmp4j.transport.DefaultUdpTransportMapping) OID(org.snmp4j.smi.OID) UserTarget(org.snmp4j.UserTarget) UsmUser(org.snmp4j.security.UsmUser) CommunityTarget(org.snmp4j.CommunityTarget) USM(org.snmp4j.security.USM)

Example 12 with USM

use of org.snmp4j.security.USM in project camel by apache.

the class SnmpProducer method doStart.

@Override
protected void doStart() throws Exception {
    super.doStart();
    this.targetAddress = GenericAddress.parse(this.endpoint.getAddress());
    LOG.debug("targetAddress: {}", targetAddress);
    this.usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
    SecurityModels.getInstance().addSecurityModel(this.usm);
    // setting up target
    this.target = new CommunityTarget();
    this.target.setCommunity(new OctetString(endpoint.getSnmpCommunity()));
    this.target.setAddress(this.targetAddress);
    this.target.setRetries(this.endpoint.getRetries());
    this.target.setTimeout(this.endpoint.getTimeout());
    this.target.setVersion(this.endpoint.getSnmpVersion());
    this.pdu = new PDU();
    for (OID oid : this.endpoint.getOids()) {
        this.pdu.add(new VariableBinding(oid));
    }
    this.pdu.setErrorIndex(0);
    this.pdu.setErrorStatus(0);
    this.pdu.setMaxRepetitions(0);
    this.pdu.setType(PDU.GET);
}
Also used : OctetString(org.snmp4j.smi.OctetString) PDU(org.snmp4j.PDU) OID(org.snmp4j.smi.OID) CommunityTarget(org.snmp4j.CommunityTarget) VariableBinding(org.snmp4j.smi.VariableBinding) USM(org.snmp4j.security.USM)

Example 13 with USM

use of org.snmp4j.security.USM in project camel by apache.

the class SnmpTrapProducer method doStart.

@Override
protected void doStart() throws Exception {
    super.doStart();
    this.targetAddress = GenericAddress.parse(this.endpoint.getAddress());
    LOG.debug("targetAddress: {}", targetAddress);
    this.usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
    SecurityModels.getInstance().addSecurityModel(this.usm);
    // setting up target
    this.target = new CommunityTarget();
    this.target.setCommunity(new OctetString(endpoint.getSnmpCommunity()));
    this.target.setAddress(this.targetAddress);
    this.target.setRetries(this.endpoint.getRetries());
    this.target.setTimeout(this.endpoint.getTimeout());
    this.target.setVersion(this.endpoint.getSnmpVersion());
}
Also used : OctetString(org.snmp4j.smi.OctetString) CommunityTarget(org.snmp4j.CommunityTarget) USM(org.snmp4j.security.USM)

Example 14 with USM

use of org.snmp4j.security.USM in project opennms by OpenNMS.

the class Snmp4JStrategy method initialize.

/**
 * Initialize for v3 communications
 */
private static void initialize() {
    if (s_initialized) {
        return;
    }
    SNMP4JSettings.setEnterpriseID(5813);
    // USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
    m_usm = new USM();
    SecurityModels.getInstance().addSecurityModel(m_usm);
    // agent bugs
    if (System.getProperty("org.snmp4j.smisyntaxes", null) != null) {
        SNMP4JSettings.setExtensibilityEnabled(true);
    }
    if (Boolean.getBoolean("org.opennms.snmp.snmp4j.forwardRuntimeExceptions")) {
        SNMP4JSettings.setForwardRuntimeExceptions(true);
    }
    SNMP4JSettings.setAllowSNMPv2InV1(Boolean.getBoolean("org.opennms.snmp.snmp4j.allowSNMPv2InV1"));
    SNMP4JSettings.setNoGetBulk(Boolean.getBoolean("org.opennms.snmp.snmp4j.noGetBulk"));
    // NMS-9223: This call can be expensive, and is synchronized
    // so we perform it only once during initialization
    SecurityProtocols.getInstance().addDefaultProtocols();
    s_initialized = true;
}
Also used : USM(org.snmp4j.security.USM)

Example 15 with USM

use of org.snmp4j.security.USM in project opennms by OpenNMS.

the class BrocadeMibIT method setUp.

@Before
public void setUp() throws Exception {
    // Create a global USM that all client calls will use
    SNMP4JSettings.setEnterpriseID(5813);
    m_usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
    SecurityModels.getInstance().addSecurityModel(m_usm);
    try {
        m_agent = MockSnmpAgent.createAgentAndRun(classPathResource("brocadeTestData1.properties"), str(InetAddress.getLocalHost()) + "/0");
    } catch (Throwable e) {
        m_agent = MockSnmpAgent.createAgentAndRun(classPathResource("brocadeTestData1.properties"), str(InetAddressUtils.ONE_TWENTY_SEVEN) + "/0");
    }
    m_requestedVarbinds = new ArrayList<>();
}
Also used : OctetString(org.snmp4j.smi.OctetString) USM(org.snmp4j.security.USM) Before(org.junit.Before)

Aggregations

USM (org.snmp4j.security.USM)17 OctetString (org.snmp4j.smi.OctetString)14 DefaultUdpTransportMapping (org.snmp4j.transport.DefaultUdpTransportMapping)10 Snmp (org.snmp4j.Snmp)9 UsmUser (org.snmp4j.security.UsmUser)7 ScopedPDU (org.snmp4j.ScopedPDU)6 UserTarget (org.snmp4j.UserTarget)6 PDU (org.snmp4j.PDU)5 UdpAddress (org.snmp4j.smi.UdpAddress)5 CommunityTarget (org.snmp4j.CommunityTarget)4 ResponseEvent (org.snmp4j.event.ResponseEvent)4 OID (org.snmp4j.smi.OID)4 IOException (java.io.IOException)3 Before (org.junit.Before)3 VariableBinding (org.snmp4j.smi.VariableBinding)3 MessageDispatcherImpl (org.snmp4j.MessageDispatcherImpl)2 TransportMapping (org.snmp4j.TransportMapping)2 MPv1 (org.snmp4j.mp.MPv1)2 MPv2c (org.snmp4j.mp.MPv2c)2 MPv3 (org.snmp4j.mp.MPv3)2