Search in sources :

Example 46 with ResourcePath

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);
}
Also used : ResourcePath(org.opennms.netmgt.model.ResourcePath) CollectionSetBuilder(org.opennms.netmgt.collection.support.builder.CollectionSetBuilder) SnmpCollectionAgent(org.opennms.netmgt.collectd.SnmpCollectionAgent) GenericTypeResource(org.opennms.netmgt.collection.support.builder.GenericTypeResource) NodeLevelResource(org.opennms.netmgt.collection.support.builder.NodeLevelResource) CollectionSet(org.opennms.netmgt.collection.api.CollectionSet) Test(org.junit.Test)

Example 47 with ResourcePath

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);
}
Also used : ResourcePath(org.opennms.netmgt.model.ResourcePath) RequestDispatcher(javax.servlet.RequestDispatcher)

Example 48 with ResourcePath

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();
    }
}
Also used : Path(java.nio.file.Path) ResourcePath(org.opennms.netmgt.model.ResourcePath) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) InitializingBean(org.springframework.beans.factory.InitializingBean) Map(java.util.Map) Path(java.nio.file.Path) Properties(java.util.Properties) Logger(org.slf4j.Logger) Files(java.nio.file.Files) Predicate(java.util.function.Predicate) RrdMetaDataUtils(org.opennms.netmgt.rrd.RrdMetaDataUtils) RrdStrategy(org.opennms.netmgt.rrd.RrdStrategy) Set(java.util.Set) Throwables(com.google.common.base.Throwables) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) ResourceStorageDao(org.opennms.netmgt.dao.api.ResourceStorageDao) Collectors(java.util.stream.Collectors) Maps(com.google.common.collect.Maps) File(java.io.File) BeanUtils(org.opennms.core.spring.BeanUtils) Stream(java.util.stream.Stream) ResourcePath(org.opennms.netmgt.model.ResourcePath) Preconditions(com.google.common.base.Preconditions) Collections(java.util.Collections) IOException(java.io.IOException)

Example 49 with ResourcePath

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;
}
Also used : ResourcePath(org.opennms.netmgt.model.ResourcePath) OnmsResource(org.opennms.netmgt.model.OnmsResource)

Example 50 with ResourcePath

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;
}
Also used : ResourcePath(org.opennms.netmgt.model.ResourcePath) Sample(org.opennms.newts.api.Sample) Resource(org.opennms.newts.api.Resource) Map(java.util.Map)

Aggregations

ResourcePath (org.opennms.netmgt.model.ResourcePath)57 OnmsResource (org.opennms.netmgt.model.OnmsResource)19 OnmsAttribute (org.opennms.netmgt.model.OnmsAttribute)14 Test (org.junit.Test)13 ArrayList (java.util.ArrayList)9 MockResourceType (org.opennms.netmgt.mock.MockResourceType)9 RrdGraphAttribute (org.opennms.netmgt.model.RrdGraphAttribute)8 HashSet (java.util.HashSet)6 Map (java.util.Map)6 CollectionResource (org.opennms.netmgt.collection.api.CollectionResource)6 Parameter (org.opennms.netmgt.config.datacollection.Parameter)6 Resource (org.opennms.newts.api.Resource)6 SnmpCollectionAgent (org.opennms.netmgt.collectd.SnmpCollectionAgent)5 CollectionSetBuilder (org.opennms.netmgt.collection.support.builder.CollectionSetBuilder)5 Sample (org.opennms.newts.api.Sample)5 Path (java.nio.file.Path)4 NodeLevelResource (org.opennms.netmgt.collection.support.builder.NodeLevelResource)4 IOException (java.io.IOException)3 ObjectNameStorageStrategy (org.opennms.netmgt.collection.support.ObjectNameStorageStrategy)3 OnmsNode (org.opennms.netmgt.model.OnmsNode)3