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());
}
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]);
}
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));
}
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());
}
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());
}
Aggregations