Search in sources :

Example 1 with Counter32

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

the class BrocadeMibIT method testGetNextMultipleVarbinds.

@Test
public void testGetNextMultipleVarbinds() throws Exception {
    request(".1.3.6.1.4.1.1588.2.1.1.1.6.2.1.11").andExpect(".1.3.6.1.4.1.1588.2.1.1.1.6.2.1.11.1", SMIConstants.SYNTAX_COUNTER32, new Counter32(128350705));
    doGetNext();
    m_agent.getUsm().setEngineBoots(15);
    byte[] hexString = new byte[] { (byte) 0x11, (byte) 0x00, (byte) 0x33, (byte) 0x44, (byte) 0x55, (byte) 0x66, (byte) 0x77, (byte) 0x88 };
    request(".1.3.6.1.4.1.1588.2.1.1.1.6.2.1.11").andExpect(".1.3.6.1.4.1.1588.2.1.1.1.6.2.1.11.1", SMIConstants.SYNTAX_COUNTER32, new Counter32(128350705));
    request(".1.3.6.1.4.1.1588.2.1.1.1.6.2.1.12").andExpect(".1.3.6.1.4.1.1588.2.1.1.1.6.2.1.12.1", SMIConstants.SYNTAX_COUNTER32, new Counter32(3180401803L));
    request(".1.3.6.1.4.1.1588.2.1.1.1.6.2.1.34").andExpect(".1.3.6.1.4.1.1588.2.1.1.1.6.2.1.34.1", SMIConstants.SYNTAX_OCTET_STRING, new OctetString(hexString));
    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.3.6.1.4.1.1588.2.1.1.1.6.2.1.11.1").andExpect(".1.3.6.1.4.1.1588.2.1.1.1.6.2.1.11.2", SMIConstants.SYNTAX_COUNTER32, new Counter32(1047537430));
    doGetNext();
}
Also used : Counter32(org.snmp4j.smi.Counter32) OctetString(org.snmp4j.smi.OctetString) Test(org.junit.Test)

Example 2 with Counter32

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

the class BrocadeMibIT method testGetNext.

@Test
public void testGetNext() throws Exception {
    request(".1.3.6.1.4.1.1588.2.1.1.1.6.2.1.11").andExpect(".1.3.6.1.4.1.1588.2.1.1.1.6.2.1.11.1", SMIConstants.SYNTAX_COUNTER32, new Counter32(128350705));
    doGetNext();
    request(".1.3.6.1.4.1.1588.2.1.1.1.6.2.1.11.1").andExpect(".1.3.6.1.4.1.1588.2.1.1.1.6.2.1.11.2", SMIConstants.SYNTAX_COUNTER32, new Counter32(1047537430));
    doGetNext();
}
Also used : Counter32(org.snmp4j.smi.Counter32) Test(org.junit.Test)

Example 3 with Counter32

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

the class PropertiesBackedManagedObject method getVariableFromValueString.

/**
 * <p>getVariableFromValueString</p>
 *
 * @param oidStr a {@link java.lang.String} object.
 * @param valStr a {@link java.lang.String} object.
 * @return a {@link org.snmp4j.smi.Variable} object.
 * @throws SnmpErrorStatusException
 */
private Variable getVariableFromValueString(String oidStr, String valStr) throws SnmpErrorStatusException {
    Variable newVar;
    if (valStr.startsWith("Wrong Type")) {
        String newVal = valStr.replaceFirst("Wrong Type \\(should be .*\\): ", "");
        s_log.error("Bad Mib walk has value: '" + valStr + "' using '" + newVal + "'");
        valStr = newVal;
    }
    if ("\"\"".equals(valStr)) {
        newVar = new Null();
    } else {
        String moTypeStr = valStr.substring(0, valStr.indexOf(':'));
        String moValStr = valStr.substring(valStr.indexOf(':') + 2);
        try {
            if (moTypeStr.equals("STRING")) {
                if (moValStr.startsWith("\"") && moValStr.endsWith("\"")) {
                    moValStr = moValStr.substring(1, moValStr.length() - 1);
                }
                newVar = new OctetString(moValStr);
            } else if (moTypeStr.equals("Hex-STRING")) {
                newVar = OctetString.fromHexString(moValStr.trim().replace(' ', ':'));
            } else if (moTypeStr.equals("INTEGER")) {
                newVar = new Integer32(Integer.parseInt(moValStr));
            } else if (moTypeStr.equals("Gauge32")) {
                newVar = new Gauge32(Long.parseLong(moValStr));
            } else if (moTypeStr.equals("Counter32")) {
                // a 32 bit counter can be > 2 ^ 31, which is > INTEGER_MAX
                newVar = new Counter32(Long.parseLong(moValStr));
            } else if (moTypeStr.equals("Counter64")) {
                newVar = new Counter64(Long.parseLong(moValStr));
            } else if (moTypeStr.equals("Timeticks")) {
                Integer ticksInt = Integer.parseInt(moValStr.substring(moValStr.indexOf('(') + 1, moValStr.indexOf(')')));
                newVar = new TimeTicks(ticksInt);
            } else if (moTypeStr.equals("OID")) {
                newVar = new OID(moValStr);
            } else if (moTypeStr.equals("IpAddress")) {
                newVar = new IpAddress(moValStr.trim());
            } else if (moTypeStr.equals("Network Address")) {
                newVar = OctetString.fromHexString(moValStr.trim());
            } else if (moTypeStr.equals("Responder")) {
                newVar = handleDynamicVariable(oidStr, moValStr);
            } else {
                // newVar = new OctetString(moValStr);
                throw new IllegalArgumentException("Unrecognized SNMP Type " + moTypeStr);
            }
        } catch (SnmpErrorStatusException e) {
            throw e;
        } catch (Throwable t) {
            throw new UndeclaredThrowableException(t, "Could not convert value '" + moValStr + "' of type '" + moTypeStr + "' to SNMP object for OID " + oidStr);
        }
    }
    return newVar;
}
Also used : OctetString(org.snmp4j.smi.OctetString) Null(org.snmp4j.smi.Null) DynamicVariable(org.opennms.mock.snmp.responder.DynamicVariable) Variable(org.snmp4j.smi.Variable) TimeTicks(org.snmp4j.smi.TimeTicks) OctetString(org.snmp4j.smi.OctetString) OID(org.snmp4j.smi.OID) Counter32(org.snmp4j.smi.Counter32) Integer32(org.snmp4j.smi.Integer32) Counter64(org.snmp4j.smi.Counter64) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) Gauge32(org.snmp4j.smi.Gauge32) SnmpErrorStatusException(org.opennms.mock.snmp.responder.SnmpErrorStatusException) IpAddress(org.snmp4j.smi.IpAddress)

Aggregations

Counter32 (org.snmp4j.smi.Counter32)3 Test (org.junit.Test)2 OctetString (org.snmp4j.smi.OctetString)2 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 DynamicVariable (org.opennms.mock.snmp.responder.DynamicVariable)1 SnmpErrorStatusException (org.opennms.mock.snmp.responder.SnmpErrorStatusException)1 Counter64 (org.snmp4j.smi.Counter64)1 Gauge32 (org.snmp4j.smi.Gauge32)1 Integer32 (org.snmp4j.smi.Integer32)1 IpAddress (org.snmp4j.smi.IpAddress)1 Null (org.snmp4j.smi.Null)1 OID (org.snmp4j.smi.OID)1 TimeTicks (org.snmp4j.smi.TimeTicks)1 Variable (org.snmp4j.smi.Variable)1