Search in sources :

Example 16 with SnmpObjId

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

the class SnmpValueTest method testSnmpObjId.

@Test
public void testSnmpObjId() {
    for (final SnmpValueFactory factory : m_factories) {
        final String oid = ".1.3.6.1.4.1.2925.4.5.2.1.1";
        final SnmpObjId id = SnmpObjId.get(oid);
        final SnmpValue value = factory.getObjectId(id);
        final String className = factory.getClass().getName();
        assertTrue(className + ": getInetAddress isDisplayable should be true", value.isDisplayable());
        assertEquals(className + ": getObjectId to SnmpObjId should return " + oid, id, value.toSnmpObjId());
        assertEquals(className + ": getObjectId to String should return " + oid, oid, value.toString());
        assertEquals(className + ": getObjectId to DisplayString should return " + oid, oid, value.toDisplayString());
        try {
            value.toInt();
            fail(className + ": getObjectId to int should throw an IllegalArgumentException");
        } catch (final IllegalArgumentException e) {
        /* expected */
        }
        try {
            value.toLong();
            fail(className + ": getObjectId to long should throw an IllegalArgumentException");
        } catch (final IllegalArgumentException e) {
        /* expected */
        }
        try {
            value.toBigInteger();
            fail(className + ": getObjectId to BigInteger should throw an IllegalArgumentException");
        } catch (final IllegalArgumentException e) {
        /* expected */
        }
        try {
            value.toHexString();
            fail(className + ": getObjectId to HexString should throw an IllegalArgumentException");
        } catch (final IllegalArgumentException e) {
        /* expected */
        }
        try {
            value.toInetAddress();
            fail(className + ": getObjectId to InetAddress 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) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) Test(org.junit.Test)

Example 17 with SnmpObjId

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

the class TrapdIT method testSnmpV2cTrapSend.

@Test
public void testSnmpV2cTrapSend() throws Exception {
    String localhost = "127.0.0.1";
    InetAddress localAddr = InetAddressUtils.addr(localhost);
    SnmpObjId enterpriseId = SnmpObjId.get(".1.3.6.1.4.1.5813");
    SnmpObjId trapOID = SnmpObjId.get(enterpriseId, new SnmpInstId(1));
    SnmpTrapBuilder pdu = SnmpUtils.getV2TrapBuilder();
    pdu.addVarBind(SnmpObjId.get(".1.3.6.1.2.1.1.3.0"), SnmpUtils.getValueFactory().getTimeTicks(0));
    pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.1.0"), SnmpUtils.getValueFactory().getObjectId(trapOID));
    pdu.addVarBind(SnmpObjId.get(".1.3.6.1.6.3.1.1.4.3.0"), SnmpUtils.getValueFactory().getObjectId(enterpriseId));
    EventBuilder defaultTrapBuilder = new EventBuilder("uei.opennms.org/default/trap", "trapd");
    defaultTrapBuilder.setInterface(localAddr);
    defaultTrapBuilder.setSnmpVersion("v2c");
    m_mockEventIpcManager.getEventAnticipator().anticipateEvent(defaultTrapBuilder.getEvent());
    EventBuilder newSuspectBuilder = new EventBuilder(EventConstants.NEW_SUSPECT_INTERFACE_EVENT_UEI, "trapd");
    newSuspectBuilder.setInterface(localAddr);
    m_mockEventIpcManager.getEventAnticipator().anticipateEvent(newSuspectBuilder.getEvent());
    pdu.send(localhost, m_trapdConfig.getSnmpTrapPort(), "public");
    // Allow time for Trapd and Eventd to do their magic
    Thread.sleep(5000);
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) InetAddress(java.net.InetAddress) SnmpTrapBuilder(org.opennms.netmgt.snmp.SnmpTrapBuilder) Test(org.junit.Test)

Example 18 with SnmpObjId

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

the class SnmpStoreTest method testStoreResultWithValueThenEndOfMibView.

public void testStoreResultWithValueThenEndOfMibView() {
    String baseOid = ".1.3.6.1.2.1.31.1.1.1.18";
    String ifAliasName = "ifAlias";
    String ifAliasValue = "Foo!";
    SnmpStore store = new SnmpStore(new NamedSnmpVar[] { new NamedSnmpVar(NamedSnmpVar.SNMPOCTETSTRING, ifAliasName, baseOid, 18) });
    SnmpObjId base = SnmpObjId.get(baseOid);
    SnmpInstId inst = new SnmpInstId("1");
    store.storeResult(new SnmpResult(base, inst, SnmpUtils.getValueFactory().getOctetString(ifAliasValue.getBytes())));
    store.storeResult(new SnmpResult(base, inst, SnmpUtils.getValueFactory().getValue(SnmpValue.SNMP_END_OF_MIB, null)));
    assertEquals("ifAlias value", ifAliasValue, store.getDisplayString(ifAliasName));
}
Also used : NamedSnmpVar(org.opennms.netmgt.snmp.NamedSnmpVar) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) SnmpStore(org.opennms.netmgt.snmp.SnmpStore) SnmpResult(org.opennms.netmgt.snmp.SnmpResult)

Example 19 with SnmpObjId

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

the class EventdStresser method createBuilder.

public static SnmpTrapBuilder createBuilder() throws IllegalArgumentException {
    SnmpV1TrapBuilder builder = SnmpUtils.getV1TrapBuilder();
    builder.setAgentAddress(m_agentAddress);
    SnmpObjId enterpriseOid = SnmpObjId.get(".1.3.6.1.4.1.5813.1");
    builder.setEnterprise(enterpriseOid);
    builder.setTimeStamp(0);
    builder.setGeneric(6);
    builder.setSpecific(1);
    builder.setTimeStamp(1);
    // dbid
    SnmpObjId dbIdOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.1");
    SnmpValue dbIdValue = SnmpUtils.getStrategy().getValueFactory().getOctetString("-1".getBytes());
    builder.addVarBind(dbIdOid, dbIdValue);
    // distPoller
    SnmpObjId distPollerOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.2");
    SnmpValue distPollerValue = SnmpUtils.getStrategy().getValueFactory().getOctetString(m_agentAddress.getHostAddress().getBytes());
    builder.addVarBind(distPollerOid, distPollerValue);
    // create-time
    SnmpObjId createTimeOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.3");
    Date createTime = Calendar.getInstance().getTime();
    String formattedTime = DateFormat.getDateTimeInstance().format(createTime);
    SnmpValue createTimeValue = SnmpUtils.getStrategy().getValueFactory().getOctetString(formattedTime.getBytes());
    builder.addVarBind(createTimeOid, createTimeValue);
    // master-station
    SnmpObjId masterStationOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.4");
    SnmpValue masterStationValue = SnmpUtils.getStrategy().getValueFactory().getOctetString(m_trapSink.getHostAddress().getBytes());
    builder.addVarBind(masterStationOid, masterStationValue);
    // uei
    SnmpObjId ueiOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.5");
    SnmpValue ueiValue = SnmpUtils.getStrategy().getValueFactory().getOctetString("uei.opennms.org/test/EventdStressTest".getBytes());
    builder.addVarBind(ueiOid, ueiValue);
    // source,
    SnmpObjId sourceOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.6");
    SnmpValue sourceValue = SnmpUtils.getStrategy().getValueFactory().getOctetString("EventdStresser".getBytes());
    builder.addVarBind(sourceOid, sourceValue);
    // nodeid,
    SnmpObjId nodeIdOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.7");
    SnmpValue nodeIdValue = SnmpUtils.getStrategy().getValueFactory().getOctetString("1".getBytes());
    builder.addVarBind(nodeIdOid, nodeIdValue);
    // time,
    SnmpObjId timeOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.8");
    SnmpValue timeValue = SnmpUtils.getStrategy().getValueFactory().getOctetString(formattedTime.getBytes());
    builder.addVarBind(timeOid, timeValue);
    // host,
    SnmpObjId hostOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.9");
    SnmpValue hostValue = SnmpUtils.getStrategy().getValueFactory().getOctetString(m_agentAddress.getHostAddress().getBytes());
    builder.addVarBind(hostOid, hostValue);
    // interface,
    SnmpObjId interfaceOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.10");
    SnmpValue interfaceValue = SnmpUtils.getStrategy().getValueFactory().getOctetString(m_agentAddress.getHostAddress().getBytes());
    builder.addVarBind(interfaceOid, interfaceValue);
    // snmphost,
    SnmpObjId snmpHostOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.11");
    SnmpValue snmpValue = SnmpUtils.getStrategy().getValueFactory().getOctetString(m_agentAddress.getHostAddress().getBytes());
    builder.addVarBind(snmpHostOid, snmpValue);
    // service,
    SnmpObjId serviceOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.12");
    SnmpValue serviceValue = SnmpUtils.getStrategy().getValueFactory().getOctetString("SNMP".getBytes());
    builder.addVarBind(serviceOid, serviceValue);
    // descr,
    SnmpObjId descrOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.13");
    SnmpValue descrValue = SnmpUtils.getStrategy().getValueFactory().getOctetString("Eventd Stressor Trap".getBytes());
    builder.addVarBind(descrOid, descrValue);
    // logmsg,
    SnmpObjId logMsgOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.14");
    SnmpValue logMsgValue = SnmpUtils.getStrategy().getValueFactory().getOctetString("Eventd Stressor Trap".getBytes());
    builder.addVarBind(logMsgOid, logMsgValue);
    // severity,
    SnmpObjId severityOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.15");
    SnmpValue severityValue = SnmpUtils.getStrategy().getValueFactory().getOctetString("4".getBytes());
    builder.addVarBind(severityOid, severityValue);
    // pathoutage,
    SnmpObjId pathOutageOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.16");
    SnmpValue pathOutageValue = SnmpUtils.getStrategy().getValueFactory().getOctetString("NA".getBytes());
    builder.addVarBind(pathOutageOid, pathOutageValue);
    // operinst,
    SnmpObjId operInstOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.17");
    SnmpValue operInstValue = SnmpUtils.getStrategy().getValueFactory().getOctetString("Ignore".getBytes());
    builder.addVarBind(operInstOid, operInstValue);
    // ifresolve,
    SnmpObjId ifResolveOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.18");
    SnmpValue ifResolveValue = SnmpUtils.getStrategy().getValueFactory().getOctetString("NA".getBytes());
    builder.addVarBind(ifResolveOid, ifResolveValue);
    // nodelabel
    SnmpObjId nodeLabelOid = SnmpObjId.get(".1.3.6.1.4.1.5813.2.19");
    String nodeLabel;
    nodeLabel = m_agentAddress.getCanonicalHostName();
    SnmpValue nodeLabelValue = SnmpUtils.getStrategy().getValueFactory().getOctetString(nodeLabel.getBytes());
    builder.addVarBind(nodeLabelOid, nodeLabelValue);
    return builder;
}
Also used : SnmpV1TrapBuilder(org.opennms.netmgt.snmp.SnmpV1TrapBuilder) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) Date(java.util.Date)

Example 20 with SnmpObjId

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

the class OmsaStorageMonitor method poll.

/** {@inheritDoc} */
@Override
public PollStatus poll(MonitoredService svc, Map<String, Object> parameters) {
    PollStatus status = PollStatus.available();
    InetAddress ipaddr = svc.getAddress();
    final StringBuffer returnValue = new StringBuffer();
    SnmpAgentConfig agentConfig = configureAgent(svc, parameters);
    Integer virtualDiskNumber = ParameterMap.getKeyedInteger(parameters, "virtualDiskNumber", 1);
    LOG.debug("poll: service= SNMP address= {}", agentConfig);
    final String hostAddress = InetAddressUtils.str(ipaddr);
    try {
        LOG.debug("OMSAStorageMonitor.poll: SnmpAgentConfig address: {}", agentConfig);
        SnmpObjId virtualDiskRollUpStatusSnmpObject = SnmpObjId.get(virtualDiskRollUpStatus + "." + virtualDiskNumber);
        SnmpValue virtualDiskRollUpStatus = SnmpUtils.get(agentConfig, virtualDiskRollUpStatusSnmpObject);
        if (virtualDiskRollUpStatus == null || virtualDiskRollUpStatus.isNull()) {
            LOG.debug("SNMP poll failed: no results, addr={} oid={}", hostAddress, virtualDiskRollUpStatusSnmpObject);
            return PollStatus.unavailable();
        }
        if (virtualDiskRollUpStatus.toInt() != 3) {
            // array or one of its components is not happy lets find out which 	
            // XXX should degraded be the virtualDiskState ? 
            returnValue.append("log vol(").append(virtualDiskNumber).append(") degraded");
            SnmpObjId arrayDiskLogicalConnectionVirtualDiskNumberSnmpObject = SnmpObjId.get(arrayDiskLogicalConnectionVirtualDiskNumber);
            Map<SnmpInstId, SnmpValue> arrayDisks = SnmpUtils.getOidValues(agentConfig, "OMSAStorageMonitor", arrayDiskLogicalConnectionVirtualDiskNumberSnmpObject);
            SnmpObjId arrayDiskLogicalConnectionArrayDiskNumberSnmpObject = SnmpObjId.get(arrayDiskLogicalConnectionArrayDiskNumber);
            Map<SnmpInstId, SnmpValue> arrayDiskConnectionNumber = SnmpUtils.getOidValues(agentConfig, "OMSAStorageMonitor", arrayDiskLogicalConnectionArrayDiskNumberSnmpObject);
            for (Map.Entry<SnmpInstId, SnmpValue> disk : arrayDisks.entrySet()) {
                LOG.debug("OMSAStorageMonitor :: arrayDiskNembers=", disk.getValue());
                if (disk.getValue().toInt() == virtualDiskNumber) {
                    LOG.debug("OMSAStorageMonitor :: Disk Found! ");
                    LOG.debug("OMSAStorageMonitor :: Found This Array Disk Value {}", disk.getKey());
                    SnmpObjId arrayDiskStateSnmpObject = SnmpObjId.get(arrayDiskState + "." + arrayDiskConnectionNumber.get(disk.getKey()));
                    SnmpValue diskValue = SnmpUtils.get(agentConfig, arrayDiskStateSnmpObject);
                    LOG.debug("OmsaStorageMonitor :: Disk State=", diskValue);
                    if (diskValue.toInt() != 3) {
                        String arrayDiskState = getArrayDiskStatus(diskValue);
                        SnmpObjId arrayDiskNexusIDSnmpObject = SnmpObjId.get(arrayDiskNexusID + "." + disk.getKey().toString());
                        SnmpValue nexusValue = SnmpUtils.get(agentConfig, arrayDiskNexusIDSnmpObject);
                        returnValue.append(" phy drv(").append(nexusValue).append(") ").append(arrayDiskState);
                    }
                }
            }
            return PollStatus.unavailable(returnValue.toString());
        }
    } catch (NumberFormatException e) {
        String reason = "Number operator used on a non-number " + e.getMessage();
        LOG.debug(reason);
        status = PollStatus.unavailable(reason);
    } catch (IllegalArgumentException e) {
        String reason = "Invalid SNMP Criteria: " + e.getMessage();
        LOG.debug(reason);
        status = PollStatus.unavailable(reason);
    } catch (Throwable t) {
        String reason = "Unexpected exception during SNMP poll of interface " + hostAddress;
        LOG.debug(reason, t);
        status = PollStatus.unavailable(reason);
    }
    return status;
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) PollStatus(org.opennms.netmgt.poller.PollStatus) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) InetAddress(java.net.InetAddress) Map(java.util.Map) ParameterMap(org.opennms.core.utils.ParameterMap)

Aggregations

SnmpObjId (org.opennms.netmgt.snmp.SnmpObjId)71 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)48 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)22 SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)20 InetAddress (java.net.InetAddress)18 ArrayList (java.util.ArrayList)15 Map (java.util.Map)14 Test (org.junit.Test)13 PollStatus (org.opennms.netmgt.poller.PollStatus)12 PDU (org.snmp4j.PDU)10 ParameterMap (org.opennms.core.utils.ParameterMap)9 SnmpResult (org.opennms.netmgt.snmp.SnmpResult)7 List (java.util.List)5 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)4 ExecutionException (java.util.concurrent.ExecutionException)4 SnmpTrapBuilder (org.opennms.netmgt.snmp.SnmpTrapBuilder)4 SnmpWalker (org.opennms.netmgt.snmp.SnmpWalker)4 IOException (java.io.IOException)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3