Search in sources :

Example 1 with CollectionSetVisitor

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());
}
Also used : XmlCollector(org.opennms.protocols.xml.collector.XmlCollector) CollectionSetVisitor(org.opennms.netmgt.collection.api.CollectionSetVisitor) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet)

Example 2 with CollectionSetVisitor

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()));
}
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 3 with CollectionSetVisitor

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());
}
Also used : CollectionSetVisitor(org.opennms.netmgt.collection.api.CollectionSetVisitor) MockCollectionAgent(org.opennms.core.collection.test.MockCollectionAgent) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) CollectionAgent(org.opennms.netmgt.collection.api.CollectionAgent) MockCollectionAgent(org.opennms.core.collection.test.MockCollectionAgent) File(java.io.File) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet)

Example 4 with CollectionSetVisitor

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);
}
Also used : SingleResourceCollectionSet(org.opennms.netmgt.collection.support.SingleResourceCollectionSet) CollectionSetVisitor(org.opennms.netmgt.collection.api.CollectionSetVisitor) PolledService(org.opennms.netmgt.poller.remote.PolledService) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Service(org.opennms.netmgt.config.poller.Service) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) RrdRepository(org.opennms.netmgt.rrd.RrdRepository) File(java.io.File) Date(java.util.Date)

Example 5 with CollectionSetVisitor

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);
}
Also used : CollectionSetVisitor(org.opennms.netmgt.collection.api.CollectionSetVisitor) RrdPersisterFactory(org.opennms.netmgt.collection.persistence.rrd.RrdPersisterFactory) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) RrdRepository(org.opennms.netmgt.rrd.RrdRepository)

Aggregations

CollectionSetVisitor (org.opennms.netmgt.collection.api.CollectionSetVisitor)16 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)14 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)10 RrdRepository (org.opennms.netmgt.rrd.RrdRepository)9 File (java.io.File)7 HashMap (java.util.HashMap)7 RrdDb (org.jrobin.core.RrdDb)6 Test (org.junit.Test)6 Datasource (org.jrobin.core.Datasource)5 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)5 XmlDataCollection (org.opennms.protocols.xml.config.XmlDataCollection)5 XmlDataCollectionConfig (org.opennms.protocols.xml.config.XmlDataCollectionConfig)5 Date (java.util.Date)3 CollectionAttribute (org.opennms.netmgt.collection.api.CollectionAttribute)3 CollectionResource (org.opennms.netmgt.collection.api.CollectionResource)2 RrdPersisterFactory (org.opennms.netmgt.collection.persistence.rrd.RrdPersisterFactory)2 CollectionSetVisitorWrapper (org.opennms.netmgt.collection.support.CollectionSetVisitorWrapper)2 ConstantTimeKeeper (org.opennms.netmgt.collection.support.ConstantTimeKeeper)2 SingleResourceCollectionSet (org.opennms.netmgt.collection.support.SingleResourceCollectionSet)2 Path (java.nio.file.Path)1