Search in sources :

Example 16 with CollectionSet

use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.

the class CollectableServiceTest method canWrapResourcesWithTimekeeper.

/**
 * Validates that we can successfully wrap collection sets with a custom time-keeper,
 * allowing us to override the timestamp of the attributes within the collection set.
 */
@Test
public void canWrapResourcesWithTimekeeper() throws CollectionInitializationException, CollectionException, IOException, RrdException {
    System.setProperty(CollectableService.USE_COLLECTION_START_TIME_SYS_PROP, Boolean.TRUE.toString());
    createCollectableService();
    long collectionDelayInSecs = 2;
    when(spec.collect(any())).then(new Answer<CollectionSet>() {

        @Override
        public CollectionSet answer(InvocationOnMock invocation) throws InterruptedException {
            Thread.sleep(collectionDelayInSecs * 1000);
            CollectionAgent agent = (CollectionAgent) invocation.getArguments()[0];
            NodeLevelResource nodeResource = new NodeLevelResource(agent.getNodeId());
            return new CollectionSetBuilder(agent).withNumericAttribute(nodeResource, "mibGroup", "myCounter", 1000, AttributeType.COUNTER).build();
        }
    });
    File nodeDir = fileAnticipator.expecting(getSnmpRrdDirectory(), "1");
    File jrbFile = fileAnticipator.expecting(nodeDir, "myCounter" + rrdStrategy.getDefaultFileExtension());
    fileAnticipator.expecting(nodeDir, "myCounter" + ".meta");
    long beforeInMs = System.currentTimeMillis();
    service.run();
    long afterInMs = System.currentTimeMillis();
    // Quick sanity check
    assertTrue(String.format("Delay was not succesfully applied (delay was %d).", beforeInMs - afterInMs), afterInMs - beforeInMs >= collectionDelayInSecs * 1000);
    // Verify the last update time match the start of the collection time
    RrdDb rrdDb = new RrdDb(jrbFile);
    long lastUpdateTimeInSecs = rrdDb.getLastUpdateTime();
    long beforeInSecs = Math.floorDiv(beforeInMs, 1000);
    long afterInSecs = Math.floorDiv(afterInMs, 1000) + 1;
    assertTrue("Last update was before the collector was invoked!", lastUpdateTimeInSecs >= beforeInSecs);
    assertTrue("Last update was too long after the collector was invoked!", lastUpdateTimeInSecs < (afterInSecs - (collectionDelayInSecs / 2d)));
}
Also used : CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) InvocationOnMock(org.mockito.invocation.InvocationOnMock) RrdDb(org.jrobin.core.RrdDb) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) File(java.io.File) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) Test(org.junit.Test)

Example 17 with CollectionSet

use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.

the class HttpCollectorIT method testCollect.

/**
 * Test method for {@link org.opennms.netmgt.collectd.HttpCollector#collect(
 *   org.opennms.netmgt.collection.api.CollectionAgent, org.opennms.netmgt.model.events.EventProxy, Map)}.
 */
@Test
@JUnitHttpServer(port = 10342, vhosts = { "127.0.0.1" })
@JUnitCollector(datacollectionConfig = "/org/opennms/netmgt/config/http-datacollection-config.xml", datacollectionType = "http", anticipateRrds = { "1/documentCount", "1/greatAnswer", "1/someNumber" }, anticipateFiles = { "1/strings.properties" })
public final void testCollect() throws Exception {
    CollectionSet collectionSet = m_collectionSpecification.collect(m_collectionAgent);
    assertEquals("collection status", CollectionStatus.SUCCEEDED, collectionSet.getStatus());
    CollectorTestUtils.persistCollectionSet(m_rrdStrategy, m_resourceStorageDao, m_collectionSpecification, collectionSet);
}
Also used : CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) JUnitCollector(org.opennms.core.collection.test.JUnitCollector) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 18 with CollectionSet

use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.

the class SnmpCollectorIT method testBrocadeCollect.

@Test
@Transactional
@JUnitCollector(datacollectionConfig = "/org/opennms/netmgt/config/datacollection-brocade-config.xml", datacollectionType = "snmp", anticipateRrds = { "1/brocadeFCPortIndex/1/swFCPortTxWords", "1/brocadeFCPortIndex/1/swFCPortRxWords", "1/brocadeFCPortIndex/2/swFCPortTxWords", "1/brocadeFCPortIndex/2/swFCPortRxWords", "1/brocadeFCPortIndex/3/swFCPortTxWords", "1/brocadeFCPortIndex/3/swFCPortRxWords", "1/brocadeFCPortIndex/4/swFCPortTxWords", "1/brocadeFCPortIndex/4/swFCPortRxWords", "1/brocadeFCPortIndex/5/swFCPortTxWords", "1/brocadeFCPortIndex/5/swFCPortRxWords", "1/brocadeFCPortIndex/6/swFCPortTxWords", "1/brocadeFCPortIndex/6/swFCPortRxWords", "1/brocadeFCPortIndex/7/swFCPortTxWords", "1/brocadeFCPortIndex/7/swFCPortRxWords", "1/brocadeFCPortIndex/8/swFCPortTxWords", "1/brocadeFCPortIndex/8/swFCPortRxWords" }, anticipateFiles = { "1", "1/brocadeFCPortIndex", "1/brocadeFCPortIndex/1/strings.properties", "1/brocadeFCPortIndex/1", "1/brocadeFCPortIndex/2/strings.properties", "1/brocadeFCPortIndex/2", "1/brocadeFCPortIndex/3/strings.properties", "1/brocadeFCPortIndex/3", "1/brocadeFCPortIndex/4/strings.properties", "1/brocadeFCPortIndex/4", "1/brocadeFCPortIndex/5/strings.properties", "1/brocadeFCPortIndex/5", "1/brocadeFCPortIndex/6/strings.properties", "1/brocadeFCPortIndex/6", "1/brocadeFCPortIndex/7/strings.properties", "1/brocadeFCPortIndex/7", "1/brocadeFCPortIndex/8/strings.properties", "1/brocadeFCPortIndex/8" })
@JUnitSnmpAgent(resource = "/org/opennms/netmgt/snmp/brocadeTestData1.properties")
public void testBrocadeCollect() throws Exception {
    // now do the actual collection
    CollectionSet collectionSet = m_collectionSpecification.collect(m_collectionAgent);
    assertEquals("collection status", CollectionStatus.SUCCEEDED, collectionSet.getStatus());
    CollectorTestUtils.persistCollectionSet(m_rrdStrategy, m_resourceStorageDao, m_collectionSpecification, collectionSet);
    System.err.println("FIRST COLLECTION FINISHED");
    // need a one second time elapse to update the RRD
    Thread.sleep(1000);
    // try collecting again
    assertEquals("collection status", CollectionStatus.SUCCEEDED, m_collectionSpecification.collect(m_collectionAgent).getStatus());
    System.err.println("SECOND COLLECTION FINISHED");
}
Also used : CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) JUnitCollector(org.opennms.core.collection.test.JUnitCollector) Test(org.junit.Test) JUnitSnmpAgent(org.opennms.core.test.snmp.annotations.JUnitSnmpAgent) Transactional(org.springframework.transaction.annotation.Transactional)

Example 19 with CollectionSet

use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.

the class SnmpCollectorIT method testCollect.

@Test
@JUnitCollector(datacollectionConfig = "/org/opennms/netmgt/config/datacollection-config.xml", datacollectionType = "snmp", anticipateFiles = { "1", "1/fw0" }, anticipateRrds = { "1/tcpActiveOpens", "1/tcpAttemptFails", "1/tcpPassiveOpens", "1/tcpRetransSegs", "1/tcpCurrEstab", "1/tcpEstabResets", "1/tcpInErrors", "1/tcpInSegs", "1/tcpOutRsts", "1/tcpOutSegs", "1/fw0/ifInDiscards", "1/fw0/ifInErrors", "1/fw0/ifInNUcastpkts", "1/fw0/ifInOctets", "1/fw0/ifInUcastpkts", "1/fw0/ifOutErrors", "1/fw0/ifOutNUcastPkts", "1/fw0/ifOutOctets", "1/fw0/ifOutUcastPkts" })
@JUnitSnmpAgent(resource = "/org/opennms/netmgt/snmp/snmpTestData1.properties")
public void testCollect() throws Exception {
    System.setProperty("org.opennms.netmgt.collectd.SnmpCollector.limitCollectionToInstances", "true");
    // now do the actual collection
    CollectionSet collectionSet = m_collectionSpecification.collect(m_collectionAgent);
    assertEquals("collection status", CollectionStatus.SUCCEEDED, collectionSet.getStatus());
    CollectorTestUtils.persistCollectionSet(m_rrdStrategy, m_resourceStorageDao, m_collectionSpecification, collectionSet);
    System.err.println("FIRST COLLECTION FINISHED");
    // need a one second time elapse to update the RRD
    Thread.sleep(1000);
    // try collecting again
    assertEquals("collection status", CollectionStatus.SUCCEEDED, m_collectionSpecification.collect(m_collectionAgent).getStatus());
    System.err.println("SECOND COLLECTION FINISHED");
}
Also used : CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) JUnitCollector(org.opennms.core.collection.test.JUnitCollector) Test(org.junit.Test) JUnitSnmpAgent(org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)

Example 20 with CollectionSet

use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.

the class SnmpCollectorIT method testBug2447_GenericIndexedOnlyCollect.

@Test
@Transactional
@JUnitCollector(datacollectionConfig = "/org/opennms/netmgt/config/datacollection-brocade-no-ifaces-config.xml", datacollectionType = "snmp", anticipateRrds = { "1/brocadeFCPortIndex/1/swFCPortTxWords", "1/brocadeFCPortIndex/1/swFCPortRxWords", "1/brocadeFCPortIndex/2/swFCPortTxWords", "1/brocadeFCPortIndex/2/swFCPortRxWords", "1/brocadeFCPortIndex/3/swFCPortTxWords", "1/brocadeFCPortIndex/3/swFCPortRxWords", "1/brocadeFCPortIndex/4/swFCPortTxWords", "1/brocadeFCPortIndex/4/swFCPortRxWords", "1/brocadeFCPortIndex/5/swFCPortTxWords", "1/brocadeFCPortIndex/5/swFCPortRxWords", "1/brocadeFCPortIndex/6/swFCPortTxWords", "1/brocadeFCPortIndex/6/swFCPortRxWords", "1/brocadeFCPortIndex/7/swFCPortTxWords", "1/brocadeFCPortIndex/7/swFCPortRxWords", "1/brocadeFCPortIndex/8/swFCPortTxWords", "1/brocadeFCPortIndex/8/swFCPortRxWords" }, anticipateFiles = { "1", "1/brocadeFCPortIndex", "1/brocadeFCPortIndex/1/strings.properties", "1/brocadeFCPortIndex/1", "1/brocadeFCPortIndex/2/strings.properties", "1/brocadeFCPortIndex/2", "1/brocadeFCPortIndex/3/strings.properties", "1/brocadeFCPortIndex/3", "1/brocadeFCPortIndex/4/strings.properties", "1/brocadeFCPortIndex/4", "1/brocadeFCPortIndex/5/strings.properties", "1/brocadeFCPortIndex/5", "1/brocadeFCPortIndex/6/strings.properties", "1/brocadeFCPortIndex/6", "1/brocadeFCPortIndex/7/strings.properties", "1/brocadeFCPortIndex/7", "1/brocadeFCPortIndex/8/strings.properties", "1/brocadeFCPortIndex/8" })
@JUnitSnmpAgent(resource = "/org/opennms/netmgt/snmp/brocadeTestData1.properties")
public void testBug2447_GenericIndexedOnlyCollect() throws Exception {
    // now do the actual collection
    CollectionSet collectionSet = m_collectionSpecification.collect(m_collectionAgent);
    assertEquals("collection status", CollectionStatus.SUCCEEDED, collectionSet.getStatus());
    CollectorTestUtils.persistCollectionSet(m_rrdStrategy, m_resourceStorageDao, m_collectionSpecification, collectionSet);
    System.err.println("FIRST COLLECTION FINISHED");
    // need a one second time elapse to update the RRD
    Thread.sleep(1000);
    // try collecting again
    assertEquals("collection status", CollectionStatus.SUCCEEDED, m_collectionSpecification.collect(m_collectionAgent).getStatus());
    System.err.println("SECOND COLLECTION FINISHED");
}
Also used : CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) JUnitCollector(org.opennms.core.collection.test.JUnitCollector) Test(org.junit.Test) JUnitSnmpAgent(org.opennms.core.test.snmp.annotations.JUnitSnmpAgent) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)52 Test (org.junit.Test)30 HashMap (java.util.HashMap)17 CollectionAgent (org.opennms.netmgt.collection.api.CollectionAgent)17 CollectionSetBuilder (org.opennms.netmgt.collection.support.builder.CollectionSetBuilder)11 NodeLevelResource (org.opennms.netmgt.collection.support.builder.NodeLevelResource)11 CollectionSetVisitor (org.opennms.netmgt.collection.api.CollectionSetVisitor)10 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)10 File (java.io.File)9 RrdRepository (org.opennms.netmgt.rrd.RrdRepository)8 RrdDb (org.jrobin.core.RrdDb)7 JUnitCollector (org.opennms.core.collection.test.JUnitCollector)7 OnmsNode (org.opennms.netmgt.model.OnmsNode)7 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)6 JUnitSnmpAgent (org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)6 Map (java.util.Map)5 Datasource (org.jrobin.core.Datasource)5 Date (java.util.Date)4 GenericTypeResource (org.opennms.netmgt.collection.support.builder.GenericTypeResource)4 ResourcePath (org.opennms.netmgt.model.ResourcePath)4