Search in sources :

Example 46 with CollectionSet

use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.

the class ThresholdingVisitorIT method testThresholdFiltersOnGenericResourceWithSiblingColumnStorageStrategy.

/**
 * Verifies that we are able to generate thresholds for CollectionSets
 * using GenericTypeResource resources that use the SiblingColumnStorageStrategy.
 *
 * Resources of this type are commonly used by the WS-Man collector,
 * where data is returned in a tabular format and the resource name is set using
 * the SiblingColumnStorageStrategy.
 *
 * In the case of the WS-Man collector, the instance ids are generated systematically
 * and will differ from one collection run to another. For this reason, it's important
 * that the thresholder keys it's state based off of the resource label, and not
 * the instance id - this test will validate this.
 */
@Test
public void testThresholdFiltersOnGenericResourceWithSiblingColumnStorageStrategy() throws Exception {
    initFactories("/threshd-configuration.xml", "/test-thresholds-wsman.xml");
    ThresholdingVisitor visitor = createVisitor();
    SnmpCollectionAgent agent = createCollectionAgent();
    NodeLevelResource nodeResource = new NodeLevelResource(agent.getNodeId());
    org.opennms.netmgt.config.datacollection.ResourceType wmiLogicalDisk = createWmiLogicalDiskResourceType();
    // Expect a low threshold event (as configured in test-thresholds-wsman.xml)
    addEvent(// uei
    "uei.opennms.org/threshold/lowThresholdExceededWSManLogStorage", // ipaddr
    "127.0.0.1", // service
    "SNMP", // trigger
    2, // threshold
    10240.0, // rearm
    12288.0, // value
    1.0, // label
    "HarddiskVolume16", // instance
    "volume16-1", // ds
    "wmiLDPctFreeMBytes", // iflabel
    null, // ifindex
    null, m_anticipator, m_anticipatedEvents);
    // Visit the collection set twice (the trigger is set to 2)
    for (int i = 0; i < 2; i++) {
        // A resource for each drive, with a unique instance on each iteration
        GenericTypeResource volume16 = new GenericTypeResource(nodeResource, wmiLogicalDisk, "volume16-" + i);
        GenericTypeResource iDrive = new GenericTypeResource(nodeResource, wmiLogicalDisk, "iDrive" + i);
        // Create the entries in strings.properties
        ResourcePath path = ResourcePath.get("snmp", "1", "wmiLogicalDisk", "HarddiskVolume16");
        m_resourceStorageDao.setStringAttribute(path, "wmiLDName", "HarddiskVolume16");
        path = ResourcePath.get("snmp", "1", "wmiLogicalDisk", "I");
        m_resourceStorageDao.setStringAttribute(path, "wmiLDName", "I");
        // Build a collection set containing attributes for both resources
        CollectionSet collectionSet = new CollectionSetBuilder(agent).withStringAttribute(volume16, "windows-os-wmi-LogicalDisk", "wmiLDName", "HarddiskVolume16").withNumericAttribute(volume16, "windows-os-wmi-LogicalDisk", "wmiLDPctFreeMBytes", 1.0, AttributeType.GAUGE).withNumericAttribute(volume16, "windows-os-wmi-LogicalDisk", "wmiLDPctFreeSpace", 10, AttributeType.GAUGE).withStringAttribute(iDrive, "windows-os-wmi-LogicalDisk", "wmiLDName", "I").withNumericAttribute(iDrive, "windows-os-wmi-LogicalDisk", "wmiLDPctFreeMBytes", 2668498.0, AttributeType.GAUGE).withNumericAttribute(iDrive, "windows-os-wmi-LogicalDisk", "wmiLDPctFreeSpace", 10, AttributeType.GAUGE).build();
        collectionSet.visit(visitor);
    }
    // Verify!
    verifyEvents(0);
}
Also used : ResourcePath(org.opennms.netmgt.model.ResourcePath) CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) Test(org.junit.Test)

Example 47 with CollectionSet

use of org.opennms.netmgt.collection.api.CollectionSet 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 48 with CollectionSet

use of org.opennms.netmgt.collection.api.CollectionSet 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)

Example 49 with CollectionSet

use of org.opennms.netmgt.collection.api.CollectionSet in project opennms by OpenNMS.

the class HttpDataCollectionIT method testCssSelectorHttpCollection.

/**
 * Test HTTP Data Collection with CSS Selector
 *
 * @throws Exception the exception
 */
@Test
@JUnitHttpServer(port = 10342, https = false, webapps = { @Webapp(context = "/junit", path = "src/test/resources/test-webapp") })
public void testCssSelectorHttpCollection() 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-Market");
    RrdRepository repository = createRrdRepository(collection.getXmlRrd());
    Map<String, Object> parameters = new HashMap<String, Object>();
    parameters.put("collection", "Http-Market");
    HttpCollectionHandler collector = new HttpCollectionHandler();
    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/market.jrb"));
    Assert.assertNotNull(jrb);
    Assert.assertEquals(2, jrb.getDsCount());
    Datasource ds = jrb.getDatasource("nasdaq");
    Assert.assertNotNull(ds);
    Assert.assertEquals(new Double(3578.30), 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) HttpCollectionHandler(org.opennms.protocols.http.collector.HttpCollectionHandler) 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 50 with CollectionSet

use of org.opennms.netmgt.collection.api.CollectionSet 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()));
}
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

CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)52 Test (org.junit.Test)30 HashMap (java.util.HashMap)17 CollectionAgent (org.opennms.netmgt.collection.api.CollectionAgent)17 CollectionSetBuilder (org.opennms.netmgt.collection.support.builder.CollectionSetBuilder)11 NodeLevelResource (org.opennms.netmgt.collection.support.builder.NodeLevelResource)11 CollectionSetVisitor (org.opennms.netmgt.collection.api.CollectionSetVisitor)10 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)10 File (java.io.File)9 RrdRepository (org.opennms.netmgt.rrd.RrdRepository)8 RrdDb (org.jrobin.core.RrdDb)7 JUnitCollector (org.opennms.core.collection.test.JUnitCollector)7 OnmsNode (org.opennms.netmgt.model.OnmsNode)7 JUnitHttpServer (org.opennms.core.test.http.annotations.JUnitHttpServer)6 JUnitSnmpAgent (org.opennms.core.test.snmp.annotations.JUnitSnmpAgent)6 Map (java.util.Map)5 Datasource (org.jrobin.core.Datasource)5 Date (java.util.Date)4 GenericTypeResource (org.opennms.netmgt.collection.support.builder.GenericTypeResource)4 ResourcePath (org.opennms.netmgt.model.ResourcePath)4