Search in sources :

Example 1 with GenericIndexResourceType

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);
}
Also used : ResourcePath(org.opennms.netmgt.model.ResourcePath) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) GenericIndexResource(org.opennms.netmgt.collectd.GenericIndexResource) SnmpCollectionResource(org.opennms.netmgt.collectd.SnmpCollectionResource) GenericIndexResourceType(org.opennms.netmgt.collectd.GenericIndexResourceType)

Example 2 with GenericIndexResourceType

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()));
}
Also used : StorageStrategy(org.opennms.netmgt.config.datacollection.StorageStrategy) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) HashMap(java.util.HashMap) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) GenericIndexResourceType(org.opennms.netmgt.collectd.GenericIndexResourceType) NodeResourceType(org.opennms.netmgt.collectd.NodeResourceType) IfResourceType(org.opennms.netmgt.collectd.IfResourceType) MockDataCollectionConfig(org.opennms.netmgt.mock.MockDataCollectionConfig) GenericIndexResource(org.opennms.netmgt.collectd.GenericIndexResource) GenericIndexResourceType(org.opennms.netmgt.collectd.GenericIndexResourceType) CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) SnmpAttribute(org.opennms.netmgt.collectd.SnmpAttribute) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) Parameter(org.opennms.netmgt.config.datacollection.Parameter) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) SnmpCollectionResource(org.opennms.netmgt.collectd.SnmpCollectionResource) OnmsSnmpCollection(org.opennms.netmgt.collectd.OnmsSnmpCollection) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy) Test(org.junit.Test)

Example 3 with GenericIndexResourceType

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());
}
Also used : StorageStrategy(org.opennms.netmgt.config.datacollection.StorageStrategy) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) HashMap(java.util.HashMap) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) GenericIndexResourceType(org.opennms.netmgt.collectd.GenericIndexResourceType) NodeResourceType(org.opennms.netmgt.collectd.NodeResourceType) IfResourceType(org.opennms.netmgt.collectd.IfResourceType) MockDataCollectionConfig(org.opennms.netmgt.mock.MockDataCollectionConfig) GenericIndexResource(org.opennms.netmgt.collectd.GenericIndexResource) GenericIndexResourceType(org.opennms.netmgt.collectd.GenericIndexResourceType) CollectionAttribute(org.opennms.netmgt.collection.api.CollectionAttribute) SnmpAttribute(org.opennms.netmgt.collectd.SnmpAttribute) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) Parameter(org.opennms.netmgt.config.datacollection.Parameter) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) SnmpCollectionResource(org.opennms.netmgt.collectd.SnmpCollectionResource) OnmsSnmpCollection(org.opennms.netmgt.collectd.OnmsSnmpCollection) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy) Test(org.junit.Test)

Example 4 with GenericIndexResourceType

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);
}
Also used : SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) SnmpInstId(org.opennms.netmgt.snmp.SnmpInstId) GenericIndexResource(org.opennms.netmgt.collectd.GenericIndexResource) SnmpCollectionResource(org.opennms.netmgt.collectd.SnmpCollectionResource) GenericIndexResourceType(org.opennms.netmgt.collectd.GenericIndexResourceType) Date(java.util.Date) Test(org.junit.Test)

Example 5 with GenericIndexResourceType

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);
}
Also used : HashMap(java.util.HashMap) MockDataCollectionConfig(org.opennms.netmgt.mock.MockDataCollectionConfig) ServiceParameters(org.opennms.netmgt.collection.api.ServiceParameters) OnmsSnmpCollection(org.opennms.netmgt.collectd.OnmsSnmpCollection) GenericIndexResourceType(org.opennms.netmgt.collectd.GenericIndexResourceType)

Aggregations

GenericIndexResourceType (org.opennms.netmgt.collectd.GenericIndexResourceType)6 GenericIndexResource (org.opennms.netmgt.collectd.GenericIndexResource)5 SnmpCollectionAgent (org.opennms.netmgt.collectd.SnmpCollectionAgent)5 SnmpCollectionResource (org.opennms.netmgt.collectd.SnmpCollectionResource)5 SnmpInstId (org.opennms.netmgt.snmp.SnmpInstId)5 Test (org.junit.Test)4 HashMap (java.util.HashMap)3 OnmsSnmpCollection (org.opennms.netmgt.collectd.OnmsSnmpCollection)3 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)3 MockDataCollectionConfig (org.opennms.netmgt.mock.MockDataCollectionConfig)3 IfResourceType (org.opennms.netmgt.collectd.IfResourceType)2 NodeResourceType (org.opennms.netmgt.collectd.NodeResourceType)2 SnmpAttribute (org.opennms.netmgt.collectd.SnmpAttribute)2 CollectionAttribute (org.opennms.netmgt.collection.api.CollectionAttribute)2 Parameter (org.opennms.netmgt.config.datacollection.Parameter)2 PersistenceSelectorStrategy (org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy)2 ResourceType (org.opennms.netmgt.config.datacollection.ResourceType)2 StorageStrategy (org.opennms.netmgt.config.datacollection.StorageStrategy)2 Date (java.util.Date)1 ResourcePath (org.opennms.netmgt.model.ResourcePath)1