use of org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy in project opennms by OpenNMS.
the class PersistRegexSelectorStrategyTest method setUp.
@Before
public void setUp() throws Exception {
ipInterfaceDao = EasyMock.createMock(IpInterfaceDao.class);
String localhost = InetAddress.getLocalHost().getHostAddress();
NetworkBuilder builder = new NetworkBuilder();
builder.addNode("myNode");
builder.addInterface(localhost).setIsManaged("M").setIsSnmpPrimary("P");
OnmsNode node = builder.getCurrentNode();
node.setId(1);
OnmsIpInterface ipInterface = node.getIpInterfaces().iterator().next();
EasyMock.expect(ipInterfaceDao.load(1)).andReturn(ipInterface).anyTimes();
EasyMock.replay(ipInterfaceDao);
Package pkg = new Package();
pkg.setName("junitTestPackage");
Filter filter = new Filter();
filter.setContent("IPADDR != '0.0.0.0'");
pkg.setFilter(filter);
Service service = new Service();
service.setName("SNMP");
pkg.addService(service);
Map<String, Object> map = new TreeMap<String, Object>();
List<org.opennms.netmgt.config.collectd.Parameter> params = pkg.getService("SNMP").getParameters();
for (org.opennms.netmgt.config.collectd.Parameter p : params) {
map.put(p.getKey(), p.getValue());
}
map.put("collection", "default");
serviceParams = new ServiceParameters(map);
LocationAwareSnmpClient locationAwareSnmpClient = new LocationAwareSnmpClientRpcImpl(new MockRpcClientFactory());
PlatformTransactionManager ptm = new MockPlatformTransactionManager();
SnmpCollectionAgent agent = DefaultCollectionAgent.create(1, ipInterfaceDao, ptm);
OnmsSnmpCollection snmpCollection = new OnmsSnmpCollection(agent, serviceParams, new MockDataCollectionConfigDao(), locationAwareSnmpClient);
org.opennms.netmgt.config.datacollection.ResourceType rt = new org.opennms.netmgt.config.datacollection.ResourceType();
rt.setName("myResourceType");
StorageStrategy storageStrategy = new StorageStrategy();
storageStrategy.setClazz("org.opennms.netmgt.collection.support.IndexStorageStrategy");
rt.setStorageStrategy(storageStrategy);
PersistenceSelectorStrategy persistenceSelectorStrategy = new PersistenceSelectorStrategy();
persistenceSelectorStrategy.setClazz("org.opennms.netmgt.collectd.PersistRegexSelectorStrategy");
Parameter param = new Parameter();
param.setKey(PersistRegexSelectorStrategy.MATCH_EXPRESSION);
param.setValue("#name matches '^agalue.*$'");
persistenceSelectorStrategy.addParameter(param);
rt.setPersistenceSelectorStrategy(persistenceSelectorStrategy);
GenericIndexResourceType resourceType = new GenericIndexResourceType(agent, snmpCollection, rt);
resourceA = new GenericIndexResource(resourceType, rt.getName(), new SnmpInstId("1.2.3.4.5.6.7.8.9.1.1"));
AttributeGroupType groupType = new AttributeGroupType("mib2-interfaces", AttributeGroupType.IF_TYPE_ALL);
MibObject mibObject = new MibObject();
mibObject.setOid(".1.2.3.4.5.6.7.8.9.2.1");
mibObject.setInstance("1");
mibObject.setAlias("name");
mibObject.setType("string");
StringAttributeType attributeType = new StringAttributeType(resourceType, snmpCollection.getName(), mibObject, groupType);
SnmpValue snmpValue = new Snmp4JValueFactory().getOctetString("agalue rules!".getBytes());
resourceA.setAttributeValue(attributeType, snmpValue);
resourceB = new GenericIndexResource(resourceType, rt.getName(), new SnmpInstId("1.2.3.4.5.6.7.8.9.1.2"));
}
use of org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy 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.PersistenceSelectorStrategy 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;
}
use of org.opennms.netmgt.config.datacollection.PersistenceSelectorStrategy 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.PersistenceSelectorStrategy in project opennms by OpenNMS.
the class WSManCollectorTest method canGenerateManyResources.
/**
* NMS-8924: Verifies that the generated collection set includes a resource
* for every node (XML) in the response.
*/
@Test
public void canGenerateManyResources() {
// Define our resource type, and create a supplier that returns a new instance on every call
NodeLevelResource node = mock(NodeLevelResource.class);
ResourceType rt = new ResourceType();
rt.setName("wsProcIndex");
rt.setLabel("Processor (wsman)");
rt.setResourceLabel("Processor (${wmiOSCpuName})");
StorageStrategy strategy = new StorageStrategy();
strategy.setClazz(SiblingColumnStorageStrategy.class.getCanonicalName());
strategy.addParameter(new Parameter("sibling-column-name", "wmiOSCpuName"));
rt.setStorageStrategy(strategy);
PersistenceSelectorStrategy pstrategy = new PersistenceSelectorStrategy();
pstrategy.setClazz(PersistAllSelectorStrategy.class.getCanonicalName());
rt.setPersistenceSelectorStrategy(pstrategy);
final AtomicInteger instanceId = new AtomicInteger();
Supplier<Resource> resourceSupplier = () -> {
return new GenericTypeResource(node, rt, Integer.toString(instanceId.getAndIncrement()));
};
// Define our group
Group group = new Group();
group.setName("windows-os-wmi-processor");
addAttribute(group, "Name", "wmiOSCpuName", AttributeType.STRING);
addAttribute(group, "InterruptsPersec", "wmiOSCpuIntsPerSec", AttributeType.GAUGE);
addAttribute(group, "PercentProcessorTime", "wmiOSCpuPctProcTime", AttributeType.GAUGE);
addAttribute(group, "PercentDPCTime", "wmiOSCpuPctDPCTime", AttributeType.GAUGE);
addAttribute(group, "PercentInterruptTime", "wmiOSCpuPctIntrTime", AttributeType.GAUGE);
addAttribute(group, "PercentUserTime", "wmiOSCpuPctUserTime", AttributeType.GAUGE);
// Mock the agent
CollectionAgent agent = mock(CollectionAgent.class);
when(agent.getStorageResourcePath()).thenReturn(ResourcePath.get());
CollectionSetBuilder builder = new CollectionSetBuilder(agent);
// Sample data
XMLTag xmlTag = XMLDoc.newDocument(true).addRoot("body").addTag("Win32_PerfFormattedData_PerfOS_Processor").addTag("Name").setText("c0").addTag("InterruptsPersec").setText("95").gotoRoot().addTag("Win32_PerfFormattedData_PerfOS_Processor").addTag("Name").setText("c1").addTag("InterruptsPersec").setText("100");
List<Node> nodes = xmlTag.gotoRoot().getChildElement().stream().map(el -> (Node) el).collect(Collectors.toList());
// Process the data and generate the collection set
WsManCollector.processEnumerationResults(group, builder, resourceSupplier, nodes);
// Verify the result
assertEquals(Arrays.asList("wsProcIndex/c0/windows-os-wmi-processor/wmiOSCpuName[c0,null]", "wsProcIndex/c0/windows-os-wmi-processor/wmiOSCpuIntsPerSec[null,95.0]", "wsProcIndex/c1/windows-os-wmi-processor/wmiOSCpuName[c1,null]", "wsProcIndex/c1/windows-os-wmi-processor/wmiOSCpuIntsPerSec[null,100.0]"), CollectionSetUtils.flatten(builder.build()));
}
Aggregations