Search in sources :

Example 1 with PrefabGraphDumper

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.");
    }
}
Also used : PrefabGraphDumper(org.opennms.features.mibcompiler.services.PrefabGraphDumper) PrefabGraph(org.opennms.netmgt.model.PrefabGraph) StringWriter(java.io.StringWriter) ByteArrayInputStream(java.io.ByteArrayInputStream) PropertiesGraphDao(org.opennms.netmgt.dao.support.PropertiesGraphDao) ObjectRetrievalFailureException(org.springframework.orm.ObjectRetrievalFailureException) File(java.io.File) Test(org.junit.Test)

Example 2 with PrefabGraphDumper

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);
    }
}
Also used : PrefabGraphDumper(org.opennms.features.mibcompiler.services.PrefabGraphDumper) PrefabGraph(org.opennms.netmgt.model.PrefabGraph) FileWriter(java.io.FileWriter) File(java.io.File)

Aggregations

File (java.io.File)2 PrefabGraphDumper (org.opennms.features.mibcompiler.services.PrefabGraphDumper)2 PrefabGraph (org.opennms.netmgt.model.PrefabGraph)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileWriter (java.io.FileWriter)1 StringWriter (java.io.StringWriter)1 Test (org.junit.Test)1 PropertiesGraphDao (org.opennms.netmgt.dao.support.PropertiesGraphDao)1 ObjectRetrievalFailureException (org.springframework.orm.ObjectRetrievalFailureException)1