Search in sources :

Example 36 with OnmsAttribute

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

the class AttributeMatchingResourceVisitorTest method testVisitWithMatch.

public void testVisitWithMatch() throws Exception {
    AttributeMatchingResourceVisitor resourceVisitor = new AttributeMatchingResourceVisitor();
    resourceVisitor.setAttributeVisitor(m_attributeVisitor);
    resourceVisitor.setAttributeMatch("ifInOctets");
    resourceVisitor.afterPropertiesSet();
    MockResourceType resourceType = new MockResourceType();
    resourceType.setName("interfaceSnmp");
    OnmsAttribute attribute = new RrdGraphAttribute("ifInOctets", "something", "something else");
    OnmsResource resource = new OnmsResource("1", "Node One", resourceType, Collections.singleton(attribute), ResourcePath.get("foo"));
    m_attributeVisitor.visit(attribute);
    m_mocks.replayAll();
    resourceVisitor.visit(resource);
    m_mocks.verifyAll();
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Example 37 with OnmsAttribute

use of org.opennms.netmgt.model.OnmsAttribute 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)

Example 38 with OnmsAttribute

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

the class DefaultRrdDaoIntegrationTest method testPrintValue.

public void testPrintValue() throws Exception {
    long start = System.currentTimeMillis();
    long end = start + (24 * 60 * 60 * 1000);
    OnmsResource topResource = new OnmsResource("1", "Node One", new MockResourceType(), new HashSet<OnmsAttribute>(0), new ResourcePath("foo"));
    OnmsAttribute attribute = new RrdGraphAttribute("ifInOctets", "snmp/1/eth0", "ifInOctets.jrb");
    HashSet<OnmsAttribute> attributeSet = new HashSet<OnmsAttribute>(1);
    attributeSet.add(attribute);
    MockResourceType childResourceType = new MockResourceType();
    OnmsResource childResource = new OnmsResource("eth0", "Interface One: eth0", childResourceType, attributeSet, new ResourcePath("foo"));
    childResource.setParent(topResource);
    File snmp = m_fileAnticipator.tempDir(ResourceTypeUtils.SNMP_DIRECTORY);
    File node = m_fileAnticipator.tempDir(snmp, topResource.getName());
    File intf = m_fileAnticipator.tempDir(node, childResource.getName());
    RrdDataSource rrdDataSource = new RrdDataSource(attribute.getName(), RrdAttributeType.GAUGE, 600, "U", "U");
    RrdDef def = m_rrdStrategy.createDefinition("test", intf.getAbsolutePath(), attribute.getName(), 600, Collections.singletonList(rrdDataSource), Collections.singletonList("RRA:AVERAGE:0.5:1:100"));
    m_rrdStrategy.createFile(def);
    File rrdFile = m_fileAnticipator.expecting(intf, attribute.getName() + m_rrdStrategy.getDefaultFileExtension());
    RrdDb rrdFileObject = m_rrdStrategy.openFile(rrdFile.getAbsolutePath());
    for (int i = 0; i < 10; i++) {
        m_rrdStrategy.updateFile(rrdFileObject, "test", (start / 1000 + 300 * i) + ":1");
    }
    m_rrdStrategy.closeFile(rrdFileObject);
    Double value = m_dao.getPrintValue(childResource.getAttributes().iterator().next(), "AVERAGE", start, end);
    assertNotNull("value should not be null", value);
    assertEquals("value", 1.0, value);
}
Also used : RrdDef(org.jrobin.core.RrdDef) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) OnmsResource(org.opennms.netmgt.model.OnmsResource) ResourcePath(org.opennms.netmgt.model.ResourcePath) RrdDataSource(org.opennms.netmgt.rrd.RrdDataSource) RrdDb(org.jrobin.core.RrdDb) File(java.io.File) MockResourceType(org.opennms.netmgt.mock.MockResourceType) HashSet(java.util.HashSet)

Example 39 with OnmsAttribute

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

the class DefaultRrdDaoTest method testFetchLastValue.

public void testFetchLastValue() throws Exception {
    String rrdDir = "snmp" + File.separator + "1" + File.separator + "eth0";
    String rrdFile = "ifInOctets.jrb";
    OnmsResource topResource = new OnmsResource("1", "Node One", new MockResourceType(), new HashSet<OnmsAttribute>(0), new ResourcePath("foo"));
    OnmsAttribute attribute = new RrdGraphAttribute("ifInOctets", rrdDir, rrdFile);
    HashSet<OnmsAttribute> attributeSet = new HashSet<OnmsAttribute>(1);
    attributeSet.add(attribute);
    MockResourceType childResourceType = new MockResourceType();
    OnmsResource childResource = new OnmsResource("eth0", "Interface One: eth0", childResourceType, attributeSet, new ResourcePath("foo"));
    childResource.setParent(topResource);
    int interval = 300000;
    Double expectedValue = new Double(1.0);
    String fullRrdFilePath = m_dao.getRrdBaseDirectory().getAbsolutePath() + File.separator + rrdDir + File.separator + rrdFile;
    expect(m_rrdStrategy.fetchLastValue(fullRrdFilePath, attribute.getName(), interval)).andReturn(expectedValue);
    m_mocks.replayAll();
    Double value = m_dao.getLastFetchValue(attribute, interval);
    m_mocks.verifyAll();
    assertNotNull("last fetched value must not be null, but was null", value);
    assertEquals("last fetched value", expectedValue, value);
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) ResourcePath(org.opennms.netmgt.model.ResourcePath) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) MockResourceType(org.opennms.netmgt.mock.MockResourceType) HashSet(java.util.HashSet)

Example 40 with OnmsAttribute

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

the class TopNAttributeStatisticVisitorTest method testVisit.

public void testVisit() throws Exception {
    BottomNAttributeStatisticVisitor visitor = new TopNAttributeStatisticVisitor();
    visitor.setCount(20);
    visitor.afterPropertiesSet();
    Map<OnmsAttribute, Double> attributes = new HashMap<OnmsAttribute, Double>();
    attributes.put(new MockAttribute("foo"), 0.0);
    OnmsResource resource = new OnmsResource("1", "Node One", new MockResourceType(), attributes.keySet(), ResourcePath.get("foo"));
    resource.getAttributes();
    for (Entry<OnmsAttribute, Double> entry : attributes.entrySet()) {
        visitor.visit(entry.getKey(), entry.getValue());
    }
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) HashMap(java.util.HashMap) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Aggregations

OnmsAttribute (org.opennms.netmgt.model.OnmsAttribute)45 OnmsResource (org.opennms.netmgt.model.OnmsResource)40 MockResourceType (org.opennms.netmgt.mock.MockResourceType)30 RrdGraphAttribute (org.opennms.netmgt.model.RrdGraphAttribute)21 HashSet (java.util.HashSet)13 ResourcePath (org.opennms.netmgt.model.ResourcePath)13 Test (org.junit.Test)7 FetchResults (org.opennms.netmgt.measurements.api.FetchResults)7 Source (org.opennms.netmgt.measurements.model.Source)7 ExternalValueAttribute (org.opennms.netmgt.model.ExternalValueAttribute)7 LazySet (org.opennms.core.collections.LazySet)6 HashMap (java.util.HashMap)5 PrefabGraph (org.opennms.netmgt.model.PrefabGraph)5 AttributeStatistic (org.opennms.netmgt.model.AttributeStatistic)4 OnmsNode (org.opennms.netmgt.model.OnmsNode)3 OnmsResourceType (org.opennms.netmgt.model.OnmsResourceType)3 ResourceId (org.opennms.netmgt.model.ResourceId)3 StringPropertyAttribute (org.opennms.netmgt.model.StringPropertyAttribute)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2