use of org.opennms.features.mibcompiler.services.PrefabGraphDumper in project opennms by OpenNMS.
the class JsmiMibParserTest method testGenerateGraphTemplates.
/**
* Test generate graph templates.
*
* @throws Exception the exception
*/
@Test
public void testGenerateGraphTemplates() throws Exception {
if (parser.parseMib(new File(MIB_DIR, "Clavister-MIB.mib"))) {
List<PrefabGraph> graphs = parser.getPrefabGraphs();
StringWriter writer = new StringWriter();
PrefabGraphDumper dumper = new PrefabGraphDumper();
dumper.dump(graphs, writer);
System.out.println(writer.getBuffer().toString());
// FIXME we should implement a more comprehensive check here.
Assert.assertEquals(102533, writer.getBuffer().toString().length());
PropertiesGraphDao dao = new PropertiesGraphDao();
StringBuffer sb = new StringBuffer();
sb.append("command.prefix=/usr/bin/rrdtool\n");
sb.append("output.mime=image/png\n");
sb.append(writer.getBuffer().toString());
dao.loadProperties("performance", new ByteArrayInputStream(sb.toString().getBytes()));
Assert.assertEquals(graphs.size(), dao.getAllPrefabGraphs().size());
for (PrefabGraph g : graphs) {
try {
PrefabGraph graph = dao.getPrefabGraph(g.getName());
Assert.assertEquals(g.getTitle(), graph.getTitle());
} catch (ObjectRetrievalFailureException e) {
Assert.fail(e.getMessage());
}
}
} else {
Assert.fail("The Clavister-MIB.mib file couldn't be parsed successfully.");
}
}
use of org.opennms.features.mibcompiler.services.PrefabGraphDumper in project opennms by OpenNMS.
the class DataCollectionWindow method generateGraphTemplates.
/**
* Generate graph templates.
*
* @param parser the MIB parser
* @param logger the logger
*/
public void generateGraphTemplates(final MibParser parser, final Logger logger) {
final File configDir = new File(ConfigFileConstants.getHome(), "etc" + File.separatorChar + "snmp-graph.properties.d");
final File file = new File(configDir, parser.getMibName().replaceAll(" ", "_") + "-graph.properties");
try {
FileWriter writer = new FileWriter(file);
List<PrefabGraph> graphs = parser.getPrefabGraphs();
PrefabGraphDumper dumper = new PrefabGraphDumper();
dumper.dump(graphs, writer);
writer.close();
logger.info("Graph templates successfully generated on " + file);
} catch (Exception e) {
logger.error("Can't generate the graph templates on " + file);
}
}
Aggregations