use of org.opennms.netmgt.collection.api.CollectionSetVisitor in project opennms by OpenNMS.
the class AbstractVTDXmlCollectorTest method executeCollectorTest.
/**
* Executes collector test.
*
* @param parameters the parameters
* @param expectedFiles the expected amount of JRB files
* @throws Exception the exception
*/
public void executeCollectorTest(Map<String, Object> parameters, int expectedFiles) throws Exception {
XmlCollector collector = new XmlCollector();
collector.setXmlCollectionDao(m_xmlCollectionDao);
CollectionSet collectionSet = XmlCollectorTestUtils.doCollect(collector, m_collectionAgent, parameters);
Assert.assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus());
ServiceParameters serviceParams = new ServiceParameters(new HashMap<String, Object>());
CollectionSetVisitor persister = m_persisterFactory.createGroupPersister(serviceParams, createRrdRepository((String) parameters.get("collection")), false, false);
collectionSet.visit(persister);
Assert.assertEquals(expectedFiles, FileUtils.listFiles(getSnmpRoot(), new String[] { "jrb" }, true).size());
}
use of org.opennms.netmgt.collection.api.CollectionSetVisitor 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.netmgt.collection.api.CollectionSetVisitor in project opennms by OpenNMS.
the class NodeLevelDataOnMultipleNodesTest method executeCollectorTest.
/**
* Executes collector test.
*
* @param nodeId the node id
* @param ipAddress the IP address
* @param xmlSampleFileName the XML sample file name
* @param parameters the parameters
* @param expectedFiles the expected amount of JRB files
* @throws Exception the exception
*/
public void executeCollectorTest(int nodeId, String ipAddress, String xmlSampleFileName, Map<String, Object> parameters, int expectedFiles) throws Exception {
MockDocumentBuilder.setXmlFileName(xmlSampleFileName);
CollectionAgent collectionAgent = new MockCollectionAgent(nodeId, "mynode", InetAddrUtils.addr(ipAddress));
CollectionSet collectionSet = XmlCollectorTestUtils.doCollect(m_collector, collectionAgent, parameters);
Assert.assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus());
ServiceParameters serviceParams = new ServiceParameters(new HashMap<String, Object>());
CollectionSetVisitor persister = m_persisterFactory.createGroupPersister(serviceParams, createRrdRepository((String) parameters.get("collection")), false, false);
collectionSet.visit(persister);
Assert.assertEquals(expectedFiles, FileUtils.listFiles(new File(getSnmpRoot(), Integer.toString(nodeId)), new String[] { getRrdExtension() }, true).size());
}
use of org.opennms.netmgt.collection.api.CollectionSetVisitor in project opennms by OpenNMS.
the class DefaultPollerBackEnd method saveResponseTimeData.
/**
* <p>saveResponseTimeData</p>
*
* @param locationMonitorId a {@link java.lang.String} object.
* @param monSvc a {@link org.opennms.netmgt.model.OnmsMonitoredService} object.
* @param responseTime a double.
* @param pkg a {@link org.opennms.netmgt.config.poller.Package} object.
*/
@Override
public void saveResponseTimeData(final String locationMonitorId, final OnmsMonitoredService monSvc, final double responseTime, final Package pkg) {
final String svcName = monSvc.getServiceName();
final Service svc = m_pollerConfig.getServiceInPackage(svcName, pkg);
String dsName = getServiceParameter(svc, "ds-name");
if (dsName == null) {
dsName = PollStatus.PROPERTY_RESPONSE_TIME;
}
String rrdBaseName = getServiceParameter(svc, "rrd-base-name");
if (rrdBaseName == null) {
rrdBaseName = dsName;
}
final String rrdRepository = getServiceParameter(svc, "rrd-repository");
if (rrdRepository == null) {
return;
}
RrdRepository repository = new RrdRepository();
repository.setStep(m_pollerConfig.getStep(pkg));
repository.setHeartBeat(repository.getStep() * HEARTBEAT_STEP_MULTIPLIER);
repository.setRraList(m_pollerConfig.getRRAList(pkg));
repository.setRrdBaseDir(new File(rrdRepository));
DistributedLatencyCollectionResource distributedLatencyResource = new DistributedLatencyCollectionResource(locationMonitorId, InetAddressUtils.toIpAddrString(monSvc.getIpAddress()));
DistributedLatencyCollectionAttributeType distributedLatencyType = new DistributedLatencyCollectionAttributeType(rrdBaseName, dsName);
distributedLatencyResource.addAttribute(new DistributedLatencyCollectionAttribute(distributedLatencyResource, distributedLatencyType, responseTime));
ServiceParameters params = new ServiceParameters(Collections.emptyMap());
CollectionSetVisitor persister = m_persisterFactory.createPersister(params, repository, false, true, true);
SingleResourceCollectionSet collectionSet = new SingleResourceCollectionSet(distributedLatencyResource, new Date());
collectionSet.setStatus(CollectionStatus.SUCCEEDED);
collectionSet.visit(persister);
}
use of org.opennms.netmgt.collection.api.CollectionSetVisitor in project opennms by OpenNMS.
the class CollectorTestUtils method persistCollectionSet.
public static void persistCollectionSet(RrdStrategy<?, ?> rrdStrategy, ResourceStorageDao resourceStorageDao, CollectionSpecification spec, CollectionSet collectionSet) {
RrdRepository repository = spec.getRrdRepository("default");
System.err.println("repository = " + repository);
ServiceParameters params = spec.getServiceParameters();
System.err.println("service parameters = " + params);
RrdPersisterFactory persisterFactory = new RrdPersisterFactory();
persisterFactory.setRrdStrategy(rrdStrategy);
persisterFactory.setResourceStorageDao(resourceStorageDao);
CollectionSetVisitor persister = persisterFactory.createPersister(params, repository);
System.err.println("persister = " + persister);
collectionSet.visit(persister);
}
Aggregations