use of org.opennms.protocols.xml.config.XmlDataCollection 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()));
}
use of org.opennms.protocols.xml.config.XmlDataCollection in project opennms by OpenNMS.
the class XmlCollector method collect.
/* (non-Javadoc)
* @see org.opennms.netmgt.collectd.ServiceCollector#collect(org.opennms.netmgt.collectd.CollectionAgent, org.opennms.netmgt.model.events.EventProxy, java.util.Map)
*/
@Override
public CollectionSet collect(CollectionAgent agent, Map<String, Object> parameters) throws CollectionException {
final String rrdRepositoryPath = ParameterMap.getKeyedString(parameters, RRD_REPOSITORY_PATH_KEY, null);
final XmlDataCollection collection = (XmlDataCollection) parameters.get(XML_DATACOLLECTION_KEY);
final String serviceName = ParameterMap.getKeyedString(parameters, "SERVICE", "XML");
final String handlerClass = ParameterMap.getKeyedString(parameters, "handler-class", "org.opennms.protocols.xml.collector.DefaultXmlCollectionHandler");
final XmlCollectionHandlerKey key = new XmlCollectionHandlerKey(serviceName, handlerClass);
try {
// Filling XML CollectionSet
RrdRepository rrdRepository = XmlDataCollectionConfig.buildRrdRepository(rrdRepositoryPath, collection);
XmlCollectionHandler handler = m_handlers.get(key);
handler.setRrdRepository(rrdRepository);
return handler.collect(agent, collection, parameters);
} catch (Exception e) {
throw new CollectionException("Can't collect XML data because " + e.getMessage(), e);
}
}
use of org.opennms.protocols.xml.config.XmlDataCollection in project opennms by OpenNMS.
the class XmlCollector method getRuntimeAttributes.
@Override
public Map<String, Object> getRuntimeAttributes(CollectionAgent agent, Map<String, Object> parameters) {
final Map<String, Object> runtimeAttributes = new HashMap<>();
// Construct the handler
LOG.debug("getRuntimeAttributes: initializing XML collection handling using {} for collection agent {}", parameters, agent);
String serviceName = ParameterMap.getKeyedString(parameters, "SERVICE", "XML");
String handlerClass = ParameterMap.getKeyedString(parameters, "handler-class", "org.opennms.protocols.xml.collector.DefaultXmlCollectionHandler");
XmlCollectionHandlerKey key = new XmlCollectionHandlerKey(serviceName, handlerClass);
XmlCollectionHandler handler;
try {
handler = m_handlers.get(key);
} catch (ExecutionException e) {
throw new RuntimeException(e);
}
// Retrieve the XML Collection
String collectionName = ParameterMap.getKeyedString(parameters, "collection", ParameterMap.getKeyedString(parameters, "xml-collection", null));
if (collectionName == null) {
throw new IllegalArgumentException("Parameter collection is required for the XML Collector!");
}
LOG.debug("getRuntimeAttributes: collecting XML data using collection {} for {}", collectionName, agent);
XmlDataCollection collection = m_xmlCollectionDao.getDataCollectionByName(collectionName);
if (collection == null) {
throw new IllegalArgumentException("XML Collection " + collectionName + " does not exist.");
}
// Parse the collection attributes before adding it in the map
runtimeAttributes.put(XML_DATACOLLECTION_KEY, parseCollection(collection, handler, agent, parameters));
runtimeAttributes.put(RRD_REPOSITORY_PATH_KEY, m_xmlCollectionDao.getConfig().getRrdRepository());
return runtimeAttributes;
}
use of org.opennms.protocols.xml.config.XmlDataCollection 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.XmlDataCollection in project opennms by OpenNMS.
the class XmlCollectorTestUtils method doCollect.
public static CollectionSet doCollect(NodeDao nodeDao, XmlCollectionHandler handler, CollectionAgent agent, XmlDataCollection collection, Map<String, Object> parameters) throws CollectionException {
ResourceTypeMapper.getInstance().setResourceTypeMapper(type -> getResourceType(type));
XmlCollector collector = new XmlCollector();
collector.setNodeDao(nodeDao);
XmlDataCollection parsedCollection = collector.parseCollection(collection, handler, agent, parameters);
return handler.collect(agent, parsedCollection, parameters);
}
Aggregations