Search in sources :

Example 6 with XmlDataCollectionConfig

use of org.opennms.protocols.xml.config.XmlDataCollectionConfig 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 7 with XmlDataCollectionConfig

use of org.opennms.protocols.xml.config.XmlDataCollectionConfig in project opennms by OpenNMS.

the class XmlCollectorComplianceTest method getRequiredBeans.

public Map<String, Object> getRequiredBeans() {
    XmlDataCollectionConfig config = mock(XmlDataCollectionConfig.class);
    when(config.getRrdRepository()).thenReturn("target");
    when(config.buildRrdRepository(COLLECTION)).thenReturn(new RrdRepository());
    XmlRrd xmlRrd = new XmlRrd();
    xmlRrd.setStep(300);
    XmlDataCollection collection = new XmlDataCollection();
    collection.setXmlRrd(xmlRrd);
    XmlDataCollectionConfigDao xmlDataCollectionConfigDao = mock(XmlDataCollectionConfigDao.class);
    when(xmlDataCollectionConfigDao.getDataCollectionByName(COLLECTION)).thenReturn(collection);
    when(xmlDataCollectionConfigDao.getConfig()).thenReturn(config);
    return new ImmutableMap.Builder<String, Object>().put("xmlDataCollectionConfigDao", xmlDataCollectionConfigDao).build();
}
Also used : XmlRrd(org.opennms.protocols.xml.config.XmlRrd) XmlDataCollection(org.opennms.protocols.xml.config.XmlDataCollection) XmlDataCollectionConfig(org.opennms.protocols.xml.config.XmlDataCollectionConfig) XmlDataCollectionConfigDao(org.opennms.protocols.xml.dao.XmlDataCollectionConfigDao) RrdRepository(org.opennms.netmgt.rrd.RrdRepository)

Aggregations

XmlDataCollectionConfig (org.opennms.protocols.xml.config.XmlDataCollectionConfig)7 File (java.io.File)6 Test (org.junit.Test)6 RrdRepository (org.opennms.netmgt.rrd.RrdRepository)6 XmlDataCollection (org.opennms.protocols.xml.config.XmlDataCollection)6 HashMap (java.util.HashMap)5 Datasource (org.jrobin.core.Datasource)5 RrdDb (org.jrobin.core.RrdDb)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 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 HttpCollectionHandler (org.opennms.protocols.http.collector.HttpCollectionHandler)1 DefaultJsonCollectionHandler (org.opennms.protocols.json.collector.DefaultJsonCollectionHandler)1 XmlRrd (org.opennms.protocols.xml.config.XmlRrd)1 XmlDataCollectionConfigDao (org.opennms.protocols.xml.dao.XmlDataCollectionConfigDao)1 InputStreamResource (org.springframework.core.io.InputStreamResource)1