use of org.opennms.netmgt.collectd.GenericIndexResourceType 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.GenericIndexResourceType 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.GenericIndexResourceType 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.GenericIndexResourceType 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.GenericIndexResourceType in project opennms by OpenNMS.
the class ThresholdingVisitorIT method createGenericIndexResourceType.
private GenericIndexResourceType createGenericIndexResourceType(SnmpCollectionAgent agent, String resourceTypeName) {
org.opennms.netmgt.config.datacollection.ResourceType type = createIndexResourceType(agent, resourceTypeName);
MockDataCollectionConfig dataCollectionConfig = new MockDataCollectionConfig();
OnmsSnmpCollection collection = new OnmsSnmpCollection(agent, new ServiceParameters(new HashMap<String, Object>()), dataCollectionConfig, m_locationAwareSnmpClient);
return new GenericIndexResourceType(agent, collection, type);
}
Aggregations