Search in sources :

Example 36 with OctetString

use of org.snmp4j.smi.OctetString in project opennms by OpenNMS.

the class BrocadeMibIT method sendRequestV3.

private PDU sendRequestV3(PDU pdu) throws IOException {
    PDU response;
    OctetString userId = new OctetString("opennmsUser");
    OctetString pw = new OctetString("0p3nNMSv3");
    UserTarget target = new UserTarget();
    target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
    target.setSecurityName(userId);
    target.setAddress(new UdpAddress(m_agent.getInetAddress(), m_agent.getPort()));
    target.setVersion(SnmpConstants.version3);
    target.setTimeout(5000);
    TransportMapping<UdpAddress> transport = null;
    try {
        USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
        SecurityModels.getInstance().addSecurityModel(usm);
        transport = new DefaultUdpTransportMapping();
        Snmp snmp = new Snmp(transport);
        UsmUser user = new UsmUser(userId, AuthMD5.ID, pw, PrivDES.ID, pw);
        snmp.getUSM().addUser(userId, user);
        transport.listen();
        ResponseEvent e = snmp.send(pdu, target);
        response = e.getResponse();
    } finally {
        if (transport != null) {
            transport.close();
        }
    }
    return response;
}
Also used : ScopedPDU(org.snmp4j.ScopedPDU) PDU(org.snmp4j.PDU) OctetString(org.snmp4j.smi.OctetString) UdpAddress(org.snmp4j.smi.UdpAddress) Snmp(org.snmp4j.Snmp) DefaultUdpTransportMapping(org.snmp4j.transport.DefaultUdpTransportMapping) ResponseEvent(org.snmp4j.event.ResponseEvent) UserTarget(org.snmp4j.UserTarget) UsmUser(org.snmp4j.security.UsmUser) USM(org.snmp4j.security.USM)

Example 37 with OctetString

use of org.snmp4j.smi.OctetString in project opennms by OpenNMS.

the class LLDPMibIT method sendRequestV3.

private PDU sendRequestV3(PDU pdu) throws IOException {
    PDU response;
    OctetString userId = new OctetString("opennmsUser");
    OctetString pw = new OctetString("0p3nNMSv3");
    UserTarget target = new UserTarget();
    target.setSecurityLevel(SecurityLevel.AUTH_PRIV);
    target.setSecurityName(userId);
    target.setAddress(new UdpAddress(m_agent.getInetAddress(), m_agent.getPort()));
    target.setVersion(SnmpConstants.version3);
    if (m_timeout > 0) {
        target.setTimeout(m_timeout);
    } else {
        target.setTimeout(5000);
    }
    TransportMapping<UdpAddress> transport = null;
    try {
        USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);
        SecurityModels.getInstance().addSecurityModel(usm);
        transport = new DefaultUdpTransportMapping();
        Snmp snmp = new Snmp(transport);
        UsmUser user = new UsmUser(userId, AuthMD5.ID, pw, PrivDES.ID, pw);
        snmp.getUSM().addUser(userId, user);
        transport.listen();
        ResponseEvent e = snmp.send(pdu, target);
        response = e.getResponse();
    } finally {
        if (transport != null) {
            transport.close();
        }
    }
    return response;
}
Also used : ScopedPDU(org.snmp4j.ScopedPDU) PDU(org.snmp4j.PDU) OctetString(org.snmp4j.smi.OctetString) UdpAddress(org.snmp4j.smi.UdpAddress) Snmp(org.snmp4j.Snmp) DefaultUdpTransportMapping(org.snmp4j.transport.DefaultUdpTransportMapping) ResponseEvent(org.snmp4j.event.ResponseEvent) UserTarget(org.snmp4j.UserTarget) UsmUser(org.snmp4j.security.UsmUser) USM(org.snmp4j.security.USM)

Example 38 with OctetString

use of org.snmp4j.smi.OctetString in project opennms by OpenNMS.

the class LLDPMibIT method sendRequestV1V2.

private PDU sendRequestV1V2(PDU pdu, int version) throws Exception {
    PDU response;
    CommunityTarget target = new CommunityTarget();
    target.setCommunity(new OctetString("public"));
    target.setAddress(new UdpAddress(m_agent.getInetAddress(), m_agent.getPort()));
    target.setVersion(version);
    if (m_timeout > 0) {
        target.setTimeout(m_timeout);
    }
    TransportMapping<UdpAddress> transport = null;
    try {
        transport = new DefaultUdpTransportMapping();
        Snmp snmp = new Snmp(transport);
        transport.listen();
        ResponseEvent e = snmp.send(pdu, target);
        response = e.getResponse();
    } finally {
        if (transport != null) {
            transport.close();
        }
    }
    return response;
}
Also used : ScopedPDU(org.snmp4j.ScopedPDU) PDU(org.snmp4j.PDU) OctetString(org.snmp4j.smi.OctetString) UdpAddress(org.snmp4j.smi.UdpAddress) Snmp(org.snmp4j.Snmp) DefaultUdpTransportMapping(org.snmp4j.transport.DefaultUdpTransportMapping) ResponseEvent(org.snmp4j.event.ResponseEvent) CommunityTarget(org.snmp4j.CommunityTarget)

Example 39 with OctetString

use of org.snmp4j.smi.OctetString in project opennms by OpenNMS.

the class LLDPMibIT method testGetNextMultipleVarbinds.

@Test
public void testGetNextMultipleVarbinds() throws Exception {
    request(".1.0.8802.1.1.2.1.3.1").andExpect(".1.0.8802.1.1.2.1.3.1.0", SMIConstants.SYNTAX_INTEGER32, new Integer32(4));
    doGetNext();
    m_agent.getUsm().setEngineBoots(15);
    byte[] hexString = new byte[] { (byte) 0x80, (byte) 0x71, (byte) 0x1F, (byte) 0x8F, (byte) 0xAF, (byte) 0xC0 };
    request(".1.0.8802.1.1.2.1.3.1").andExpect(".1.0.8802.1.1.2.1.3.1.0", SMIConstants.SYNTAX_INTEGER32, new Integer32(4));
    request(".1.0.8802.1.1.2.1.3.2").andExpect(".1.0.8802.1.1.2.1.3.2.0", SMIConstants.SYNTAX_OCTET_STRING, new OctetString(hexString));
    request(".1.0.8802.1.1.2.1.3.3").andExpect(".1.0.8802.1.1.2.1.3.3.0", SMIConstants.SYNTAX_OCTET_STRING, new OctetString("penrose-mx480".getBytes()));
    doGetNext();
    // This statement breaks the internal state of the SNMP4J agent
    // m_agent.getUsm().setLocalEngine(m_agent.getUsm().getLocalEngineID(), 15, 200);
    m_agent.getUsm().removeEngineTime(m_usm.getLocalEngineID());
    m_usm.removeEngineTime(m_agent.getUsm().getLocalEngineID());
    request(".1.0.8802.1.1.2.1.3.1").andExpect(".1.0.8802.1.1.2.1.3.1.0", SMIConstants.SYNTAX_INTEGER32, new Integer32(4));
    doGetNext();
}
Also used : OctetString(org.snmp4j.smi.OctetString) Integer32(org.snmp4j.smi.Integer32) Test(org.junit.Test)

Example 40 with OctetString

use of org.snmp4j.smi.OctetString in project cloudstack by apache.

the class SnmpHelper method createPDU.

private PDU createPDU(SnmpTrapInfo snmpTrapInfo) {
    PDU trap = new PDU();
    trap.setType(PDU.TRAP);
    int alertType = snmpTrapInfo.getAlertType() + 1;
    if (alertType > 0) {
        trap.add(new VariableBinding(SnmpConstants.snmpTrapOID, getOID(CsSnmpConstants.TRAPS_PREFIX + alertType)));
        if (snmpTrapInfo.getDataCenterId() != 0) {
            trap.add(new VariableBinding(getOID(CsSnmpConstants.DATA_CENTER_ID), new UnsignedInteger32(snmpTrapInfo.getDataCenterId())));
        }
        if (snmpTrapInfo.getPodId() != 0) {
            trap.add(new VariableBinding(getOID(CsSnmpConstants.POD_ID), new UnsignedInteger32(snmpTrapInfo.getPodId())));
        }
        if (snmpTrapInfo.getClusterId() != 0) {
            trap.add(new VariableBinding(getOID(CsSnmpConstants.CLUSTER_ID), new UnsignedInteger32(snmpTrapInfo.getClusterId())));
        }
        if (snmpTrapInfo.getMessage() != null) {
            trap.add(new VariableBinding(getOID(CsSnmpConstants.MESSAGE), new OctetString(snmpTrapInfo.getMessage())));
        } else {
            throw new CloudRuntimeException(" What is the use of alert without message ");
        }
        if (snmpTrapInfo.getGenerationTime() != null) {
            trap.add(new VariableBinding(getOID(CsSnmpConstants.GENERATION_TIME), new OctetString(snmpTrapInfo.getGenerationTime().toString())));
        } else {
            trap.add(new VariableBinding(getOID(CsSnmpConstants.GENERATION_TIME)));
        }
    } else {
        throw new CloudRuntimeException(" Invalid alert Type ");
    }
    return trap;
}
Also used : PDU(org.snmp4j.PDU) OctetString(org.snmp4j.smi.OctetString) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) UnsignedInteger32(org.snmp4j.smi.UnsignedInteger32) VariableBinding(org.snmp4j.smi.VariableBinding)

Aggregations

OctetString (org.snmp4j.smi.OctetString)40 PDU (org.snmp4j.PDU)17 OID (org.snmp4j.smi.OID)17 Snmp (org.snmp4j.Snmp)14 DefaultUdpTransportMapping (org.snmp4j.transport.DefaultUdpTransportMapping)13 CommunityTarget (org.snmp4j.CommunityTarget)11 ScopedPDU (org.snmp4j.ScopedPDU)11 USM (org.snmp4j.security.USM)11 UdpAddress (org.snmp4j.smi.UdpAddress)11 VariableBinding (org.snmp4j.smi.VariableBinding)11 Test (org.junit.Test)10 UsmUser (org.snmp4j.security.UsmUser)8 Integer32 (org.snmp4j.smi.Integer32)8 ResponseEvent (org.snmp4j.event.ResponseEvent)7 IOException (java.io.IOException)5 TrapInformation (org.opennms.netmgt.snmp.TrapInformation)5 Address (org.snmp4j.smi.Address)5 TimeTicks (org.snmp4j.smi.TimeTicks)5 InetAddress (java.net.InetAddress)4 PDUv1 (org.snmp4j.PDUv1)4