Search in sources :

Example 36 with RrdRepository

use of org.opennms.netmgt.rrd.RrdRepository in project opennms by OpenNMS.

the class HttpDataCollectionIT method testHttpCollection.

/**
 * Test HTTP Data Collection with XPath
 *
 * @throws Exception the exception
 */
@Test
@JUnitHttpServer(port = 10342, https = false, webapps = { @Webapp(context = "/junit", path = "src/test/resources/test-webapp") })
public void testHttpCollection() throws Exception {
    File configFile = new File("src/test/resources/http-datacollection-config.xml");
    XmlDataCollectionConfig config = JaxbUtils.unmarshal(XmlDataCollectionConfig.class, configFile);
    XmlDataCollection collection = config.getDataCollectionByName("Http-Count");
    RrdRepository repository = createRrdRepository(collection.getXmlRrd());
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("collection", "Http-Count");
    DefaultXmlCollectionHandler collector = new DefaultXmlCollectionHandler();
    collector.setRrdRepository(repository);
    collector.setServiceName("HTTP");
    CollectionSet collectionSet = XmlCollectorTestUtils.doCollect(m_nodeDao, collector, m_collectionAgent, collection, parameters);
    Assert.assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus());
    ServiceParameters serviceParams = new ServiceParameters(new HashMap<String, Object>());
    CollectionSetVisitor persister = m_persisterFactory.createGroupPersister(serviceParams, repository, false, false);
    collectionSet.visit(persister);
    RrdDb jrb = new RrdDb(new File(getSnmpRoot(), "1/count-stats.jrb"));
    Assert.assertNotNull(jrb);
    Assert.assertEquals(1, jrb.getDsCount());
    Datasource ds = jrb.getDatasource("count");
    Assert.assertNotNull(ds);
    Assert.assertEquals(new Double(5), Double.valueOf(ds.getLastValue()));
}
Also used : Datasource(org.jrobin.core.Datasource) XmlDataCollectionConfig(org.opennms.protocols.xml.config.XmlDataCollectionConfig) HashMap(java.util.HashMap) CollectionSetVisitor(org.opennms.netmgt.collection.api.CollectionSetVisitor) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) XmlDataCollection(org.opennms.protocols.xml.config.XmlDataCollection) RrdDb(org.jrobin.core.RrdDb) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) File(java.io.File) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 37 with RrdRepository

use of org.opennms.netmgt.rrd.RrdRepository in project opennms by OpenNMS.

the class HttpDataCollectionIT method testCssSelectorHttpCollection.

/**
 * Test HTTP Data Collection with CSS Selector
 *
 * @throws Exception the exception
 */
@Test
@JUnitHttpServer(port = 10342, https = false, webapps = { @Webapp(context = "/junit", path = "src/test/resources/test-webapp") })
public void testCssSelectorHttpCollection() throws Exception {
    File configFile = new File("src/test/resources/http-datacollection-config.xml");
    XmlDataCollectionConfig config = JaxbUtils.unmarshal(XmlDataCollectionConfig.class, configFile);
    XmlDataCollection collection = config.getDataCollectionByName("Http-Market");
    RrdRepository repository = createRrdRepository(collection.getXmlRrd());
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("collection", "Http-Market");
    HttpCollectionHandler collector = new HttpCollectionHandler();
    collector.setRrdRepository(repository);
    collector.setServiceName("HTTP");
    CollectionSet collectionSet = XmlCollectorTestUtils.doCollect(m_nodeDao, collector, m_collectionAgent, collection, parameters);
    Assert.assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus());
    ServiceParameters serviceParams = new ServiceParameters(new HashMap<String, Object>());
    CollectionSetVisitor persister = m_persisterFactory.createGroupPersister(serviceParams, repository, false, false);
    collectionSet.visit(persister);
    RrdDb jrb = new RrdDb(new File(getSnmpRoot(), "1/market.jrb"));
    Assert.assertNotNull(jrb);
    Assert.assertEquals(2, jrb.getDsCount());
    Datasource ds = jrb.getDatasource("nasdaq");
    Assert.assertNotNull(ds);
    Assert.assertEquals(new Double(3578.30), Double.valueOf(ds.getLastValue()));
}
Also used : Datasource(org.jrobin.core.Datasource) XmlDataCollectionConfig(org.opennms.protocols.xml.config.XmlDataCollectionConfig) HashMap(java.util.HashMap) CollectionSetVisitor(org.opennms.netmgt.collection.api.CollectionSetVisitor) HttpCollectionHandler(org.opennms.protocols.http.collector.HttpCollectionHandler) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) XmlDataCollection(org.opennms.protocols.xml.config.XmlDataCollection) RrdDb(org.jrobin.core.RrdDb) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) File(java.io.File) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 38 with RrdRepository

use of org.opennms.netmgt.rrd.RrdRepository in project opennms by OpenNMS.

the class HttpDataCollectionIT method testPostRequestHttpCollection.

/**
 * Test HTTP Data Collection with a POST Request
 *
 * @throws Exception the exception
 */
@Test
@JUnitHttpServer(port = 10342, https = false, webapps = { @Webapp(context = "/junit", path = "src/test/resources/test-webapp") })
public void testPostRequestHttpCollection() throws Exception {
    File configFile = new File("src/test/resources/http-datacollection-config.xml");
    XmlDataCollectionConfig config = JaxbUtils.unmarshal(XmlDataCollectionConfig.class, configFile);
    XmlDataCollection collection = config.getDataCollectionByName("Http-Person-Stats");
    RrdRepository repository = createRrdRepository(collection.getXmlRrd());
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("collection", "Http-Person-Stats");
    DefaultXmlCollectionHandler collector = new DefaultXmlCollectionHandler();
    collector.setRrdRepository(repository);
    collector.setServiceName("HTTP");
    CollectionSet collectionSet = XmlCollectorTestUtils.doCollect(m_nodeDao, collector, m_collectionAgent, collection, parameters);
    Assert.assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus());
    ServiceParameters serviceParams = new ServiceParameters(new HashMap<String, Object>());
    CollectionSetVisitor persister = m_persisterFactory.createGroupPersister(serviceParams, repository, false, false);
    collectionSet.visit(persister);
    RrdDb jrb = new RrdDb(new File(getSnmpRoot(), "1/person-stats.jrb"));
    Assert.assertNotNull(jrb);
    Assert.assertEquals(3, jrb.getDsCount());
    Datasource ds = jrb.getDatasource("contributions");
    Assert.assertNotNull(ds);
    Assert.assertEquals(new Double(500), Double.valueOf(ds.getLastValue()));
}
Also used : Datasource(org.jrobin.core.Datasource) XmlDataCollectionConfig(org.opennms.protocols.xml.config.XmlDataCollectionConfig) HashMap(java.util.HashMap) CollectionSetVisitor(org.opennms.netmgt.collection.api.CollectionSetVisitor) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) XmlDataCollection(org.opennms.protocols.xml.config.XmlDataCollection) RrdDb(org.jrobin.core.RrdDb) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) File(java.io.File) Test(org.junit.Test) JUnitHttpServer(org.opennms.core.test.http.annotations.JUnitHttpServer)

Example 39 with RrdRepository

use of org.opennms.netmgt.rrd.RrdRepository in project opennms by OpenNMS.

the class NodeLevelDataOnMultipleNodesTest method createRrdRepository.

/**
 * Creates the RRD repository.
 *
 * @return the RRD repository
 * @throws IOException Signals that an I/O exception has occurred.
 */
private RrdRepository createRrdRepository(String collection) throws IOException {
    XmlRrd rrd = m_xmlCollectionDao.getDataCollectionByName(collection).getXmlRrd();
    RrdRepository repository = new RrdRepository();
    repository.setRrdBaseDir(getSnmpRoot());
    repository.setHeartBeat(rrd.getStep() * 2);
    repository.setStep(rrd.getStep());
    repository.setRraList(rrd.getXmlRras());
    return repository;
}
Also used : XmlRrd(org.opennms.protocols.xml.config.XmlRrd) RrdRepository(org.opennms.netmgt.rrd.RrdRepository)

Example 40 with RrdRepository

use of org.opennms.netmgt.rrd.RrdRepository in project opennms by OpenNMS.

the class NSClientDataCollectionConfigFactory method getRrdRepository.

/**
 * <p>getRrdRepository</p>
 *
 * @param collectionName a {@link java.lang.String} object.
 * @return a {@link org.opennms.netmgt.rrd.RrdRepository} object.
 */
public RrdRepository getRrdRepository(final String collectionName) {
    try {
        getReadLock().lock();
        final RrdRepository repo = new RrdRepository();
        repo.setRrdBaseDir(new File(getRrdPath()));
        repo.setRraList(getRRAList(collectionName));
        repo.setStep(getStep(collectionName));
        repo.setHeartBeat((2 * getStep(collectionName)));
        return repo;
    } finally {
        getReadLock().unlock();
    }
}
Also used : RrdRepository(org.opennms.netmgt.rrd.RrdRepository) File(java.io.File)

Aggregations

RrdRepository (org.opennms.netmgt.rrd.RrdRepository)54 File (java.io.File)27 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)19 HashMap (java.util.HashMap)11 Test (org.junit.Test)11 CollectionSetVisitor (org.opennms.netmgt.collection.api.CollectionSetVisitor)10 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)7 XmlDataCollection (org.opennms.protocols.xml.config.XmlDataCollection)6 Datasource (org.jrobin.core.Datasource)5 RrdDb (org.jrobin.core.RrdDb)5 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)5 MockDataCollectionConfig (org.opennms.netmgt.mock.MockDataCollectionConfig)5 XmlDataCollectionConfig (org.opennms.protocols.xml.config.XmlDataCollectionConfig)5 ExecutionException (java.util.concurrent.ExecutionException)4 AttributeGroupType (org.opennms.netmgt.collection.api.AttributeGroupType)4 MibObject (org.opennms.netmgt.config.datacollection.MibObject)4 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)4 SnmpResult (org.opennms.netmgt.snmp.SnmpResult)4 XmlRrd (org.opennms.protocols.xml.config.XmlRrd)4 CollectionResource (org.opennms.netmgt.collection.api.CollectionResource)3