Search in sources :

Example 6 with ResourceType

use of org.opennms.netmgt.config.datacollection.ResourceType in project opennms by OpenNMS.

the class TcaCollectorIT method getJuniperTcaEntryResourceType.

public static ResourceType getJuniperTcaEntryResourceType() {
    final ResourceType resourceType = new ResourceType();
    resourceType.setName("juniperTcaEntry");
    resourceType.setLabel("Juniper TCA Entry");
    resourceType.setResourceLabel("Peer ${index}");
    StorageStrategy storageStrategy = new StorageStrategy();
    storageStrategy.setClazz(IndexStorageStrategy.class.getCanonicalName());
    resourceType.setStorageStrategy(storageStrategy);
    PersistenceSelectorStrategy persistenceSelectorStrategy = new PersistenceSelectorStrategy();
    persistenceSelectorStrategy.setClazz(PersistAllSelectorStrategy.class.getCanonicalName());
    resourceType.setPersistenceSelectorStrategy(persistenceSelectorStrategy);
    return resourceType;
}
Also used : StorageStrategy(org.opennms.netmgt.config.datacollection.StorageStrategy) IndexStorageStrategy(org.opennms.netmgt.collection.support.IndexStorageStrategy) PersistAllSelectorStrategy(org.opennms.netmgt.collection.support.PersistAllSelectorStrategy) IndexStorageStrategy(org.opennms.netmgt.collection.support.IndexStorageStrategy) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy)

Example 7 with ResourceType

use of org.opennms.netmgt.config.datacollection.ResourceType in project opennms by OpenNMS.

the class FindTopLevelResourcesTest method execute_testFindTopLevelResources_provisionedNodes.

/*
     * On environments where all the nodes are part of a requisition (i.e. they have been provisioned)
     * the top level resources are always going to be built using NodeSourceResourceType only
     * if storeByForeignSource is enabled, otherwise they are all going to built using NodeResourceType.
     */
private void execute_testFindTopLevelResources_provisionedNodes(boolean storeByForeignSource) throws Exception {
    setStoreByForeignSource(storeByForeignSource);
    final List<OnmsNode> nodes = new ArrayList<OnmsNode>();
    final String foreignSource = "Junit";
    // Node on the DB with RRD Data with Response Time
    OnmsNode n1 = createNode(1, "node1", foreignSource, "node1", "10.0.0.1");
    nodes.add(n1);
    // Node on the DB with RRD Data without Response Time
    OnmsNode n2 = createNode(2, "node2", foreignSource, "node2", "10.0.0.2");
    nodes.add(n2);
    // Node on the DB with No RRD Data or Response Time
    OnmsNode n3 = createNode(3, "node3", foreignSource, "node3", "10.0.0.3");
    nodes.add(n3);
    expect(m_resourceTypesDao.getLastUpdate()).andReturn(new Date(System.currentTimeMillis())).atLeastOnce();
    expect(m_resourceTypesDao.getResourceTypes()).andReturn(new HashMap<String, ResourceType>());
    expect(m_nodeDao.findAll()).andReturn(nodes);
    expect(m_locationMonitorDao.findStatusChangesForNodeForUniqueMonitorAndInterface(n1.getId())).andReturn(new ArrayList<LocationMonitorIpInterface>(0));
    expect(m_locationMonitorDao.findStatusChangesForNodeForUniqueMonitorAndInterface(n2.getId())).andReturn(new ArrayList<LocationMonitorIpInterface>(0));
    expect(m_locationMonitorDao.findStatusChangesForNodeForUniqueMonitorAndInterface(n3.getId())).andReturn(new ArrayList<LocationMonitorIpInterface>(0));
    // Common directories
    File snmpDir = m_fileAnticipator.tempDir(ResourceTypeUtils.SNMP_DIRECTORY);
    File responseDir = m_fileAnticipator.tempDir(ResourceTypeUtils.RESPONSE_DIRECTORY);
    File fsDir = m_fileAnticipator.tempDir(snmpDir, ResourceTypeUtils.FOREIGN_SOURCE_DIRECTORY);
    File foreignSourceDir = m_fileAnticipator.tempDir(fsDir, foreignSource);
    // RRD Directory for n1
    File nodeDir = null;
    if (storeByForeignSource) {
        nodeDir = m_fileAnticipator.tempDir(foreignSourceDir, n1.getForeignId());
    } else {
        nodeDir = m_fileAnticipator.tempDir(snmpDir, n1.getId().toString());
    }
    m_fileAnticipator.tempFile(nodeDir, "data" + m_rrdFileExtension);
    // RRD Directory for n2
    if (storeByForeignSource) {
        nodeDir = m_fileAnticipator.tempDir(foreignSourceDir, n2.getForeignId());
    } else {
        nodeDir = m_fileAnticipator.tempDir(snmpDir, n2.getId().toString());
    }
    m_fileAnticipator.tempFile(nodeDir, "data" + m_rrdFileExtension);
    // RRD Directory for an orphan node
    if (storeByForeignSource) {
        nodeDir = m_fileAnticipator.tempDir(foreignSourceDir, "orphan_node");
    } else {
        nodeDir = m_fileAnticipator.tempDir(snmpDir, "100");
    }
    m_fileAnticipator.tempFile(nodeDir, "data" + m_rrdFileExtension);
    // Response Time RRD Directory for n1
    File ipDir = m_fileAnticipator.tempDir(responseDir, n1.getIpInterfaces().iterator().next().getIpAddress().getHostAddress());
    m_fileAnticipator.tempFile(ipDir, "icmp" + m_rrdFileExtension);
    walkin(m_fileAnticipator.getTempDir());
    m_easyMockUtils.replayAll();
    m_resourceDao.afterPropertiesSet();
    List<OnmsResource> resources = m_resourceDao.findTopLevelResources();
    Assert.assertNotNull(resources);
    Collections.sort(resources);
    Assert.assertEquals(2, resources.size());
    // Node 1
    List<OnmsResource> children = resources.get(0).getChildResources();
    Collections.sort(children);
    Assert.assertEquals(2, children.size());
    Assert.assertEquals("node[Junit:node1].responseTime[10.0.0.1]", children.get(0).getId().toString());
    Assert.assertEquals("node[Junit:node1].nodeSnmp[]", children.get(1).getId().toString());
    // Node 2
    children = resources.get(1).getChildResources();
    Collections.sort(children);
    Assert.assertEquals(1, children.size());
    Assert.assertEquals("node[Junit:node2].nodeSnmp[]", children.get(0).getId().toString());
    m_easyMockUtils.verifyAll();
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsResource(org.opennms.netmgt.model.OnmsResource) ArrayList(java.util.ArrayList) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) LocationMonitorIpInterface(org.opennms.netmgt.model.LocationMonitorIpInterface) File(java.io.File) Date(java.util.Date)

Example 8 with ResourceType

use of org.opennms.netmgt.config.datacollection.ResourceType in project opennms by OpenNMS.

the class WmiCollector method getWmiResource.

private Resource getWmiResource(CollectionAgent agent, String resourceType, NodeLevelResource nodeResource, String instance) {
    ResourceType rt = DataCollectionConfigFactory.getInstance().getConfiguredResourceTypes().get(resourceType);
    if (rt == null) {
        LOG.debug("getWmiResourceType: using default WMI resource type strategy - index / all");
        rt = new ResourceType();
        rt.setName(resourceType);
        rt.setStorageStrategy(new StorageStrategy());
        rt.getStorageStrategy().setClazz(IndexStorageStrategy.class.getName());
        rt.setPersistenceSelectorStrategy(new PersistenceSelectorStrategy());
        rt.getPersistenceSelectorStrategy().setClazz(PersistAllSelectorStrategy.class.getName());
    }
    return new GenericTypeResource(nodeResource, rt, instance);
}
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) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy)

Example 9 with ResourceType

use of org.opennms.netmgt.config.datacollection.ResourceType in project opennms by OpenNMS.

the class ResourceTypeForm method createBasicResourceType.

/**
     * Creates the basic resource type.
     *
     * @return the resource type
     */
public ResourceType createBasicResourceType() {
    ResourceType rt = new ResourceType();
    rt.setName("New Resource Type");
    rt.setLabel("New Resource Type");
    rt.setResourceLabel("{index}");
    PersistenceSelectorStrategy persistence = new PersistenceSelectorStrategy();
    // To avoid requires opennms-services
    persistence.setClazz("org.opennms.netmgt.collection.support.PersistAllSelectorStrategy");
    rt.setPersistenceSelectorStrategy(persistence);
    StorageStrategy storage = new StorageStrategy();
    storage.setClazz(IndexStorageStrategy.class.getName());
    rt.setStorageStrategy(storage);
    return rt;
}
Also used : StorageStrategy(org.opennms.netmgt.config.datacollection.StorageStrategy) IndexStorageStrategy(org.opennms.netmgt.collection.support.IndexStorageStrategy) IndexStorageStrategy(org.opennms.netmgt.collection.support.IndexStorageStrategy) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy)

Example 10 with ResourceType

use of org.opennms.netmgt.config.datacollection.ResourceType in project opennms by OpenNMS.

the class JdbcCollectorTest method canCollectGenericResource.

@Test
public void canCollectGenericResource() throws Exception {
    // Build the query
    JdbcQuery query = new JdbcQuery();
    query.setQueryName("pg_tablespace_size");
    query.setIfType("all");
    query.setResourceType("pgTableSpace");
    query.setInstanceColumn("spcname");
    JdbcColumn spcnameColumn = new JdbcColumn();
    spcnameColumn.setColumnName("spcname");
    spcnameColumn.setAlias("spcname");
    spcnameColumn.setDataType(AttributeType.STRING);
    query.addJdbcColumn(spcnameColumn);
    JdbcColumn tssizeColumn = new JdbcColumn();
    tssizeColumn.setColumnName("ts_size");
    tssizeColumn.setAlias("ts_size");
    tssizeColumn.setDataType(AttributeType.GAUGE);
    query.addJdbcColumn(tssizeColumn);
    JdbcDataCollection collection = new JdbcDataCollection();
    collection.addQuery(query);
    // Mock the result set
    ResultSet resultSet = mock(ResultSet.class);
    when(resultSet.getRow()).thenReturn(2);
    when(resultSet.getString("spcname")).thenReturn("some: name");
    when(resultSet.getString("ts_size")).thenReturn("41").thenReturn("52");
    when(resultSet.next()).thenReturn(true).thenReturn(true).thenReturn(false);
    // Define the resource type
    ResourceType resourceType = new ResourceType();
    resourceType.setName("pgTableSpace");
    resourceType.setLabel("PostgreSQL Tablespace");
    resourceType.setResourceLabel("${spcname}");
    StorageStrategy storageStrategy = new StorageStrategy();
    storageStrategy.setClazz(IndexStorageStrategy.class.getCanonicalName());
    resourceType.setStorageStrategy(storageStrategy);
    PersistenceSelectorStrategy persistenceSelectorStrategy = new PersistenceSelectorStrategy();
    persistenceSelectorStrategy.setClazz(PersistAllSelectorStrategy.class.getCanonicalName());
    resourceType.setPersistenceSelectorStrategy(persistenceSelectorStrategy);
    // Collect and verify
    CollectionSet collectionSet = collect(collection, resultSet, resourceType);
    assertEquals(CollectionStatus.SUCCEEDED, collectionSet.getStatus());
    List<String> collectionSetKeys = CollectionSetUtils.flatten(collectionSet);
    assertEquals(Arrays.asList("snmp/1/pgTableSpace/some__name/pg_tablespace_size/spcname[some: name,null]", "snmp/1/pgTableSpace/some__name/pg_tablespace_size/ts_size[null,41.0]", "snmp/1/pgTableSpace/some__name/pg_tablespace_size/spcname[some: name,null]", "snmp/1/pgTableSpace/some__name/pg_tablespace_size/ts_size[null,52.0]"), collectionSetKeys);
}
Also used : JdbcQuery(org.opennms.netmgt.config.jdbc.JdbcQuery) StorageStrategy(org.opennms.netmgt.config.datacollection.StorageStrategy) IndexStorageStrategy(org.opennms.netmgt.collection.support.IndexStorageStrategy) PersistAllSelectorStrategy(org.opennms.netmgt.collection.support.PersistAllSelectorStrategy) JdbcColumn(org.opennms.netmgt.config.jdbc.JdbcColumn) IndexStorageStrategy(org.opennms.netmgt.collection.support.IndexStorageStrategy) JdbcDataCollection(org.opennms.netmgt.config.jdbc.JdbcDataCollection) ResultSet(java.sql.ResultSet) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) Test(org.junit.Test)

Aggregations

ResourceType (org.opennms.netmgt.config.datacollection.ResourceType)25 PersistenceSelectorStrategy (org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy)11 StorageStrategy (org.opennms.netmgt.config.datacollection.StorageStrategy)11 Test (org.junit.Test)6 PersistAllSelectorStrategy (org.opennms.netmgt.collection.support.PersistAllSelectorStrategy)6 HashMap (java.util.HashMap)5 IndexStorageStrategy (org.opennms.netmgt.collection.support.IndexStorageStrategy)5 File (java.io.File)4 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 GenericTypeResource (org.opennms.netmgt.collection.support.builder.GenericTypeResource)4 ResourceTypesDao (org.opennms.netmgt.config.api.ResourceTypesDao)4 Parameter (org.opennms.netmgt.config.datacollection.Parameter)4 OnmsNode (org.opennms.netmgt.model.OnmsNode)4 OnmsResource (org.opennms.netmgt.model.OnmsResource)4 CollectionAttribute (org.opennms.netmgt.collection.api.CollectionAttribute)3 Before (org.junit.Before)2 TcaDataCollectionConfig (org.opennms.netmgt.collectd.tca.config.TcaDataCollectionConfig)2 CollectionException (org.opennms.netmgt.collection.api.CollectionException)2 CollectionSet (org.opennms.netmgt.collection.api.CollectionSet)2