use of org.opennms.netmgt.collectd.GenericIndexResource in project opennms by OpenNMS.
the class ThresholdingVisitorIT method runFileSystemDataTest.
private void runFileSystemDataTest(ThresholdingVisitor visitor, int resourceId, String fs, long value, long max) throws Exception {
SnmpCollectionAgent agent = createCollectionAgent();
// Creating Generic ResourceType
GenericIndexResourceType resourceType = createGenericIndexResourceType(agent, "hrStorageIndex");
// Creating strings.properties file
ResourcePath path = ResourcePath.get("snmp", "1", "hrStorageIndex", Integer.toString(resourceId));
m_resourceStorageDao.setStringAttribute(path, "hrStorageType", ".1.3.6.1.2.1.25.2.1.4");
m_resourceStorageDao.setStringAttribute(path, "hrStorageDescr", fs);
// Creating Resource
SnmpInstId inst = new SnmpInstId(resourceId);
SnmpCollectionResource resource = new GenericIndexResource(resourceType, "hrStorageIndex", inst);
addAttributeToCollectionResource(resource, resourceType, "hrStorageUsed", "gauge", "hrStorageIndex", value);
addAttributeToCollectionResource(resource, resourceType, "hrStorageSize", "gauge", "hrStorageIndex", max);
addAttributeToCollectionResource(resource, resourceType, "hrStorageAllocUnits", "gauge", "hrStorageIndex", 1);
// Run Visitor
resource.visit(visitor);
EasyMock.verify(agent);
}
use of org.opennms.netmgt.collectd.GenericIndexResource in project opennms by OpenNMS.
the class CollectionResourceWrapperIT method testNumericFields.
@Test
public void testNumericFields() throws Exception {
SnmpCollectionAgent agent = createCollectionAgent();
MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig();
OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient);
ResourceType rt = new ResourceType();
rt.setName("dskIndex");
rt.setLabel("Disk Table Index (UCD-SNMP MIB)");
StorageStrategy strategy = new StorageStrategy();
strategy.setClazz("org.opennms.netmgt.dao.support.SiblingColumnStorageStrategy");
strategy.addParameter(new Parameter("sibling-column-name", "ns-dskPath"));
strategy.addParameter(new Parameter("replace-first", "s/^-$/_root_fs/"));
strategy.addParameter(new Parameter("replace-all", "s/^-//"));
strategy.addParameter(new Parameter("replace-all", "s/\\s//"));
strategy.addParameter(new Parameter("replace-all", "s/:\\\\.*//"));
rt.setStorageStrategy(strategy);
PersistenceSelectorStrategy pstrategy = new PersistenceSelectorStrategy();
pstrategy.setClazz("org.opennms.netmgt.collection.support.PersistAllSelectorStrategy");
rt.setPersistenceSelectorStrategy(pstrategy);
GenericIndexResourceType resourceType = new GenericIndexResourceType(agent, collection, rt);
SnmpCollectionResource resource = new GenericIndexResource(resourceType, resourceType.getName(), new SnmpInstId(100));
SnmpAttribute total = addAttributeToCollectionResource(resource, "ns-dskTotal", AttributeType.GAUGE, "dskIndex", "10000");
SnmpAttribute used = addAttributeToCollectionResource(resource, "ns-dskUsed", AttributeType.GAUGE, "dskIndex", "5000");
SnmpAttribute label = addAttributeToCollectionResource(resource, "ns-dskPath", AttributeType.STRING, "dskIndex", "/opt");
Map<String, CollectionAttribute> attributes = new HashMap<String, CollectionAttribute>();
attributes.put(used.getName(), used);
attributes.put(total.getName(), total);
attributes.put(label.getName(), label);
CollectionResourceWrapper wrapper = createWrapper(resource, attributes);
Assert.assertEquals("opt", wrapper.getInstanceLabel());
Assert.assertEquals(new Double("10000.0"), wrapper.getAttributeValue(total.getName()));
Assert.assertEquals("10000.0", wrapper.getFieldValue(total.getName()));
}
use of org.opennms.netmgt.collectd.GenericIndexResource in project opennms by OpenNMS.
the class CollectionResourceWrapperIT method testGenericResource.
@Test
public void testGenericResource() throws Exception {
SnmpCollectionAgent agent = createCollectionAgent();
MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig();
OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient);
ResourceType rt = new ResourceType();
rt.setName("hrStorageIndex");
rt.setLabel("host-resources storage");
StorageStrategy strategy = new StorageStrategy();
strategy.setClazz("org.opennms.netmgt.dao.support.SiblingColumnStorageStrategy");
strategy.addParameter(new Parameter("sibling-column-name", "hrStorageLabel"));
strategy.addParameter(new Parameter("replace-all", "s/^-//"));
rt.setStorageStrategy(strategy);
PersistenceSelectorStrategy pstrategy = new PersistenceSelectorStrategy();
pstrategy.setClazz("org.opennms.netmgt.collection.support.PersistAllSelectorStrategy");
rt.setPersistenceSelectorStrategy(pstrategy);
GenericIndexResourceType resourceType = new GenericIndexResourceType(agent, collection, rt);
SnmpCollectionResource resource = new GenericIndexResource(resourceType, resourceType.getName(), new SnmpInstId(100));
SnmpAttribute used = addAttributeToCollectionResource(resource, "hrStorageUsed", AttributeType.GAUGE, "hrStorageIndex", "5000");
SnmpAttribute label = addAttributeToCollectionResource(resource, "hrStorageLabel", AttributeType.STRING, "hrStorageIndex", "/opt");
Map<String, CollectionAttribute> attributes = new HashMap<String, CollectionAttribute>();
attributes.put(used.getName(), used);
attributes.put(label.getName(), label);
CollectionResourceWrapper wrapper = createWrapper(resource, attributes);
Assert.assertEquals("opt", wrapper.getInstanceLabel());
}
use of org.opennms.netmgt.collectd.GenericIndexResource in project opennms by OpenNMS.
the class ThresholdingVisitorIT method testBug3554_withMockFilterDao.
/*
* This test uses this files from src/test/resources:
* - threshd-configuration-bug3554.xml
* - test-thresholds-bug3554.xml
*/
@Test
public void testBug3554_withMockFilterDao() throws Exception {
initFactories("/threshd-configuration-bug3554.xml", "/test-thresholds-bug3554.xml");
// Visitor with Mock FavoriteFilterDao
ThresholdingVisitor visitor = createVisitor();
visitor.visitCollectionSet(createAnonymousCollectionSet(new Date().getTime()));
// Do nothing, just to check visitor
// real value = (46000 - 10000)/300 = 120
runInterfaceResource(visitor, "127.0.0.1", "eth0", 10000000l, 1, 10000, 46000);
// Do nothing, just to check visitor
runGaugeDataTest(visitor, 12000);
// Do nothing, just to check visitor
SnmpCollectionAgent agent = createCollectionAgent();
GenericIndexResourceType resourceType = createGenericIndexResourceType(agent, "ciscoEnvMonTemperatureStatusIndex");
SnmpCollectionResource resource = new GenericIndexResource(resourceType, "ciscoEnvMonTemperatureStatusIndex", new SnmpInstId(45));
resource.visit(visitor);
EasyMock.verify(agent);
}
use of org.opennms.netmgt.collectd.GenericIndexResource in project opennms by OpenNMS.
the class ThresholdingVisitorIT method testBug3227.
/*
* This test uses this files from src/test/resources:
* - threshd-configuration.xml
* - test-thresholds-bug3227.xml
*
* There is no Frame Relay related thresholds definitions on test-thresholds-bug3227.xml.
* When visit resources, getEntityMap from ThresholdingSet must be null.
* Updated to reflect the fact that counter are treated as rates.
*/
@Test
public void testBug3227() throws Exception {
initFactories("/threshd-configuration.xml", "/test-thresholds-bug3227.xml");
ThresholdingVisitor visitor = createVisitor();
SnmpCollectionAgent agent = createCollectionAgent();
GenericIndexResourceType resourceType = createGenericIndexResourceType(agent, "frCircuitIfIndex");
// Creating Resource
SnmpInstId inst = new SnmpInstId(100);
SnmpCollectionResource resource = new GenericIndexResource(resourceType, "frCircuitIfIndex", inst);
addAttributeToCollectionResource(resource, resourceType, "frReceivedOctets", "counter", "frCircuitIfIndex", 1000);
addAttributeToCollectionResource(resource, resourceType, "frSentOctets", "counter", "frCircuitIfIndex", 1000);
/*
* Run Visitor
* I must receive 2 special info events because getEntityMap should be called 2 times.
* One for each attribute and one for each resource.
* Original code will throw a NullPointerException after call getEntityMap.
* Original code expects WARNs, but this message is now an INFO.
*/
resource.visit(visitor);
}
Aggregations