Search in sources :

Example 11 with Integer32

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

the class MockSnmpAgent method addCommunities.

/**
 * {@inheritDoc}
 */
@Override
protected void addCommunities(SnmpCommunityMIB communityMIB) {
    Variable[] com2sec = new Variable[] { // community name
    new OctetString("public"), // security name
    new OctetString("public"), // local engine ID
    getAgent().getContextEngineID(), // default context name
    new OctetString(), // transport tag
    new OctetString(), // storage type
    new Integer32(StorageType.nonVolatile), // row status
    new Integer32(RowStatus.active) };
    SnmpCommunityEntryRow row = communityMIB.getSnmpCommunityEntry().createRow(new OctetString("public2public").toSubIndex(true), com2sec);
    communityMIB.getSnmpCommunityEntry().addRow(row);
}
Also used : OctetString(org.snmp4j.smi.OctetString) SnmpCommunityEntryRow(org.snmp4j.agent.mo.snmp.SnmpCommunityMIB.SnmpCommunityEntryRow) Integer32(org.snmp4j.smi.Integer32) Variable(org.snmp4j.smi.Variable)

Example 12 with Integer32

use of org.snmp4j.smi.Integer32 in project camel by apache.

the class SnmpProducer method doStop.

@Override
protected void doStop() throws Exception {
    super.doStop();
    try {
        SecurityModels.getInstance().removeSecurityModel(new Integer32(this.usm.getID()));
    } finally {
        this.targetAddress = null;
        this.usm = null;
        this.target = null;
        this.pdu = null;
    }
}
Also used : Integer32(org.snmp4j.smi.Integer32)

Example 13 with Integer32

use of org.snmp4j.smi.Integer32 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)

Example 14 with Integer32

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

the class Snmp4JDummyTransportTest method makePdu.

private static final PDU makePdu() {
    PDU snmp4JV2cTrapPdu = new PDUv1();
    OID oid = new OID(".1.3.6.1.2.1.1.3.0");
    snmp4JV2cTrapPdu.add(new VariableBinding(SnmpConstants.sysUpTime, new TimeTicks(5000)));
    snmp4JV2cTrapPdu.add(new VariableBinding(SnmpConstants.snmpTrapOID, new OID(oid)));
    snmp4JV2cTrapPdu.add(new VariableBinding(SnmpConstants.snmpTrapAddress, new IpAddress("127.0.0.1")));
    snmp4JV2cTrapPdu.add(new VariableBinding(new OID(oid), new OctetString("Trap Msg v2-1")));
    snmp4JV2cTrapPdu.add(new VariableBinding(new OID(oid), new OctetString("Trap Msg v2-2")));
    snmp4JV2cTrapPdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.0"), new OctetString("Trap v1 msg-1")));
    snmp4JV2cTrapPdu.add(new VariableBinding(new OID(".1.3.6.1.2.1.1.3"), new OctetString("Trap v1 msg-2")));
    snmp4JV2cTrapPdu.add(new VariableBinding(new OID(".1.3.6.1.6.3.1.1.4.1.1"), new OctetString("Trap v1 msg-3")));
    snmp4JV2cTrapPdu.add(new VariableBinding(new OID(".1.3.6.1.4.1.733.6.3.18.1.5.0"), new Integer32(1)));
    snmp4JV2cTrapPdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.0"), new Null()));
    snmp4JV2cTrapPdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.1"), new Null(128)));
    snmp4JV2cTrapPdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.2"), new Null(129)));
    snmp4JV2cTrapPdu.add(new VariableBinding(new OID("1.3.6.1.2.1.1.5.3"), new Null(130)));
    snmp4JV2cTrapPdu.setType(PDU.V1TRAP);
    return snmp4JV2cTrapPdu;
}
Also used : PDU(org.snmp4j.PDU) OctetString(org.snmp4j.smi.OctetString) Integer32(org.snmp4j.smi.Integer32) Null(org.snmp4j.smi.Null) TimeTicks(org.snmp4j.smi.TimeTicks) IpAddress(org.snmp4j.smi.IpAddress) PDUv1(org.snmp4j.PDUv1) OID(org.snmp4j.smi.OID) VariableBinding(org.snmp4j.smi.VariableBinding)

Example 15 with Integer32

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

the class MockAgentTest method setUp.

@Override
protected void setUp() throws Exception {
    MockUtil.println("------------ Begin Test " + getName() + " --------------------------");
    MockLogAppender.setupLogging();
    m_network = new MockNetwork();
    m_network.setCriticalService("ICMP");
    m_network.addNode(1, "Router");
    m_network.addInterface("192.168.1.1");
    m_network.addService("ICMP");
    m_network.addService("SMTP");
    m_network.addInterface("192.168.1.2");
    m_network.addService("ICMP");
    m_network.addService("SMTP");
    m_network.addNode(2, "Server");
    m_network.addInterface("192.168.1.3");
    m_network.addService("ICMP");
    m_network.addService("HTTP");
    m_network.addInterface("192.168.1.2");
    MapSubAgent systemGroup = new MapSubAgent("1.3.6.1.2.1.1");
    systemGroup.put("1.0", new OctetString("MockAgent!"));
    systemGroup.put("2.0", new OID("1.3.6.1.4.1.5813.1"));
    systemGroup.put("3.0", new TimeTicks(1234));
    systemGroup.put("4.0", new OctetString("Mr. Personality"));
    systemGroup.put("5.0", new OctetString("mockhost"));
    systemGroup.put("6.0", new OctetString("Wouldn't you like to know"));
    // what happened to 7.0?
    MapSubAgent interfaces = new MapSubAgent("1.3.6.1.2.1.2");
    interfaces.put("1.0", new Integer32(2));
    try {
        m_proxy = new MockProxy(9161);
    } catch (Throwable t) {
        throw new Exception("Could not start MockProxy on 9161: " + t, t);
    }
    MockAgent agent = new MockAgent();
    agent.addSubAgent(systemGroup);
    agent.addSubAgent(interfaces);
    m_proxy.addAgent(agent);
}
Also used : OctetString(org.snmp4j.smi.OctetString) Integer32(org.snmp4j.smi.Integer32) TimeTicks(org.snmp4j.smi.TimeTicks) OID(org.snmp4j.smi.OID) IOException(java.io.IOException)

Aggregations

Integer32 (org.snmp4j.smi.Integer32)21 Test (org.junit.Test)12 OctetString (org.snmp4j.smi.OctetString)11 OID (org.snmp4j.smi.OID)7 PDU (org.snmp4j.PDU)4 TimeTicks (org.snmp4j.smi.TimeTicks)4 VariableBinding (org.snmp4j.smi.VariableBinding)4 IpAddress (org.snmp4j.smi.IpAddress)3 Null (org.snmp4j.smi.Null)3 Variable (org.snmp4j.smi.Variable)3 IOException (java.io.IOException)1 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)1 DecimalFormat (java.text.DecimalFormat)1 Date (java.util.Date)1 Matcher (java.util.regex.Matcher)1 SnmpBindingProvider (org.openhab.binding.snmp.SnmpBindingProvider)1 Command (org.openhab.core.types.Command)1 BindingConfigParseException (org.openhab.model.item.binding.BindingConfigParseException)1 DynamicVariable (org.opennms.mock.snmp.responder.DynamicVariable)1 SnmpErrorStatusException (org.opennms.mock.snmp.responder.SnmpErrorStatusException)1