Search in sources :

Example 6 with SnmpValue

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

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

the class V1TrapInformation method getSnmpVarBindDTO.

@Override
public SnmpVarBindDTO getSnmpVarBindDTO(int i) {
    SnmpObjId name = SnmpObjId.get(getVarBindAt(i).getName().getIdentifiers());
    SnmpValue value = new JoeSnmpValue(getVarBindAt(i).getValue());
    return new SnmpVarBindDTO(name, value);
}
Also used : SnmpVarBindDTO(org.opennms.netmgt.snmp.SnmpVarBindDTO) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId)

Example 8 with SnmpValue

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

the class V2TrapInformation method getSnmpVarBindDTO.

@Override
public SnmpVarBindDTO getSnmpVarBindDTO(int i) {
    if (i < 2) {
        if (i == 0) {
            LOG.debug("Skipping processing of varbind it is the sysuptime and the first varbind, it is not processed as a parm per RFC2089");
        } else {
            LOG.debug("Skipping processing of varbind it is the trap OID and the second varbind, it is not processed as a parm per RFC2089");
        }
        return null;
    } else {
        SnmpObjId name = SnmpObjId.get(getVarBindAt(i).getName().getIdentifiers());
        SnmpValue value = new JoeSnmpValue(getVarBindAt(i).getValue());
        return new SnmpVarBindDTO(name, value);
    }
}
Also used : SnmpVarBindDTO(org.opennms.netmgt.snmp.SnmpVarBindDTO) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId)

Example 9 with SnmpValue

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

the class SnmpValueTest method testInetAddress.

@Test
public void testInetAddress() {
    for (final SnmpValueFactory factory : m_factories) {
        final InetAddress address = InetAddressUtils.addr("192.168.0.1");
        final SnmpValue value = factory.getIpAddress(address);
        final String className = factory.getClass().getName();
        assertTrue(className + ": getInetAddress isDisplayable should be true", value.isDisplayable());
        assertEquals(className + ": getInetAddress to InetAddress should return 192.168.0.1", address, value.toInetAddress());
        assertEquals(className + ": getInetAddress to String should return 192.168.0.1", "192.168.0.1", value.toString());
        assertEquals(className + ": getInetAddress to DisplayString should return 192.168.0.1", "192.168.0.1", value.toDisplayString());
        try {
            value.toInt();
            fail(className + ": getInetAddress to int should throw an IllegalArgumentException");
        } catch (final IllegalArgumentException e) {
        /* expected */
        }
        try {
            value.toLong();
            fail(className + ": getInetAddress to long should throw an IllegalArgumentException");
        } catch (final IllegalArgumentException e) {
        /* expected */
        }
        try {
            value.toBigInteger();
            fail(className + ": getInetAddress to BigInteger should throw an IllegalArgumentException");
        } catch (final IllegalArgumentException e) {
        /* expected */
        }
        try {
            value.toHexString();
            fail(className + ": getInetAddress to HexString should throw an IllegalArgumentException");
        } catch (final IllegalArgumentException e) {
        /* expected */
        }
        try {
            value.toSnmpObjId();
            fail(className + ": getInetAddress to SnmpObjId should throw an IllegalArgumentException");
        } catch (final IllegalArgumentException e) {
        /* expected */
        }
    }
}
Also used : SnmpValueFactory(org.opennms.netmgt.snmp.SnmpValueFactory) JoeSnmpValueFactory(org.opennms.netmgt.snmp.joesnmp.JoeSnmpValueFactory) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 10 with SnmpValue

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

the class SnmpValueTest method testNull.

@Test
public void testNull() {
    for (final SnmpValueFactory factory : m_factories) {
        final SnmpValue value = factory.getNull();
        final String factoryClassName = factory.getClass().getName();
        assertFalse(factoryClassName + ": Null isDisplayable should be false", value.isDisplayable());
        assertTrue(factoryClassName + ": Null isNull should be true", value.isNull());
        assertFalse(factoryClassName + ": Null isEndOfMib should be false", value.isEndOfMib());
        assertFalse(factoryClassName + ": Null isError should be false", value.isError());
    }
}
Also used : SnmpValueFactory(org.opennms.netmgt.snmp.SnmpValueFactory) JoeSnmpValueFactory(org.opennms.netmgt.snmp.joesnmp.JoeSnmpValueFactory) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) Test(org.junit.Test)

Aggregations

SnmpValue (org.opennms.netmgt.snmp.SnmpValue)112 Test (org.junit.Test)57 SnmpObjId (org.opennms.netmgt.snmp.SnmpObjId)47 SnmpValueFactory (org.opennms.netmgt.snmp.SnmpValueFactory)24 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)21 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)20 InetAddress (java.net.InetAddress)19 Map (java.util.Map)14 PollStatus (org.opennms.netmgt.poller.PollStatus)14 JoeSnmpValueFactory (org.opennms.netmgt.snmp.joesnmp.JoeSnmpValueFactory)12 ArrayList (java.util.ArrayList)11 ParameterMap (org.opennms.core.utils.ParameterMap)9 Parm (org.opennms.netmgt.xml.event.Parm)9 PDU (org.snmp4j.PDU)9 AttributeGroupType (org.opennms.netmgt.collection.api.AttributeGroupType)8 SnmpResult (org.opennms.netmgt.snmp.SnmpResult)8 LinkedHashMap (java.util.LinkedHashMap)7 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)5 HashMap (java.util.HashMap)4 NumericAttributeType (org.opennms.netmgt.collectd.NumericAttributeType)4