Search in sources :

Example 6 with PrefabGraph

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

the class PropertiesGraphDaoIT method testGetName.

@Test
public void testGetName() {
    PrefabGraph bits = m_graphs.get("mib2.bits").getObject();
    ;
    assertEquals("getName", "mib2.bits", bits.getName());
}
Also used : PrefabGraph(org.opennms.netmgt.model.PrefabGraph) Test(org.junit.Test)

Example 7 with PrefabGraph

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

the class PropertiesGraphDaoIT method testGetPrefabGraphsForResource.

@Test
public void testGetPrefabGraphsForResource() {
    MockResourceType resourceType = new MockResourceType();
    resourceType.setName("interface");
    HashSet<OnmsAttribute> attributes = new HashSet<OnmsAttribute>(0);
    attributes.add(new RrdGraphAttribute("ifInOctets", "", ""));
    attributes.add(new RrdGraphAttribute("ifOutOctets", "", ""));
    attributes.add(new ExternalValueAttribute("ifSpeed", ""));
    OnmsResource resource = new OnmsResource("node", "1", resourceType, attributes, ResourcePath.get("foo"));
    PrefabGraph[] graphs = m_dao.getPrefabGraphsForResource(resource);
    assertEquals("prefab graph array size", 1, graphs.length);
    assertEquals("prefab graph[0] name", "mib2.bits", graphs[0].getName());
}
Also used : OnmsResource(org.opennms.netmgt.model.OnmsResource) PrefabGraph(org.opennms.netmgt.model.PrefabGraph) OnmsAttribute(org.opennms.netmgt.model.OnmsAttribute) RrdGraphAttribute(org.opennms.netmgt.model.RrdGraphAttribute) ExternalValueAttribute(org.opennms.netmgt.model.ExternalValueAttribute) MockResourceType(org.opennms.netmgt.mock.MockResourceType) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 8 with PrefabGraph

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

the class PropertiesGraphDaoIT method testPrefabGraphPartlyBorkedConfig.

/**
     * Test that we can load a partly borked config file (i.e. if one graph is incorrectly specified,
     * we load as many of the rest as we can).
     * The borked'ness we can tolerate does not include poor double quoting which confuses the underlying
     * Java properties parser, but misspelled property names should only affect the graph in question.
     * 
     * NB: It should still complain with an Error log.  Should there be an event as well?
     * @throws Exception
     */
@Test
public void testPrefabGraphPartlyBorkedConfig() throws Exception {
    //We're expecting an ERROR log, and will be most disappointed if
    // we don't get it.  Turn off the default check in runTest
    m_testSpecificLoggingTest = true;
    PropertiesGraphDao dao = createPropertiesGraphDao(s_emptyMap, s_emptyMap);
    dao.loadProperties("foo", new ByteArrayInputStream(s_partlyBorkedPrefab.getBytes(StandardCharsets.UTF_8)));
    //We expect to be able to get a mib2.HCbits, and a mib2.discards, but no mib2.bits 
    try {
        PrefabGraph mib2bits = dao.getPrefabGraph("mib2.bits");
        fail("Should have thrown an ObjectRetrievalFailureException retrieving graph " + mib2bits);
    } catch (ObjectRetrievalFailureException e) {
    }
    PrefabGraph mib2HCbits = dao.getPrefabGraph("mib2.HCbits");
    assertNotNull(mib2HCbits);
    PrefabGraph mib2Discards = dao.getPrefabGraph("mib2.discards");
    assertNotNull(mib2Discards);
}
Also used : PrefabGraph(org.opennms.netmgt.model.PrefabGraph) ByteArrayInputStream(java.io.ByteArrayInputStream) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException) Test(org.junit.Test)

Example 9 with PrefabGraph

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

the class PropertiesGraphDaoIT method testGetCommand.

@Test
public void testGetCommand() {
    String expectedCommand = "--title=\"Bits In/Out\" " + "DEF:octIn={rrd1}:ifInOctets:AVERAGE " + "DEF:octOut={rrd2}:ifOutOctets:AVERAGE " + "CDEF:bitsIn=octIn,8,* " + "CDEF:bitsOut=octOut,8,* " + "CDEF:totBits=octIn,octOut,+,8,* " + "AREA:totBits#00ff00:\"Total\" " + "GPRINT:totBits:AVERAGE:\" Avg  \\: %8.2lf %s\\n\" " + "LINE2:bitsIn#0000ff:\"Bits In\" " + "GPRINT:bitsIn:AVERAGE:\" Avg  \\: %8.2lf %s\" " + "GPRINT:bitsIn:MIN:\"Min  \\: %8.2lf %s\" " + "GPRINT:bitsIn:MAX:\"Max  \\: %8.2lf %s\\n\" " + "LINE2:bitsOut#ff0000:\"Bits Out\" " + "GPRINT:bitsOut:AVERAGE:\"Avg  \\: %8.2lf %s\" " + "GPRINT:bitsOut:MIN:\"Min  \\: %8.2lf %s\" " + "GPRINT:bitsOut:MAX:\"Max  \\: %8.2lf %s\\n\"";
    PrefabGraph bits = m_graphs.get("mib2.bits").getObject();
    ;
    assertEquals("getCommand", expectedCommand, bits.getCommand());
}
Also used : PrefabGraph(org.opennms.netmgt.model.PrefabGraph) Test(org.junit.Test)

Example 10 with PrefabGraph

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

the class PropertiesGraphDaoIT method testOneType.

@Test
public void testOneType() throws Exception {
    PropertiesGraphDao dao = createPropertiesGraphDao(s_emptyMap, s_emptyMap);
    ByteArrayInputStream in = new ByteArrayInputStream(s_responsePrefab.getBytes());
    dao.loadProperties("response", in);
    PrefabGraphTypeDao type = dao.findPrefabGraphTypeDaoByName("response");
    assertNotNull("could not get response prefab graph type", type);
    PrefabGraph graph = type.getQuery("icmp");
    assertNotNull("could not get icmp response prefab graph type", graph);
    assertNotNull("graph type list should not be null", graph.getTypes());
    assertEquals("graph type was not specified the list should be empty", 1, graph.getTypes().length);
    assertEquals("graph type 1", "responseTime", graph.getTypes()[0]);
    assertTrue("should have responseTime type", graph.hasMatchingType("responseTime"));
    assertFalse("should not have distributedStatus type", graph.hasMatchingType("distributedStatus"));
    assertTrue("should have responseTime or distributedStatus type", graph.hasMatchingType("responseTime", "distributedStatus"));
}
Also used : PrefabGraph(org.opennms.netmgt.model.PrefabGraph) ByteArrayInputStream(java.io.ByteArrayInputStream) PrefabGraphTypeDao(org.opennms.netmgt.dao.support.PropertiesGraphDao.PrefabGraphTypeDao) Test(org.junit.Test)

Aggregations

PrefabGraph (org.opennms.netmgt.model.PrefabGraph)50 Test (org.junit.Test)28 OnmsResource (org.opennms.netmgt.model.OnmsResource)16 File (java.io.File)8 ArrayList (java.util.ArrayList)8 FileSystemResource (org.springframework.core.io.FileSystemResource)8 HashMap (java.util.HashMap)7 ObjectRetrievalFailureException (org.springframework.orm.ObjectRetrievalFailureException)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 OnmsAttribute (org.opennms.netmgt.model.OnmsAttribute)5 Resource (org.springframework.core.io.Resource)5 FileOutputStream (java.io.FileOutputStream)4 OutputStreamWriter (java.io.OutputStreamWriter)4 HashSet (java.util.HashSet)4 Report (org.opennms.netmgt.config.kscReports.Report)4 MockResourceType (org.opennms.netmgt.mock.MockResourceType)4 RrdGraphAttribute (org.opennms.netmgt.model.RrdGraphAttribute)4 Calendar (java.util.Calendar)3 LinkedHashMap (java.util.LinkedHashMap)3 Graph (org.opennms.netmgt.config.kscReports.Graph)3