Search in sources :

Example 11 with OnmsResource

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

the class RrdGraphHelper method checkLabelForQuotes.

/**
     * Checks a resource label for quotes.
     *
     * @param childResource the child resource to check
     * @return the resource
     */
private OnmsResource checkLabelForQuotes(OnmsResource childResource) {
    String lbl = Util.convertToJsSafeString(childResource.getLabel());
    OnmsResource resource = new OnmsResource(childResource.getName(), lbl, childResource.getResourceType(), childResource.getAttributes(), childResource.getPath());
    resource.setParent(childResource.getParent());
    resource.setEntity(childResource.getEntity());
    resource.setLink(childResource.getLink());
    return resource;
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource)

Example 12 with OnmsResource

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

the class TopNAttributeStatisticVisitorTest method testVisitGetResultsLimitedByCount.

public void testVisitGetResultsLimitedByCount() throws Exception {
    BottomNAttributeStatisticVisitor visitor = new TopNAttributeStatisticVisitor();
    visitor.setCount(20);
    visitor.afterPropertiesSet();
    Map<OnmsAttribute, Double> attributes = new HashMap<OnmsAttribute, Double>();
    for (int i = 0; i < 100; i++) {
        attributes.put(new MockAttribute("foo"), 0.0 + i);
    }
    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());
    }
    SortedSet<AttributeStatistic> top = visitor.getResults();
    assertNotNull("topN list should not be null", top);
    assertEquals("topN list size", 20, top.size());
    int i = 0;
    for (AttributeStatistic stat : top) {
        assertEquals("topN[" + i + "] value", 99.0 - i, stat.getStatistic());
        i++;
    }
}
Also used : HashMap(java.util.HashMap) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) OnmsResource(org.opennms.netmgt.model.OnmsResource) AttributeStatistic(org.opennms.netmgt.model.AttributeStatistic) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

Example 13 with OnmsResource

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

the class RrdResourceAttributeUtilsTest method testLoadPropertiesNonEmpty.

@Test
public void testLoadPropertiesNonEmpty() throws Exception {
    OnmsResource childResource = createResource();
    createPropertiesFile(childResource, "foo=bar", false);
    Properties p = RrdResourceAttributeUtils.getStringProperties(m_fileAnticipator.getTempDir(), "snmp/1/eth0");
    assertNotNull("properties should not be null", p);
    assertEquals("properties size", 1, p.size());
    assertNotNull("property 'foo' should exist", p.get("foo"));
    assertEquals("property 'foo' value", "bar", p.get("foo"));
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) Properties(java.util.Properties) Test(org.junit.Test)

Example 14 with OnmsResource

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

the class RrdResourceAttributeUtilsTest method testLoadPropertiesDoesNotExist.

@Test
public void testLoadPropertiesDoesNotExist() throws Exception {
    OnmsResource childResource = createResource();
    createPropertiesFile(childResource, "", true);
    Properties p = RrdResourceAttributeUtils.getStringProperties(m_fileAnticipator.getTempDir(), "snmp/1/eth0");
    assertNull("no properties file was created, so the properties object should be null", p);
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) Properties(java.util.Properties) Test(org.junit.Test)

Example 15 with OnmsResource

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

the class RrdStatisticAttributeVisitorTest method testVisitWithNonRrdAttribute.

public void testVisitWithNonRrdAttribute() throws Exception {
    RrdStatisticAttributeVisitor attributeVisitor = new RrdStatisticAttributeVisitor();
    attributeVisitor.setFetchStrategy(m_fetchStrategy);
    attributeVisitor.setConsolidationFunction("AVERAGE");
    attributeVisitor.setStartTime(m_startTime);
    attributeVisitor.setEndTime(m_endTime);
    attributeVisitor.setStatisticVisitor(m_statisticVisitor);
    attributeVisitor.afterPropertiesSet();
    MockResourceType resourceType = new MockResourceType();
    resourceType.setName("something other than interfaceSnmp");
    OnmsAttribute attribute = new StringPropertyAttribute("ifInOctets", "one billion octets!");
    attribute.setResource(new OnmsResource("1", "Node One", resourceType, Collections.singleton(attribute), ResourcePath.get("foo")));
    m_mocks.replayAll();
    attributeVisitor.visit(attribute);
    m_mocks.verifyAll();
}
Also used : StringPropertyAttribute(org.opennms.netmgt.model.StringPropertyAttribute) OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) MockResourceType(org.opennms.netmgt.mock.MockResourceType)

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