Search in sources :

Example 1 with XmlDataCollectionConfig

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

the class NMS7963IT 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("NMS-7963");
    RrdRepository repository = createRrdRepository(collection.getXmlRrd());
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("collection", "NMS-7963");
    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/xml-retrv-wipo-data.jrb"));
    Assert.assertNotNull(jrb);
    Assert.assertEquals(1, jrb.getDsCount());
    Datasource ds = jrb.getDatasource("xml-wipo-paco");
    Assert.assertNotNull(ds);
    Assert.assertEquals(new Double(903), 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 2 with XmlDataCollectionConfig

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

the class XmlDataCollectionConfigDaoJaxbTest method testAfterPropertiesSetWithNestedFiles.

/**
 * Test after properties set with nested files (external references to XML groups).
 *
 * @throws Exception the exception
 */
@Test
public void testAfterPropertiesSetWithNestedFiles() throws Exception {
    System.setProperty("opennms.home", "src/test/resources");
    XmlDataCollectionConfigDaoJaxb dao = new XmlDataCollectionConfigDaoJaxb();
    File xmlCollectionConfig = new File("src/test/resources/etc", XmlDataCollectionConfig.XML_DATACOLLECTION_CONFIG_FILE);
    assertTrue(XmlDataCollectionConfig.XML_DATACOLLECTION_CONFIG_FILE + " is readable", xmlCollectionConfig.canRead());
    InputStream in = new FileInputStream(xmlCollectionConfig);
    dao.setConfigResource(new InputStreamResource(in));
    dao.afterPropertiesSet();
    XmlDataCollectionConfig config = dao.getConfig();
    Assert.assertNotNull("xml data collection should not be null", config);
    Assert.assertEquals(2, config.getXmlDataCollections().get(0).getXmlSources().get(0).getXmlGroups().size());
    Assert.assertEquals(5, config.getXmlDataCollections().get(1).getXmlSources().get(0).getXmlGroups().size());
}
Also used : XmlDataCollectionConfig(org.opennms.protocols.xml.config.XmlDataCollectionConfig) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) InputStreamResource(org.springframework.core.io.InputStreamResource) Test(org.junit.Test)

Example 3 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)

Example 4 with XmlDataCollectionConfig

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

the class HttpDataCollectionIT method testJsonHttpCollection.

/**
 * Test HTTP Data Collection with JSON
 *
 * @throws Exception the exception
 */
@Test
@JUnitHttpServer(port = 10342, https = false, webapps = { @Webapp(context = "/junit", path = "src/test/resources/test-webapp") })
public void testJsonHttpCollection() throws Exception {
    File configFile = new File("src/test/resources/solaris-zones-datacollection-config.xml");
    XmlDataCollectionConfig config = JaxbUtils.unmarshal(XmlDataCollectionConfig.class, configFile);
    XmlDataCollection collection = config.getDataCollectionByName("Solaris");
    RrdRepository repository = createRrdRepository(collection.getXmlRrd());
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("collection", "Solaris");
    DefaultJsonCollectionHandler collector = new DefaultJsonCollectionHandler();
    collector.setRrdRepository(repository);
    collector.setServiceName("HTTP");
    CollectionSet collectionSet = XmlCollectorTestUtils.doCollect(m_nodeDao, collector, m_collectionAgent, collection, parameters);
    Assert.assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus());
    System.err.println(CollectionSetUtils.flatten(collectionSet));
    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/solarisZoneStats/global/solaris-zone-stats.jrb"));
    Assert.assertNotNull(jrb);
    Assert.assertEquals(6, jrb.getDsCount());
    Datasource ds = jrb.getDatasource("nproc");
    Assert.assertNotNull(ds);
    Assert.assertEquals(new Double(245.0), Double.valueOf(ds.getLastValue()));
}
Also used : Datasource(org.jrobin.core.Datasource) DefaultJsonCollectionHandler(org.opennms.protocols.json.collector.DefaultJsonCollectionHandler) 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 5 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)

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