use of org.opennms.netmgt.config.datacollection.ResourceType in project opennms by OpenNMS.
the class ResourceDaoIntegrityIT method createResourceTypes.
/**
* Define a resource type so that test the GenericIndexResourceType
*/
private Map<String, ResourceType> createResourceTypes() {
Map<String, ResourceType> types = new HashMap<String, ResourceType>();
ResourceType hrStorageIndex = new ResourceType();
hrStorageIndex.setName("hrStorageIndex");
hrStorageIndex.setLabel("Storage (SNMP MIB-2 Host Resources)");
hrStorageIndex.setResourceLabel("${hrStorageDescr}");
hrStorageIndex.setPersistenceSelectorStrategy(new PersistenceSelectorStrategy("org.opennms.netmgt.collectd.PersistAllSelectorStrategy"));
StorageStrategy storageStrategy = new StorageStrategy("org.opennms.netmgt.dao.support.SiblingColumnStorageStrategy");
storageStrategy.addParameter(new Parameter("sibling-column-name", "hrStorageDescr"));
storageStrategy.addParameter(new Parameter("replace-first", "s/^-$/_root_fs/"));
storageStrategy.addParameter(new Parameter("replace-all", "s/^-//"));
storageStrategy.addParameter(new Parameter("replace-all", "s/\\s//"));
storageStrategy.addParameter(new Parameter("replace-all", "s/:\\\\.*//"));
hrStorageIndex.setStorageStrategy(storageStrategy);
types.put(hrStorageIndex.getName(), hrStorageIndex);
return types;
}
use of org.opennms.netmgt.config.datacollection.ResourceType in project opennms by OpenNMS.
the class ResourceDaoIntegrityIT method walkResourceTree.
@Test
@Transactional
public void walkResourceTree() throws IOException {
// Setup the file tree and the necessary objects in the DAOs
createResourceTree();
createNodes();
Map<String, ResourceType> types = createResourceTypes();
expect(m_resourceTypesDao.getLastUpdate()).andReturn(new Date(System.currentTimeMillis())).anyTimes();
expect(m_resourceTypesDao.getResourceTypes()).andReturn(types).anyTimes();
m_easyMockUtils.replayAll();
m_resourceDao.afterPropertiesSet();
// Walk the tree and collect the results
ResourceCollector visitor = new ResourceCollector();
ResourceTreeWalker walker = new ResourceTreeWalker();
walker.setResourceDao(m_resourceDao);
walker.setVisitor(visitor);
walker.walk();
// We must have at least one resource for every known type
for (OnmsResourceType type : m_resourceDao.getResourceTypes()) {
// Ignore this type for now #needstoomanydbojects
if (DistributedStatusResourceType.TYPE_NAME.equals(type.getName())) {
continue;
}
// and should never be returned when enumerating resources
if (InterfaceSnmpByIfIndexResourceType.TYPE_NAME.equals(type.getName())) {
continue;
}
assertTrue("No resources of type: " + type.getLabel(), visitor.resourceTypes.contains(type));
}
// We must be able to retrieve the same resource by id
for (Entry<ResourceId, OnmsResource> entry : visitor.resourcesById.entrySet()) {
OnmsResource resourceRetrievedById = m_resourceDao.getResourceById(entry.getKey());
assertNotNull(String.format("Failed to retrieve resource with id '%s'.", entry.getKey()), resourceRetrievedById);
assertEquals(String.format("Result mismatch for resource with id '%s'. Retrieved id is '%s'.", entry.getKey(), resourceRetrievedById.getId()), entry.getValue().getName(), resourceRetrievedById.getName());
}
// Build a line that represent the resource for every unique id
// and compare it to the known results
int k = 0;
String[] expectedResults = loadExpectedResults();
for (Entry<ResourceId, OnmsResource> entry : visitor.resourcesById.entrySet()) {
// Convert the attributes to strings and order them lexicographically
Set<String> attributeNames = new TreeSet<>();
for (OnmsAttribute attribute : entry.getValue().getAttributes()) {
attributeNames.add(attribute.toString());
}
// Compare
String actualResult = entry.getKey() + ": " + attributeNames;
assertEquals(String.format("Result mismatch at line %d.", k + 1), expectedResults[k], actualResult);
k++;
}
// We should have as many unique resource ids as we have results
assertEquals(expectedResults.length, visitor.resourcesById.size());
m_easyMockUtils.verifyAll();
}
use of org.opennms.netmgt.config.datacollection.ResourceType in project opennms by OpenNMS.
the class DefaultDataCollectionConfigDao method processObjectList.
/**
* Takes a list of MibObj objects iterates over them
* creating corresponding MibObject objects and adding them to the supplied
* MibObject list.
* @param groupName TODO
* @param groupIfType TODO
* @param objectList
* List of MibObject objects parsed from
* 'datacollection-config.xml'
* @param mibObjectList
* List of MibObject objects currently being built
*/
private void processObjectList(final String groupName, final String groupIfType, final List<MibObj> objectList, final List<MibObject> mibObjectList) {
for (final MibObj mibObj : objectList) {
// Create a MibObject from the XML MibObj
final MibObject aMibObject = new MibObject();
aMibObject.setGroupName(groupName);
aMibObject.setGroupIfType(groupIfType);
aMibObject.setOid(mibObj.getOid());
aMibObject.setAlias(mibObj.getAlias());
aMibObject.setType(mibObj.getType());
aMibObject.setInstance(mibObj.getInstance());
aMibObject.setMaxval(mibObj.getMaxval());
aMibObject.setMinval(mibObj.getMinval());
final ResourceType resourceType = getConfiguredResourceTypes().get(mibObj.getInstance());
if (resourceType != null) {
aMibObject.setResourceType(resourceType);
}
// Add the MIB object provided it isn't already in the list
if (!mibObjectList.contains(aMibObject)) {
mibObjectList.add(aMibObject);
}
}
}
use of org.opennms.netmgt.config.datacollection.ResourceType in project opennms by OpenNMS.
the class TcaCollectorIT method setUp.
/**
* Sets the up.
*
* @throws Exception the exception
*/
@Before
public void setUp() throws Exception {
MockLogAppender.setupLogging();
m_tempFolder.newFolder("snmp");
m_resourceStorageDao.setRrdDirectory(m_tempFolder.getRoot());
OnmsIpInterface iface = null;
OnmsNode testNode = null;
Collection<OnmsNode> testNodes = m_nodeDao.findByLabel(TEST_NODE_LABEL);
if (testNodes == null || testNodes.size() < 1) {
NetworkBuilder builder = new NetworkBuilder();
builder.addNode(TEST_NODE_LABEL).setId(1).setSysObjectId(".1.3.6.1.4.1.1588.2.1.1.1");
InterfaceBuilder ifBldr = builder.addInterface(TEST_NODE_IP).setIsSnmpPrimary("P");
ifBldr.addSnmpInterface(6).setIfName("fw0").setPhysAddr("44:33:22:11:00").setIfType(144).setCollectionEnabled(true);
testNode = builder.getCurrentNode();
Assert.assertNotNull(testNode);
m_nodeDao.save(testNode);
m_nodeDao.flush();
} else {
testNode = testNodes.iterator().next();
}
Set<OnmsIpInterface> ifaces = testNode.getIpInterfaces();
Assert.assertEquals(1, ifaces.size());
iface = ifaces.iterator().next();
SnmpPeerFactory.setInstance(m_snmpPeerFactory);
m_collectionAgent = DefaultSnmpCollectionAgent.create(iface.getId(), m_ipInterfaceDao, m_transactionManager);
TcaRrd rrd = new TcaRrd();
rrd.addRra("RRA:AVERAGE:0.5:1:3600");
rrd.addRra("RRA:AVERAGE:0.5:300:288");
rrd.addRra("RRA:MIN:0.5:300:288");
rrd.addRra("RRA:MAX:0.5:300:288");
rrd.addRra("RRA:AVERAGE:0.5:900:2880");
rrd.addRra("RRA:MIN:0.5:900:2880");
rrd.addRra("RRA:MAX:0.5:900:2880");
rrd.addRra("RRA:AVERAGE:0.5:3600:4300");
rrd.addRra("RRA:MIN:0.5:3600:4300");
rrd.addRra("RRA:MAX:0.5:3600:4300");
TcaDataCollection tcadc = new TcaDataCollection();
tcadc.setName("default");
tcadc.setRrd(rrd);
TcaDataCollectionConfig tcadcc = new TcaDataCollectionConfig();
tcadcc.addDataCollection(tcadc);
tcadcc.setRrdRepository(getSnmpRoot().getAbsolutePath());
EasyMock.expect(m_configDao.getConfig()).andReturn(tcadcc).atLeastOnce();
EasyMock.replay(m_configDao);
// Define the resource type
ResourceType resourceType = getJuniperTcaEntryResourceType();
m_resourceTypesDao = EasyMock.createMock(ResourceTypesDao.class);
EasyMock.expect(m_resourceTypesDao.getResourceTypeByName(TcaCollectionHandler.RESOURCE_TYPE_NAME)).andReturn(resourceType).anyTimes();
EasyMock.replay(m_resourceTypesDao);
}
use of org.opennms.netmgt.config.datacollection.ResourceType 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
CollectionSet collectionSet = builder.build();
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(collectionSet));
assertEquals(Sets.newHashSet("c0", "c1"), CollectionSetUtils.getResourcesByLabel(collectionSet).keySet());
}
Aggregations