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);
}
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);
}
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;
}
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()));
}
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;
}
Aggregations