Search in sources :

Example 86 with OnmsResource

use of org.opennms.netmgt.model.OnmsResource in project opennms by OpenNMS.

the class FilterResourceWalker method walk.

/**
 * <p>walk</p>
 *
 * @param node a {@link org.opennms.netmgt.model.OnmsNode} object.
 */
public void walk(OnmsNode node) {
    OnmsResource resource = getResourceDao().getResourceForNode(node);
    m_resourceWalker.walk(Collections.singleton(resource));
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource)

Example 87 with OnmsResource

use of org.opennms.netmgt.model.OnmsResource in project opennms by OpenNMS.

the class InterfaceSnmpResourceType method getResourceByParentPathAndInterface.

private OnmsResource getResourceByParentPathAndInterface(ResourcePath parent, String intf, String label, Long ifSpeed, String ifSpeedFriendly) throws DataAccessException {
    final ResourcePath path = ResourcePath.get(parent, intf);
    final AttributeLoader loader = new AttributeLoader(m_resourceStorageDao, path, ifSpeed, ifSpeedFriendly);
    final Set<OnmsAttribute> set = new LazySet<OnmsAttribute>(loader);
    return new OnmsResource(intf, label, this, set, path);
}
Also used : LazySet(org.opennms.core.collections.LazySet) ResourcePath(org.opennms.netmgt.model.ResourcePath) OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute)

Example 88 with OnmsResource

use of org.opennms.netmgt.model.OnmsResource in project opennms by OpenNMS.

the class AbstractRrdBasedFetchStrategy method fetch.

/**
 * {@inheritDoc}
 */
@Override
public FetchResults fetch(long start, long end, long step, int maxrows, Long interval, Long heartbeat, List<Source> sources, boolean relaxed) throws Exception {
    final Map<String, Object> constants = Maps.newHashMap();
    final Map<Source, String> rrdsBySource = Maps.newHashMap();
    for (final Source source : sources) {
        final ResourceId resourceId;
        try {
            resourceId = ResourceId.fromString(source.getResourceId());
        } catch (final IllegalArgumentException ex) {
            if (relaxed)
                continue;
            LOG.error("Ill-formed resource id: {}", source.getResourceId(), ex);
            return null;
        }
        // Grab the resource
        final OnmsResource resource = m_resourceDao.getResourceById(resourceId);
        if (resource == null) {
            if (relaxed)
                continue;
            LOG.error("No resource with id: {}", source.getResourceId());
            return null;
        }
        // Grab the attribute
        RrdGraphAttribute rrdGraphAttribute = resource.getRrdGraphAttributes().get(source.getAttribute());
        if (rrdGraphAttribute == null && !Strings.isNullOrEmpty(source.getFallbackAttribute())) {
            LOG.error("No attribute with name '{}', using fallback-attribute with name '{}'", source.getAttribute(), source.getFallbackAttribute());
            source.setAttribute(source.getFallbackAttribute());
            source.setFallbackAttribute(null);
            rrdGraphAttribute = resource.getRrdGraphAttributes().get(source.getAttribute());
        }
        if (rrdGraphAttribute == null) {
            if (relaxed)
                continue;
            LOG.error("No attribute with name: {}", source.getAttribute());
            return null;
        }
        // Gather the values from strings.properties
        Utils.convertStringAttributesToConstants(source.getLabel(), resource.getStringPropertyAttributes(), constants);
        // Build the path to the archive
        final String rrdFile = System.getProperty("rrd.base.dir") + File.separator + rrdGraphAttribute.getRrdRelativePath();
        rrdsBySource.put(source, rrdFile);
    }
    // Fetch
    return fetchMeasurements(start, end, step, maxrows, rrdsBySource, constants, sources, relaxed);
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) ResourceId(org.opennms.netmgt.model.ResourceId) Source(org.opennms.netmgt.measurements.model.Source) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute)

Example 89 with OnmsResource

use of org.opennms.netmgt.model.OnmsResource in project opennms by OpenNMS.

the class NrtController method createCollectionJobs.

private List<CollectionJob> createCollectionJobs(OnmsResource reportResource, PrefabGraph prefabGraph, String nrtCollectionTaskId) {
    List<CollectionJob> collectionJobs = new ArrayList<CollectionJob>();
    OnmsResource nodeResource = reportResource.getParent();
    OnmsNode node = m_nodeDao.get(nodeResource.getName());
    Integer nodeId = node.getId();
    Date createTimestamp = new Date();
    // What protocols are involved?
    // For each protocol build a new CollectionJob
    Set<RrdGraphAttribute> relevantRrdGraphAttributes = getRequiredRrdGraphAttributes(reportResource, prefabGraph);
    Map<String, String> rrdGraphAttributesMetaData = getMetaDataForReport(relevantRrdGraphAttributes);
    Map<String, List<MetricTuple>> metricsByProtocol = getMetricIdsByProtocol(rrdGraphAttributesMetaData);
    // Destinations for MeasurementSets
    Set<String> resultDestinations = new HashSet<String>();
    resultDestinations.add(nrtCollectionTaskId);
    for (final Map.Entry<String, List<MetricTuple>> entry : metricsByProtocol.entrySet()) {
        final String protocol = entry.getKey();
        final List<MetricTuple> tuples = entry.getValue();
        final CollectionJob collectionJob = new DefaultCollectionJob();
        collectionJob.setService(protocol);
        collectionJob.setNodeId(nodeId);
        collectionJob.setCreationTimestamp(createTimestamp);
        for (final MetricTuple metricTuple : tuples) {
            collectionJob.addMetric(metricTuple.getMetricId(), resultDestinations, metricTuple.getOnmsLogicMetricId());
        }
        // I know....
        if (protocol.equals("SNMP") || protocol.equals("TCA")) {
            collectionJob.setNetInterface(protocol);
            OnmsMonitoringLocation location = node.getLocation();
            String locationName = (location == null) ? null : location.getLocationName();
            final SnmpAgentConfig snmpAgentConfig = m_snmpAgentConfigFactory.getAgentConfig(node.getPrimaryInterface().getIpAddress(), locationName);
            collectionJob.setProtocolConfiguration(snmpAgentConfig.toProtocolConfigString());
            collectionJob.setNetInterface(node.getPrimaryInterface().getIpAddress().getHostAddress());
            collectionJobs.add(collectionJob);
        } else {
            logger.error("Protocol '{}' is not supported yet. CollectionJob will be ignorred.", protocol);
        }
    }
    return collectionJobs;
}
Also used : SnmpAgentConfig(org.opennms.netmgt.snmp.SnmpAgentConfig) OnmsNode(org.opennms.netmgt.model.OnmsNode) DefaultCollectionJob(org.opennms.nrtg.api.model.DefaultCollectionJob) ArrayList(java.util.ArrayList) Date(java.util.Date) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) OnmsResource(org.opennms.netmgt.model.OnmsResource) DefaultCollectionJob(org.opennms.nrtg.api.model.DefaultCollectionJob) CollectionJob(org.opennms.nrtg.api.model.CollectionJob) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)

Example 90 with OnmsResource

use of org.opennms.netmgt.model.OnmsResource in project opennms by OpenNMS.

the class NewtsFetchStrategyTest method createMockResource.

public Source createMockResource(final String label, final String attr, final String node, boolean expect) {
    OnmsResourceType type = EasyMock.createNiceMock(OnmsResourceType.class);
    final int nodeId = node.hashCode();
    final String newtsResourceId = "response:" + node + ":" + attr;
    final ResourceId resourceId = ResourceId.get("nodeSource", "NODES:" + nodeId).resolve("responseTime", node);
    OnmsResource resource = m_resources.get(resourceId);
    if (resource == null) {
        resource = new OnmsResource(attr, label, type, Sets.newHashSet(), ResourcePath.get("foo"));
        m_resources.put(resourceId, resource);
    }
    Set<OnmsAttribute> attributes = resource.getAttributes();
    attributes.add(new RrdGraphAttribute(attr, "", newtsResourceId));
    Results<Measurement> results = new Results<>();
    Resource res = new Resource(newtsResourceId);
    Row<Measurement> row = new Row<Measurement>(Timestamp.fromEpochSeconds(0), res);
    Measurement measurement = new Measurement(Timestamp.fromEpochSeconds(0), res, label, 0.0d);
    row.addElement(measurement);
    results.addRow(row);
    if (expect) {
        EasyMock.expect(m_sampleRepository.select(EasyMock.eq(m_context), EasyMock.eq(res), EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject(), EasyMock.anyObject())).andReturn(results);
    }
    final Source source = new Source();
    source.setAggregation("AVERAGE");
    source.setAttribute(attr);
    source.setLabel(label);
    source.setResourceId(resourceId.toString());
    source.setTransient(false);
    return source;
}
Also used : Measurement(org.opennms.newts.api.Measurement) OnmsResource(org.opennms.netmgt.model.OnmsResource) Resource(org.opennms.newts.api.Resource) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) Source(org.opennms.netmgt.measurements.model.Source) OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsResourceType(org.opennms.netmgt.model.OnmsResourceType) ResourceId(org.opennms.netmgt.model.ResourceId) FetchResults(org.opennms.netmgt.measurements.api.FetchResults) Results(org.opennms.newts.api.Results) Row(org.opennms.newts.api.Results.Row)

Aggregations

OnmsResource (org.opennms.netmgt.model.OnmsResource)143 Test (org.junit.Test)54 OnmsAttribute (org.opennms.netmgt.model.OnmsAttribute)40 MockResourceType (org.opennms.netmgt.mock.MockResourceType)31 OnmsNode (org.opennms.netmgt.model.OnmsNode)28 RrdGraphAttribute (org.opennms.netmgt.model.RrdGraphAttribute)23 File (java.io.File)22 ResourcePath (org.opennms.netmgt.model.ResourcePath)19 ArrayList (java.util.ArrayList)14 HashSet (java.util.HashSet)14 PrefabGraph (org.opennms.netmgt.model.PrefabGraph)12 HashMap (java.util.HashMap)11 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)11 ResourceId (org.opennms.netmgt.model.ResourceId)11 Date (java.util.Date)10 Source (org.opennms.netmgt.measurements.model.Source)8 LinkedList (java.util.LinkedList)7 FetchResults (org.opennms.netmgt.measurements.api.FetchResults)7 ExternalValueAttribute (org.opennms.netmgt.model.ExternalValueAttribute)7 ModelAndView (org.springframework.web.servlet.ModelAndView)7