Search in sources :

Example 1 with StorageStrategy

use of org.opennms.netmgt.config.datacollection.StorageStrategy 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)

Example 2 with StorageStrategy

use of org.opennms.netmgt.config.datacollection.StorageStrategy 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 3 with StorageStrategy

use of org.opennms.netmgt.config.datacollection.StorageStrategy 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 4 with StorageStrategy

use of org.opennms.netmgt.config.datacollection.StorageStrategy 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 5 with StorageStrategy

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

the class XmlCollectorTestUtils method getResourceType.

public static ResourceType getResourceType(String resourceType) {
    ResourceType rt = new ResourceType();
    rt.setName(resourceType);
    rt.setStorageStrategy(new StorageStrategy());
    rt.getStorageStrategy().setClazz(XmlStorageStrategy.class.getName());
    rt.setPersistenceSelectorStrategy(new PersistenceSelectorStrategy());
    rt.getPersistenceSelectorStrategy().setClazz(PersistAllSelectorStrategy.class.getName());
    return rt;
}
Also used : StorageStrategy(org.opennms.netmgt.config.datacollection.StorageStrategy) PersistAllSelectorStrategy(org.opennms.netmgt.collection.support.PersistAllSelectorStrategy) ResourceType(org.opennms.netmgt.config.datacollection.ResourceType) PersistenceSelectorStrategy(org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy)

Aggregations

PersistenceSelectorStrategy (org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy)14 StorageStrategy (org.opennms.netmgt.config.datacollection.StorageStrategy)14 ResourceType (org.opennms.netmgt.config.datacollection.ResourceType)11 IndexStorageStrategy (org.opennms.netmgt.collection.support.IndexStorageStrategy)7 PersistAllSelectorStrategy (org.opennms.netmgt.collection.support.PersistAllSelectorStrategy)7 Test (org.junit.Test)5 Parameter (org.opennms.netmgt.config.datacollection.Parameter)5 HashMap (java.util.HashMap)3 GenericIndexResourceType (org.opennms.netmgt.collectd.GenericIndexResourceType)3 IfResourceType (org.opennms.netmgt.collectd.IfResourceType)3 NodeResourceType (org.opennms.netmgt.collectd.NodeResourceType)3 CollectionAttribute (org.opennms.netmgt.collection.api.CollectionAttribute)3 GenericTypeResource (org.opennms.netmgt.collection.support.builder.GenericTypeResource)3 GenericIndexResource (org.opennms.netmgt.collectd.GenericIndexResource)2 OnmsSnmpCollection (org.opennms.netmgt.collectd.OnmsSnmpCollection)2 SnmpAttribute (org.opennms.netmgt.collectd.SnmpAttribute)2 SnmpCollectionAgent (org.opennms.netmgt.collectd.SnmpCollectionAgent)2 SnmpCollectionResource (org.opennms.netmgt.collectd.SnmpCollectionResource)2 ServiceParameters (org.opennms.netmgt.collection.api.ServiceParameters)2 NodeLevelResource (org.opennms.netmgt.collection.support.builder.NodeLevelResource)2