Search in sources :

Example 66 with SnmpAgentConfig

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

the class SnmpPeerFactoryTest method testGetConfigWithValidLocation.

/**
 * Below tests for a valid/invalid location match
 *
 * @throws UnknownHostException
 */
public void testGetConfigWithValidLocation() throws UnknownHostException {
    SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr("192.168.0.50"), "MINION");
    assertNotNull(agentConfig);
    assertEquals(agentConfig.getVersion(), SnmpAgentConfig.VERSION2C);
    assertEquals(2500, agentConfig.getTimeout());
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig)

Example 67 with SnmpAgentConfig

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

the class ConfigureSnmpTest method testSnmpEventInfoClassWithRangeSuperSettingDefRanges.

/**
 * Tests getting the correct SNMP Peer after merging a new range that super sets a current range.
 *
 * @throws UnknownHostException
 */
public void testSnmpEventInfoClassWithRangeSuperSettingDefRanges() throws UnknownHostException {
    final String addr1 = "192.168.99.1";
    final String addr2 = "192.168.108.254";
    SnmpAgentConfig agent = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr(addr1));
    assertEquals(SnmpAgentConfig.VERSION1, agent.getVersion());
    EventBuilder bldr = createConfigureSnmpEventBuilder(addr1, addr2);
    SnmpEventInfo info = new SnmpEventInfo(bldr.getEvent());
    info.setReadCommunityString("opennmsrules");
    SnmpPeerFactory.getInstance().define(info);
    agent = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr(addr1));
    assertEquals(InetAddressUtils.str(agent.getAddress()), addr1);
    assertEquals(SnmpAgentConfig.VERSION1, agent.getVersion());
    assertEquals(m_startingDefCount, SnmpPeerFactory.getInstance().getSnmpConfig().getDefinitions().size());
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) EventBuilder(org.opennms.netmgt.model.events.EventBuilder)

Example 68 with SnmpAgentConfig

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

the class ConfigureSnmpTest method testSnmpEventInfoClassWithRangeReplacingSpecific.

/**
 * This test should remove the specific 192.168.0.5 from the first definition and
 * replace it with a range 192.168.0.5 - 192.168.0.7.
 *
 * @throws UnknownHostException
 */
public void testSnmpEventInfoClassWithRangeReplacingSpecific() throws UnknownHostException {
    final String addr1 = "192.168.0.5";
    final String addr2 = "192.168.0.7";
    SnmpAgentConfig agent = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr(addr1));
    assertEquals(SnmpAgentConfig.VERSION2C, agent.getVersion());
    EventBuilder bldr = createConfigureSnmpEventBuilder(addr1, addr2);
    SnmpEventInfo info = new SnmpEventInfo(bldr.getEvent());
    info.setVersion("v2c");
    SnmpPeerFactory.getInstance().define(info);
    agent = SnmpPeerFactory.getInstance().getAgentConfig(InetAddressUtils.addr(addr1));
    assertEquals(InetAddressUtils.str(agent.getAddress()), addr1);
    assertEquals(SnmpAgentConfig.VERSION2C, agent.getVersion());
    assertEquals(m_startingDefCount, SnmpPeerFactory.getInstance().getSnmpConfig().getDefinitions().size());
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) EventBuilder(org.opennms.netmgt.model.events.EventBuilder)

Example 69 with SnmpAgentConfig

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

the class TcaDataIT method testTracker.

/**
 * Test tracker.
 *
 * @throws Exception the exception
 */
@Test
public void testTracker() throws Exception {
    InetAddress localhost = InetAddressUtils.getInetAddress(TEST_IP_ADDRESS);
    SnmpAgentConfig agentConfig = SnmpPeerFactory.getInstance().getAgentConfig(localhost);
    TcaData data = new TcaData(localhost);
    try (SnmpWalker walker = SnmpUtils.createWalker(agentConfig, "TcaCollector for " + localhost, data)) {
        walker.start();
        walker.waitFor();
        Assert.assertFalse(walker.failed());
    }
    Assert.assertFalse(data.isEmpty());
    Assert.assertEquals(2, data.getEntries().size());
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) SnmpWalker(org.opennms.netmgt.snmp.SnmpWalker) InetAddress(java.net.InetAddress) Test(org.junit.Test)

Example 70 with SnmpAgentConfig

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

the class TcaProtocolCollector method collect.

@Override
public CollectionJob collect(final CollectionJob collectionJob) {
    logger.info("TcaProtocolCollector is collecting collectionJob '{}'", collectionJob);
    SnmpAgentConfig snmpAgentConfig = SnmpAgentConfig.parseProtocolConfigurationString(collectionJob.getProtocolConfiguration());
    List<Collectable> trackers = new ArrayList<>();
    for (final String metricObjId : collectionJob.getAllMetrics()) {
        final String keyword = metricObjId.substring(metricObjId.lastIndexOf("_") + 1);
        final SnmpObjId requestOid = SnmpObjId.get(metricObjId.substring(0, metricObjId.lastIndexOf("_")));
        SnmpObjId base = requestOid.getPrefix(requestOid.length() - 1);
        int lastId = requestOid.getLastSubId();
        SingleInstanceTracker instanceTracker = new SingleInstanceTracker(base, new SnmpInstId(lastId)) {

            @Override
            protected void storeResult(SnmpResult result) {
                logger.trace("Collected SnmpValue '{}'", result);
                SnmpValue value = result.getValue();
                String compositeResult = getCompositeValue(keyword, value.toDisplayString());
                collectionJob.setMetricValue(metricObjId, "int32", compositeResult);
            }

            @Override
            public void setFailed(boolean failed) {
                super.setFailed(failed);
                logger.trace("Collection Failed for metricObjId '{}'", metricObjId);
                collectionJob.setMetricValue(metricObjId, "unknown", null);
            }

            @Override
            public void setTimedOut(boolean timedOut) {
                super.setTimedOut(timedOut);
                logger.trace("Collection timedOut for metricObjId '{}'", metricObjId);
                collectionJob.setMetricValue(metricObjId, "unknown", null);
            }
        };
        trackers.add(instanceTracker);
    }
    CollectionTracker tracker = new AggregateTracker(trackers);
    try (SnmpWalker walker = m_snmpStrategy.createWalker(snmpAgentConfig, "SnmpProtocolCollector for " + snmpAgentConfig.getAddress(), tracker)) {
        walker.start();
        try {
            walker.waitFor();
        } catch (InterruptedException e) {
            logger.error("Interuppted while waiting for collector. Results may be incomplete.", e);
        }
    }
    return collectionJob;
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) Collectable(org.opennms.netmgt.snmp.Collectable) SnmpWalker(org.opennms.netmgt.snmp.SnmpWalker) ArrayList(java.util.ArrayList) SnmpObjId(org.opennms.netmgt.snmp.SnmpObjId) SnmpValue(org.opennms.netmgt.snmp.SnmpValue) SingleInstanceTracker(org.opennms.netmgt.snmp.SingleInstanceTracker) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) CollectionTracker(org.opennms.netmgt.snmp.CollectionTracker) SnmpResult(org.opennms.netmgt.snmp.SnmpResult) AggregateTracker(org.opennms.netmgt.snmp.AggregateTracker)

Aggregations

SnmpAgentConfig (org.opennms.netmgt.snmp.SnmpAgentConfig)120 InetAddress (java.net.InetAddress)31 Test (org.junit.Test)31 JUnitSnmpAgents (org.opennms.core.test.snmp.annotations.JUnitSnmpAgents)23 ArrayList (java.util.ArrayList)22 SnmpObjId (org.opennms.netmgt.snmp.SnmpObjId)21 SnmpValue (org.opennms.netmgt.snmp.SnmpValue)21 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)16 PollStatus (org.opennms.netmgt.poller.PollStatus)14 Map (java.util.Map)11 ExecutionException (java.util.concurrent.ExecutionException)9 ParameterMap (org.opennms.core.utils.ParameterMap)9 SnmpWalker (org.opennms.netmgt.snmp.SnmpWalker)8 Date (java.util.Date)7 LldpLink (org.opennms.netmgt.model.LldpLink)7 OnmsNode (org.opennms.netmgt.model.OnmsNode)7 HashMap (java.util.HashMap)6 List (java.util.List)5 LldpLocPortGetter (org.opennms.netmgt.enlinkd.snmp.LldpLocPortGetter)4 LldpRemTableTracker (org.opennms.netmgt.enlinkd.snmp.LldpRemTableTracker)4