Search in sources :

Example 6 with OnmsResourceType

use of org.opennms.netmgt.model.OnmsResourceType 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<Measurement>();
    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)

Example 7 with OnmsResourceType

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

the class CustomSpringConfiguration method createResourceDao.

@Bean(name = "resourceDao")
public ResourceDao createResourceDao() {
    return new ResourceDao() {

        @Override
        public Collection<OnmsResourceType> getResourceTypes() {
            throw new UnsupportedOperationException();
        }

        @Override
        public List<OnmsResource> findTopLevelResources() {
            throw new UnsupportedOperationException();
        }

        @Override
        public OnmsResource getResourceById(ResourceId id) {
            if (id.toString().startsWith("node[1]")) {
                final OnmsResource onmsResource = new OnmsResource(id.toString(), id.toString(), new InterfaceSnmpResourceType(null), new HashSet<OnmsAttribute>(), new ResourcePath());
                if (id.toString().contains("interfaceSnmp[127.0.0.1]")) {
                    final RrdGraphAttribute attribute = new RrdGraphAttribute();
                    attribute.setName("ifInErrors");
                    attribute.setResource(onmsResource);
                    onmsResource.getAttributes().add(attribute);
                }
                return onmsResource;
            }
            return null;
        }

        @Override
        public OnmsResource getResourceForNode(OnmsNode node) {
            throw new UnsupportedOperationException();
        }

        @Override
        public OnmsResource getResourceForIpInterface(OnmsIpInterface ipInterface, OnmsLocationMonitor locationMonitor) {
            throw new UnsupportedOperationException();
        }

        @Override
        public boolean deleteResourceById(ResourceId resourceId) {
            throw new UnsupportedOperationException();
        }
    };
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) InterfaceSnmpResourceType(org.opennms.netmgt.dao.support.InterfaceSnmpResourceType) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) OnmsResource(org.opennms.netmgt.model.OnmsResource) ResourcePath(org.opennms.netmgt.model.ResourcePath) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsResourceType(org.opennms.netmgt.model.OnmsResourceType) ResourceId(org.opennms.netmgt.model.ResourceId) ResourceDao(org.opennms.netmgt.dao.api.ResourceDao) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) Bean(org.springframework.context.annotation.Bean)

Aggregations

OnmsResourceType (org.opennms.netmgt.model.OnmsResourceType)7 OnmsResource (org.opennms.netmgt.model.OnmsResource)5 OnmsAttribute (org.opennms.netmgt.model.OnmsAttribute)3 ResourceId (org.opennms.netmgt.model.ResourceId)3 OnmsNode (org.opennms.netmgt.model.OnmsNode)2 RrdGraphAttribute (org.opennms.netmgt.model.RrdGraphAttribute)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 TreeSet (java.util.TreeSet)1 Test (org.junit.Test)1 ResourceType (org.opennms.netmgt.config.datacollection.ResourceType)1 FilterOperator (org.opennms.netmgt.config.threshd.FilterOperator)1 ThresholdType (org.opennms.netmgt.config.threshd.ThresholdType)1 ResourceDao (org.opennms.netmgt.dao.api.ResourceDao)1 GenericIndexResourceType (org.opennms.netmgt.dao.support.GenericIndexResourceType)1 InterfaceSnmpResourceType (org.opennms.netmgt.dao.support.InterfaceSnmpResourceType)1 FetchResults (org.opennms.netmgt.measurements.api.FetchResults)1