use of org.opennms.netmgt.model.ResourcePath in project opennms by OpenNMS.
the class ThresholdingVisitorIT method testThresholdFiltersOnGenericResourceWithSiblingColumnStorageStrategy.
/**
* Verifies that we are able to generate thresholds for CollectionSets
* using GenericTypeResource resources that use the SiblingColumnStorageStrategy.
*
* Resources of this type are commonly used by the WS-Man collector,
* where data is returned in a tabular format and the resource name is set using
* the SiblingColumnStorageStrategy.
*
* In the case of the WS-Man collector, the instance ids are generated systematically
* and will differ from one collection run to another. For this reason, it's important
* that the thresholder keys it's state based off of the resource label, and not
* the instance id - this test will validate this.
*/
@Test
public void testThresholdFiltersOnGenericResourceWithSiblingColumnStorageStrategy() throws Exception {
initFactories("/threshd-configuration.xml", "/test-thresholds-wsman.xml");
ThresholdingVisitor visitor = createVisitor();
SnmpCollectionAgent agent = createCollectionAgent();
NodeLevelResource nodeResource = new NodeLevelResource(agent.getNodeId());
org.opennms.netmgt.config.datacollection.ResourceType wmiLogicalDisk = createWmiLogicalDiskResourceType();
// Expect a low threshold event (as configured in test-thresholds-wsman.xml)
addEvent(// uei
"uei.opennms.org/threshold/lowThresholdExceededWSManLogStorage", // ipaddr
"127.0.0.1", // service
"SNMP", // trigger
2, // threshold
10240.0, // rearm
12288.0, // value
1.0, // label
"HarddiskVolume16", // instance
"volume16-1", // ds
"wmiLDPctFreeMBytes", // iflabel
null, // ifindex
null, m_anticipator, m_anticipatedEvents);
// Visit the collection set twice (the trigger is set to 2)
for (int i = 0; i < 2; i++) {
// A resource for each drive, with a unique instance on each iteration
GenericTypeResource volume16 = new GenericTypeResource(nodeResource, wmiLogicalDisk, "volume16-" + i);
GenericTypeResource iDrive = new GenericTypeResource(nodeResource, wmiLogicalDisk, "iDrive" + i);
// Create the entries in strings.properties
ResourcePath path = ResourcePath.get("snmp", "1", "wmiLogicalDisk", "HarddiskVolume16");
m_resourceStorageDao.setStringAttribute(path, "wmiLDName", "HarddiskVolume16");
path = ResourcePath.get("snmp", "1", "wmiLogicalDisk", "I");
m_resourceStorageDao.setStringAttribute(path, "wmiLDName", "I");
// Build a collection set containing attributes for both resources
CollectionSet collectionSet = new CollectionSetBuilder(agent).withStringAttribute(volume16, "windows-os-wmi-LogicalDisk", "wmiLDName", "HarddiskVolume16").withNumericAttribute(volume16, "windows-os-wmi-LogicalDisk", "wmiLDPctFreeMBytes", 1.0, AttributeType.GAUGE).withNumericAttribute(volume16, "windows-os-wmi-LogicalDisk", "wmiLDPctFreeSpace", 10, AttributeType.GAUGE).withStringAttribute(iDrive, "windows-os-wmi-LogicalDisk", "wmiLDName", "I").withNumericAttribute(iDrive, "windows-os-wmi-LogicalDisk", "wmiLDPctFreeMBytes", 2668498.0, AttributeType.GAUGE).withNumericAttribute(iDrive, "windows-os-wmi-LogicalDisk", "wmiLDPctFreeSpace", 10, AttributeType.GAUGE).build();
collectionSet.visit(visitor);
}
// Verify!
verifyEvents(0);
}
use of org.opennms.netmgt.model.ResourcePath in project opennms by OpenNMS.
the class DeleteNodesServlet method doPost.
/**
* {@inheritDoc}
*/
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
List<Integer> nodeList = getList(request.getParameterValues("nodeCheck"));
List<Integer> nodeDataList = getList(request.getParameterValues("nodeData"));
for (Integer nodeId : nodeDataList) {
// Get a list of response time IP address lists
List<String> ipAddrs = getIpAddrsForNode(nodeId);
ResourcePath nodeSnmpPath = new ResourcePath(ResourceTypeUtils.SNMP_DIRECTORY, Integer.toString(nodeId));
if (m_resourceStorageDao.exists(nodeSnmpPath, 0)) {
LOG.debug("Attempting to delete node data directory: {}", nodeSnmpPath);
if (m_resourceStorageDao.delete(nodeSnmpPath)) {
LOG.info("Node SNMP data directory deleted successfully: {}", nodeSnmpPath);
} else {
LOG.warn("Node SNMP data directory *not* deleted successfully: {}", nodeSnmpPath);
}
}
// Response time RRD directories
for (String ipAddr : ipAddrs) {
ResourcePath ifResponseTimePath = new ResourcePath(ResourceTypeUtils.RESPONSE_DIRECTORY, ipAddr);
if (m_resourceStorageDao.exists(ifResponseTimePath, 0)) {
LOG.debug("Attempting to delete node response time data directory: {}", ifResponseTimePath);
if (m_resourceStorageDao.delete(ifResponseTimePath)) {
LOG.info("Node response time data directory deleted successfully: {}", ifResponseTimePath);
} else {
LOG.warn("Node response time data directory *not* deleted successfully: {}", ifResponseTimePath);
}
}
}
}
// Now, tell capsd to delete the node from the database
for (Integer nodeId : nodeList) {
sendDeleteNodeEvent(nodeId);
LOG.debug("End of delete of node {}", nodeId);
}
// forward the request for proper display
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/admin/deleteNodesFinish.jsp");
dispatcher.forward(request, response);
}
use of org.opennms.netmgt.model.ResourcePath in project opennms by OpenNMS.
the class FilesystemResourceStorageDao method children.
@Override
public Set<ResourcePath> children(ResourcePath path, int depth) {
Preconditions.checkArgument(depth > 0, "depth must be positive");
final Path root = toPath(path);
if (!Files.isDirectory(root)) {
return Collections.emptySet();
}
try (Stream<Path> stream = Files.list(root)) {
return // filter for directories
stream.filter(p -> p.toFile().isDirectory()).filter(// filter for folders with metrics
p -> exists(p, depth - 1)).map(p -> ResourcePath.get(path, p.toFile().getName())).collect(Collectors.toSet());
} catch (IOException e) {
LOG.error("Failed to list {}. Returning empty set of children.", path, e);
return Collections.emptySet();
}
}
use of org.opennms.netmgt.model.ResourcePath in project opennms by OpenNMS.
the class NodeResourceType method createResourceForNode.
protected OnmsResource createResourceForNode(OnmsNode node) {
final ResourcePath path = getResourcePathForNode(node);
final LazyChildResourceLoader loader = new LazyChildResourceLoader(m_resourceDao);
final String resourceName = node.getForeignSource() != null && node.getForeignId() != null ? String.format("%s:%s", node.getForeignSource(), node.getForeignId()) : Integer.toString(node.getId());
final OnmsResource resource = new OnmsResource(resourceName, node.getLabel(), this, s_emptyAttributeSet, new LazyList<OnmsResource>(loader), path);
resource.setEntity(node);
loader.setParent(resource);
return resource;
}
use of org.opennms.netmgt.model.ResourcePath in project opennms by OpenNMS.
the class NewtsPersistOperationBuilder method getSamplesToIndex.
public List<Sample> getSamplesToIndex() {
final List<Sample> samples = Lists.newLinkedList();
// Convert string attributes to samples
for (Entry<ResourcePath, Map<String, String>> entry : m_stringAttributesByPath.entrySet()) {
Resource resource = new Resource(toResourceId(entry.getKey()), Optional.of(entry.getValue()));
samples.add(NewtsUtils.createSampleForIndexingStrings(m_context, resource));
}
return samples;
}
Aggregations