Search in sources :

Example 36 with PrefabGraph

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

the class PropertiesGraphDaoIT method testPrefabConfigDirectoryMultiReports.

/**
     * Test that properties files in an included directory with
     * multiple graphs defined in them are loaded correctly
     */
@Test
public void testPrefabConfigDirectoryMultiReports() throws IOException {
    File rootFile = m_fileAnticipator.tempFile("snmp-graph.properties");
    File graphDirectory = m_fileAnticipator.tempDir("snmp-graph.properties.d");
    File multiFile1 = m_fileAnticipator.tempFile(graphDirectory, "mib2.bits1.properties");
    File multiFile2 = m_fileAnticipator.tempFile(graphDirectory, "mib2.bits2.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(multiFile1);
    m_writer = new OutputStreamWriter(m_outputStream, StandardCharsets.UTF_8);
    m_writer.write(s_includedMultiGraph1);
    m_writer.close();
    m_outputStream.close();
    m_outputStream = new FileOutputStream(multiFile2);
    m_writer = new OutputStreamWriter(m_outputStream, StandardCharsets.UTF_8);
    m_writer.write(s_includedMultiGraph2);
    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 37 with PrefabGraph

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

the class PropertiesGraphDaoIT method testGetPropertiesValues.

@Test
public void testGetPropertiesValues() {
    PrefabGraph discards = m_graphs.get("mib2.discards").getObject();
    ;
    String[] values = discards.getPropertiesValues();
    assertEquals("getPropertiesValues().length", 1, values.length);
    assertEquals("getPropertiesValues()[0]", "ifSpeed", values[0]);
}
Also used : PrefabGraph(org.opennms.netmgt.model.PrefabGraph) Test(org.junit.Test)

Example 38 with PrefabGraph

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

the class PropertiesGraphDaoIT method testCompareToGreaterThan.

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

Example 39 with PrefabGraph

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

the class PropertiesGraphDaoIT method testGetPrefabGraphsForResourceWithSuppressUnused.

@Test
public void testGetPrefabGraphsForResourceWithSuppressUnused() {
    MockResourceType resourceType = new MockResourceType();
    resourceType.setName("interface");
    HashSet<OnmsAttribute> attributes = new HashSet<OnmsAttribute>(0);
    attributes.add(new RrdGraphAttribute("ifHCInOctets", "", ""));
    attributes.add(new RrdGraphAttribute("ifHCOutOctets", "", ""));
    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.HCbits", 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 40 with PrefabGraph

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

the class PropertiesGraphDaoIT method testBasicPrefabConfigDirectorySingleReports.

/**
     * Test that individual graph files in an include directory are loaded as expected
     */
@Test
public void testBasicPrefabConfigDirectorySingleReports() throws IOException {
    File rootFile = m_fileAnticipator.tempFile("snmp-graph.properties");
    File graphDirectory = m_fileAnticipator.tempDir("snmp-graph.properties.d");
    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();
    HashMap<String, Resource> prefabConfigs = new HashMap<String, Resource>();
    prefabConfigs.put("performance", new FileSystemResource(rootFile));
    PropertiesGraphDao dao = createPropertiesGraphDao(prefabConfigs, s_emptyMap);
    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());
}
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)

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