Search in sources :

Example 6 with Datasource

use of org.jrobin.core.Datasource 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 7 with Datasource

use of org.jrobin.core.Datasource 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 8 with Datasource

use of org.jrobin.core.Datasource in project opennms by OpenNMS.

the class NodeLevelDataOnMultipleNodesTest method validateJrb.

/**
 * Validates a JRB.
 * <p>It assumes storeByGroup=true</p>
 *
 * @param file the JRB file instance
 * @param dsnames the array of data source names
 * @param dsvalues the array of data source values
 * @throws Exception the exception
 */
public void validateJrb(File file, String[] dsnames, Double[] dsvalues) throws Exception {
    Assert.assertTrue(file.exists());
    RrdDb jrb = new RrdDb(file);
    Assert.assertEquals(dsnames.length, jrb.getDsCount());
    for (int i = 0; i < dsnames.length; i++) {
        Datasource ds = jrb.getDatasource(dsnames[i]);
        Assert.assertNotNull(ds);
        Assert.assertEquals(dsvalues[i], Double.valueOf(ds.getLastValue()));
    }
}
Also used : Datasource(org.jrobin.core.Datasource) RrdDb(org.jrobin.core.RrdDb)

Example 9 with Datasource

use of org.jrobin.core.Datasource in project opennms by OpenNMS.

the class XmlCollectorITCase method validateJrb.

/**
 * Validates a JRB.
 * <p>It assumes storeByGroup=true</p>
 *
 * @param file the JRB file instance
 * @param dsnames the array of data source names
 * @param dsvalues the array of data source values
 * @throws Exception the exception
 */
public void validateJrb(File file, String[] dsnames, Double[] dsvalues) throws Exception {
    Assert.assertTrue(file.exists());
    RrdDb jrb = new RrdDb(file);
    Assert.assertEquals(dsnames.length, jrb.getDsCount());
    for (int i = 0; i < dsnames.length; i++) {
        Datasource ds = jrb.getDatasource(dsnames[i]);
        Assert.assertNotNull(ds);
        Assert.assertEquals(dsvalues[i], Double.valueOf(ds.getLastValue()));
    }
}
Also used : Datasource(org.jrobin.core.Datasource) RrdDb(org.jrobin.core.RrdDb)

Aggregations

Datasource (org.jrobin.core.Datasource)9 RrdDb (org.jrobin.core.RrdDb)8 File (java.io.File)5 HashMap (java.util.HashMap)5 Test (org.junit.Test)5 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)5 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)5 CollectionSetVisitor (org.opennms.netmgt.collection.api.CollectionSetVisitor)5 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)5 RrdRepository (org.opennms.netmgt.rrd.RrdRepository)5 XmlDataCollection (org.opennms.protocols.xml.config.XmlDataCollection)5 XmlDataCollectionConfig (org.opennms.protocols.xml.config.XmlDataCollectionConfig)5 BigDecimal (java.math.BigDecimal)1 Sample (org.jrobin.core.Sample)1 HttpCollectionHandler (org.opennms.protocols.http.collector.HttpCollectionHandler)1 DefaultJsonCollectionHandler (org.opennms.protocols.json.collector.DefaultJsonCollectionHandler)1