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