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()));
}
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());
}
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();
}
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()));
}
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()));
}
Aggregations