Search in sources :

Example 1 with Mib

use of net.percederberg.mibble.Mib in project opennms by OpenNMS.

the class Mib2Events method printEvents.

public void printEvents(PrintStream out) throws MarshalException, ValidationException, ParserConfigurationException, SAXException, IOException {
    if (m_loader == null) {
        throw new IllegalStateException("convert() must be called first");
    }
    for (Mib mib : m_loader.getAllMibs()) {
        if (!mib.isLoaded()) {
            continue;
        }
        Events events = convertMibToEvents(mib, getEffectiveUeiBase());
        if (events.getEventCount() < 1) {
            System.err.println("No trap or notification definitions found in this MIB (" + mib.getName() + "), exiting");
            System.exit(0);
        }
        if (!m_compat) {
            StringWriter writer = new StringWriter();
            events.marshal(writer);
            stripXmlNameSpace(writer.toString(), out);
        } else {
            for (Event event : events.getEventCollection()) {
                StringWriter writer = new StringWriter();
                event.marshal(writer);
                ByteArrayOutputStream formattedXml = new ByteArrayOutputStream();
                stripXmlNameSpace(writer.toString(), formattedXml);
                String noXmlProcessingInstruction = formattedXml.toString().replaceAll("(?m)<\\?xml version=\"1.0\" encoding=\"UTF-8\"\\?>\n", "");
                out.print(noXmlProcessingInstruction.replaceAll("dest=\"logndisplay\"", "dest='logndisplay'"));
            }
        }
    }
}
Also used : StringWriter(java.io.StringWriter) Events(org.opennms.netmgt.xml.eventconf.Events) Mib(net.percederberg.mibble.Mib) Event(org.opennms.netmgt.xml.eventconf.Event) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 StringWriter (java.io.StringWriter)1 Mib (net.percederberg.mibble.Mib)1 Event (org.opennms.netmgt.xml.eventconf.Event)1 Events (org.opennms.netmgt.xml.eventconf.Events)1