Search in sources :

Example 1 with SnmpParameters

use of org.opennms.protocols.snmp.SnmpParameters in project opennms by OpenNMS.

the class JoeSnmpStrategy method getNext.

@Override
public SnmpValue[] getNext(SnmpAgentConfig snmpAgentConfig, SnmpObjId[] oids) {
    JoeSnmpAgentConfig agentConfig = new JoeSnmpAgentConfig(snmpAgentConfig);
    SnmpSession session = null;
    SnmpValue[] values = { null };
    try {
        SnmpPeer peer = createPeer(agentConfig);
        SnmpParameters params = new SnmpParameters();
        setParameters(agentConfig, params);
        peer.setParameters(params);
        configurePeer(peer, agentConfig);
        session = new SnmpSession(peer);
        SnmpObjectId[] jOids = convertOids(oids);
        SnmpSyntax[] results = session.getNext(jOids);
        values = convertSnmpSyntaxs(results);
    } catch (SocketException e) {
        LOG.error("Could not create JoeSNMP session using AgentConfig: {}", agentConfig);
    } finally {
        if (session != null) {
            session.close();
        }
    }
    return values;
}
Also used : SnmpSyntax(org.opennms.protocols.snmp.SnmpSyntax) SocketException(java.net.SocketException) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpParameters(org.opennms.protocols.snmp.SnmpParameters) SnmpObjectId(org.opennms.protocols.snmp.SnmpObjectId) SnmpSession(org.opennms.protocols.snmp.SnmpSession) SnmpPeer(org.opennms.protocols.snmp.SnmpPeer)

Example 2 with SnmpParameters

use of org.opennms.protocols.snmp.SnmpParameters in project opennms by OpenNMS.

the class JoeSnmpStrategy method get.

@Override
public SnmpValue[] get(SnmpAgentConfig snmpAgentConfig, SnmpObjId[] oids) {
    JoeSnmpAgentConfig agentConfig = new JoeSnmpAgentConfig(snmpAgentConfig);
    SnmpSession session = null;
    SnmpValue[] values = { null };
    try {
        SnmpPeer peer = createPeer(agentConfig);
        SnmpParameters params = new SnmpParameters();
        setParameters(agentConfig, params);
        peer.setParameters(params);
        configurePeer(peer, agentConfig);
        session = new SnmpSession(peer);
        SnmpObjectId[] jOids = convertOids(oids);
        SnmpSyntax[] results = session.get(jOids);
        values = convertSnmpSyntaxs(results);
    } catch (SocketException e) {
        LOG.error("Could not create JoeSNMP session using AgentConfig: {}", agentConfig);
    } finally {
        if (session != null) {
            session.close();
        }
    }
    return values;
}
Also used : SnmpSyntax(org.opennms.protocols.snmp.SnmpSyntax) SocketException(java.net.SocketException) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpParameters(org.opennms.protocols.snmp.SnmpParameters) SnmpObjectId(org.opennms.protocols.snmp.SnmpObjectId) SnmpSession(org.opennms.protocols.snmp.SnmpSession) SnmpPeer(org.opennms.protocols.snmp.SnmpPeer)

Example 3 with SnmpParameters

use of org.opennms.protocols.snmp.SnmpParameters in project opennms by OpenNMS.

the class JoeSnmpStrategy method set.

@Override
public SnmpValue[] set(SnmpAgentConfig snmpAgentConfig, SnmpObjId[] oids, SnmpValue[] values) {
    JoeSnmpAgentConfig agentConfig = new JoeSnmpAgentConfig(snmpAgentConfig);
    SnmpSession session = null;
    SnmpSyntax[] syntaxvalues = new SnmpSyntax[values.length];
    for (int i = 0; i < values.length; i++) {
        syntaxvalues[i] = new JoeSnmpValue(values[i].getType(), values[i].getBytes()).getSnmpSyntax();
    }
    values = null;
    try {
        SnmpPeer peer = createPeer(agentConfig);
        SnmpParameters params = new SnmpParameters();
        setParameters(agentConfig, params);
        peer.setParameters(params);
        configurePeer(peer, agentConfig);
        session = new SnmpSession(peer);
        SnmpObjectId[] jOids = convertOids(oids);
        SnmpSyntax[] results = session.set(jOids, syntaxvalues);
        values = convertSnmpSyntaxs(results);
    } catch (SocketException e) {
        LOG.error("Could not create JoeSNMP session using AgentConfig: {}", agentConfig);
    } finally {
        if (session != null) {
            session.close();
        }
    }
    return values;
}
Also used : SnmpSyntax(org.opennms.protocols.snmp.SnmpSyntax) SocketException(java.net.SocketException) SnmpParameters(org.opennms.protocols.snmp.SnmpParameters) SnmpObjectId(org.opennms.protocols.snmp.SnmpObjectId) SnmpSession(org.opennms.protocols.snmp.SnmpSession) SnmpPeer(org.opennms.protocols.snmp.SnmpPeer)

Example 4 with SnmpParameters

use of org.opennms.protocols.snmp.SnmpParameters in project opennms by OpenNMS.

the class JoeSnmpStrategy method send.

public static void send(final String destAddr, final int destPort, final String community, final SnmpPduRequest pdu) throws Exception {
    SnmpTrapSession trapSession = getTrapSession();
    SnmpPeer peer = new SnmpPeer(InetAddress.getByName(destAddr), destPort);
    SnmpParameters parms = new SnmpParameters(community);
    parms.setVersion(SnmpSMI.SNMPV2);
    peer.setParameters(parms);
    trapSession.send(peer, pdu);
}
Also used : SnmpTrapSession(org.opennms.protocols.snmp.SnmpTrapSession) SnmpParameters(org.opennms.protocols.snmp.SnmpParameters) SnmpPeer(org.opennms.protocols.snmp.SnmpPeer)

Example 5 with SnmpParameters

use of org.opennms.protocols.snmp.SnmpParameters in project opennms by OpenNMS.

the class JoeSnmpStrategy method send.

public static void send(String destAddr, int destPort, String community, SnmpPduTrap trap) throws Exception {
    SnmpTrapSession trapSession = getTrapSession();
    SnmpPeer peer = new SnmpPeer(InetAddress.getByName(destAddr), destPort);
    SnmpParameters parms = new SnmpParameters(community);
    parms.setVersion(SnmpSMI.SNMPV1);
    peer.setParameters(parms);
    trapSession.send(peer, trap);
}
Also used : SnmpTrapSession(org.opennms.protocols.snmp.SnmpTrapSession) SnmpParameters(org.opennms.protocols.snmp.SnmpParameters) SnmpPeer(org.opennms.protocols.snmp.SnmpPeer)

Aggregations

SnmpParameters (org.opennms.protocols.snmp.SnmpParameters)5 SnmpPeer (org.opennms.protocols.snmp.SnmpPeer)5 SocketException (java.net.SocketException)3 SnmpObjectId (org.opennms.protocols.snmp.SnmpObjectId)3 SnmpSession (org.opennms.protocols.snmp.SnmpSession)3 SnmpSyntax (org.opennms.protocols.snmp.SnmpSyntax)3 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)2 SnmpTrapSession (org.opennms.protocols.snmp.SnmpTrapSession)2