Search in sources :

Example 11 with PrefabGraph

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

the class PropertiesGraphDaoIT method testPrefabConfigDirectoryMixedSingleAndMultiReports.

/**
     * Test that properties files in an included directory with
     * multiple graphs defined in some, and single graphs in others, are loaded correctly
     */
@Test
public void testPrefabConfigDirectoryMixedSingleAndMultiReports() throws IOException {
    File rootFile = m_fileAnticipator.tempFile("snmp-graph.properties");
    File graphDirectory = m_fileAnticipator.tempDir("snmp-graph.properties.d");
    File multiFile = m_fileAnticipator.tempFile(graphDirectory, "mib2-1.properties");
    File graphBits = m_fileAnticipator.tempFile(graphDirectory, "mib2.bits.properties");
    File graphHCbits = m_fileAnticipator.tempFile(graphDirectory, "mib2.HCbits.properties");
    m_outputStream = new FileOutputStream(rootFile);
    m_writer = new OutputStreamWriter(m_outputStream, StandardCharsets.UTF_8);
    m_writer.write(s_baseIncludePrefab);
    m_writer.close();
    m_outputStream.close();
    graphDirectory.mkdir();
    m_outputStream = new FileOutputStream(graphBits);
    m_writer = new OutputStreamWriter(m_outputStream, StandardCharsets.UTF_8);
    m_writer.write(s_separateBitsGraph);
    m_writer.close();
    m_outputStream.close();
    m_outputStream = new FileOutputStream(graphHCbits);
    m_writer = new OutputStreamWriter(m_outputStream, StandardCharsets.UTF_8);
    m_writer.write(s_separateHCBitsGraph);
    m_writer.close();
    m_outputStream.close();
    graphDirectory.mkdir();
    m_outputStream = new FileOutputStream(multiFile);
    m_writer = new OutputStreamWriter(m_outputStream, StandardCharsets.UTF_8);
    m_writer.write(s_includedMultiGraph1);
    m_writer.close();
    m_outputStream.close();
    HashMap<String, Resource> prefabConfigs = new HashMap<String, Resource>();
    prefabConfigs.put("performance", new FileSystemResource(rootFile));
    PropertiesGraphDao dao = createPropertiesGraphDao(prefabConfigs, s_emptyMap);
    //Check the graphs, basically ensuring that a handful of unique but easily checkable 
    // bits are uniquely what they should be.
    //We check all 4 graphs
    PrefabGraph mib2Bits = dao.getPrefabGraph("mib2.bits");
    assertNotNull(mib2Bits);
    assertEquals("mib2.bits", mib2Bits.getName());
    assertEquals("Bits In/Out", mib2Bits.getTitle());
    String[] columns1 = { "ifInOctets", "ifOutOctets" };
    Assert.assertArrayEquals(columns1, mib2Bits.getColumns());
    PrefabGraph mib2HCBits = dao.getPrefabGraph("mib2.HCbits");
    assertNotNull(mib2HCBits);
    assertEquals("mib2.HCbits", mib2HCBits.getName());
    assertEquals("Bits In/Out", mib2HCBits.getTitle());
    String[] columns2 = { "ifHCInOctets", "ifHCOutOctets" };
    Assert.assertArrayEquals(columns2, mib2HCBits.getColumns());
    PrefabGraph mib2Discards = dao.getPrefabGraph("mib2.discards");
    assertNotNull(mib2Discards);
    assertEquals("mib2.discards", mib2Discards.getName());
    assertEquals("Discards In/Out", mib2Discards.getTitle());
    String[] columns3 = { "ifInDiscards", "ifOutDiscards" };
    Assert.assertArrayEquals(columns3, mib2Discards.getColumns());
    PrefabGraph mib2Errors = dao.getPrefabGraph("mib2.errors");
    assertNotNull(mib2Errors);
    assertEquals("mib2.errors", mib2Errors.getName());
    assertEquals("Errors In/Out", mib2Errors.getTitle());
    String[] columns4 = { "ifInErrors", "ifOutErrors" };
    Assert.assertArrayEquals(columns4, mib2Errors.getColumns());
}
Also used : PrefabGraph(org.opennms.netmgt.model.PrefabGraph) HashMap(java.util.HashMap) FileOutputStream(java.io.FileOutputStream) FileSystemResource(org.springframework.core.io.FileSystemResource) OnmsResource(org.opennms.netmgt.model.OnmsResource) Resource(org.springframework.core.io.Resource) OutputStreamWriter(java.io.OutputStreamWriter) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) Test(org.junit.Test)

Example 12 with PrefabGraph

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

the class PropertiesGraphDaoIT method testGetDescription.

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

Example 13 with PrefabGraph

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

the class PropertiesGraphDaoIT method testCompareToEquals.

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

Example 14 with PrefabGraph

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

the class PropertiesGraphDaoIT method testTwoTypes.

@Test
public void testTwoTypes() throws Exception {
    PropertiesGraphDao dao = createPropertiesGraphDao(s_emptyMap, s_emptyMap);
    String ourConfig = s_responsePrefab.replaceAll("report.icmp.type=responseTime", "report.icmp.type=responseTime, distributedStatus");
    ByteArrayInputStream in = new ByteArrayInputStream(ourConfig.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 should not be null", graph.getTypes());
    assertEquals("graph type count", 2, graph.getTypes().length);
    assertEquals("graph type 1", "responseTime", graph.getTypes()[0]);
    assertEquals("graph type 2", "distributedStatus", graph.getTypes()[1]);
    assertTrue("should have responseTime type", graph.hasMatchingType("responseTime"));
    assertTrue("should have distributedStatus type", graph.hasMatchingType("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)

Example 15 with PrefabGraph

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

the class PropertiesGraphDaoIT method testGetColumns.

@Test
public void testGetColumns() {
    PrefabGraph bits = m_graphs.get("mib2.bits").getObject();
    ;
    String[] columns = bits.getColumns();
    assertEquals("getColumns().length", 2, columns.length);
    assertEquals("getColumns()[0]", "ifInOctets", columns[0]);
    assertEquals("getColumns()[1]", "ifOutOctets", columns[1]);
}
Also used : PrefabGraph(org.opennms.netmgt.model.PrefabGraph) 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