Search in sources :

Example 26 with NodeLevelResource

use of org.opennms.netmgt.collection.support.builder.NodeLevelResource in project opennms by OpenNMS.

the class NodeLevelResourceDTO method toResource.

public NodeLevelResource toResource() {
    final NodeLevelResource resource = new NodeLevelResource(nodeId, path);
    resource.setTimestamp(timestamp);
    return resource;
}
Also used : NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource)

Example 27 with NodeLevelResource

use of org.opennms.netmgt.collection.support.builder.NodeLevelResource in project opennms by OpenNMS.

the class ThresholdingVisitorIT method runFileSystemDataTestWithCollectionSetBuilder.

private void runFileSystemDataTestWithCollectionSetBuilder(ThresholdingVisitor visitor, int resourceId, String fs, long value, long max) throws Exception {
    SnmpCollectionAgent agent = createCollectionAgent();
    NodeLevelResource nodeResource = new NodeLevelResource(agent.getNodeId());
    // Creating Generic ResourceType
    org.opennms.netmgt.config.datacollection.ResourceType indexResourceType = createIndexResourceType(agent, "hrStorageIndex");
    GenericTypeResource genericResource = new GenericTypeResource(nodeResource, indexResourceType, Integer.toString(resourceId));
    // 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);
    // Build the collection set
    CollectionSet collectionSet = new CollectionSetBuilder(agent).withNumericAttribute(genericResource, "hd-usage", "hrStorageUsed", value, AttributeType.GAUGE).withNumericAttribute(genericResource, "hd-usage", "hrStorageSize", max, AttributeType.GAUGE).withNumericAttribute(genericResource, "hd-usage", "hrStorageAllocUnits", 1, AttributeType.GAUGE).build();
    // Run Visitor
    collectionSet.visit(visitor);
    EasyMock.verify(agent);
}
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)

Example 28 with NodeLevelResource

use of org.opennms.netmgt.collection.support.builder.NodeLevelResource in project opennms by OpenNMS.

the class XmpCollectorTest method canDetermineAppropriateResourceType.

@Test
public void canDetermineAppropriateResourceType() throws CollectionException {
    NodeLevelResource nodeLevelResource = new NodeLevelResource(1);
    // Define the resource type
    ResourceType resourceType = new ResourceType();
    resourceType.setName("rt");
    resourceType.setLabel("rt label");
    resourceType.setResourceLabel("${instance}");
    StorageStrategy storageStrategy = new StorageStrategy();
    storageStrategy.setClazz(IndexStorageStrategy.class.getCanonicalName());
    resourceType.setStorageStrategy(storageStrategy);
    PersistenceSelectorStrategy persistenceSelectorStrategy = new PersistenceSelectorStrategy();
    persistenceSelectorStrategy.setClazz(PersistAllSelectorStrategy.class.getCanonicalName());
    resourceType.setPersistenceSelectorStrategy(persistenceSelectorStrategy);
    ResourceTypesDao resourceTypesDao = mock(ResourceTypesDao.class);
    when(resourceTypesDao.getResourceTypeByName(resourceType.getName())).thenReturn(resourceType);
    xmpCollector.setResourceTypesDao(resourceTypesDao);
    // If the nodeTypeName is set to "node" it should always return a node level resource
    assertThat(xmpCollector.getResource(nodeLevelResource, CollectionResource.RESOURCE_TYPE_NODE, null, "instance"), instanceOf(NodeLevelResource.class));
    assertThat(xmpCollector.getResource(nodeLevelResource, CollectionResource.RESOURCE_TYPE_NODE, "some-resource", "instance"), instanceOf(NodeLevelResource.class));
    // If a resource-type is set, it should always return a generic type resource
    assertThat(xmpCollector.getResource(nodeLevelResource, null, "rt", "instance"), instanceOf(GenericTypeResource.class));
    // Otherwise, falls back to an instance level resource
    assertThat(xmpCollector.getResource(nodeLevelResource, null, null, "instance"), instanceOf(InterfaceLevelResource.class));
}
Also used : StorageStrategy(org.opennms.netmgt.config.datacollection.StorageStrategy) IndexStorageStrategy(org.opennms.netmgt.collection.support.IndexStorageStrategy) PersistAllSelectorStrategy(org.opennms.netmgt.collection.support.PersistAllSelectorStrategy) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) IndexStorageStrategy(org.opennms.netmgt.collection.support.IndexStorageStrategy) ResourceTypesDao(org.opennms.netmgt.config.api.ResourceTypesDao) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) InterfaceLevelResource(org.opennms.netmgt.collection.support.builder.InterfaceLevelResource) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy) Test(org.junit.Test)

Aggregations

NodeLevelResource (org.opennms.netmgt.collection.support.builder.NodeLevelResource)28 CollectionSetBuilder (org.opennms.netmgt.collection.support.builder.CollectionSetBuilder)18 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)10 GenericTypeResource (org.opennms.netmgt.collection.support.builder.GenericTypeResource)10 Test (org.junit.Test)8 CollectionAgent (org.opennms.netmgt.collection.api.CollectionAgent)8 DeferredGenericTypeResource (org.opennms.netmgt.collection.support.builder.DeferredGenericTypeResource)8 Resource (org.opennms.netmgt.collection.support.builder.Resource)8 InterfaceLevelResource (org.opennms.netmgt.collection.support.builder.InterfaceLevelResource)7 Date (java.util.Date)5 AttributeType (org.opennms.netmgt.collection.api.AttributeType)5 ResourcePath (org.opennms.netmgt.model.ResourcePath)5 HashMap (java.util.HashMap)4 List (java.util.List)3 ResourceType (org.opennms.netmgt.collection.api.ResourceType)3 File (java.io.File)2 MalformedURLException (java.net.MalformedURLException)2 RemoteException (java.rmi.RemoteException)2 Map (java.util.Map)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2