Search in sources :

Example 11 with Event

use of org.opennms.netmgt.xml.eventconf.Event in project opennms by OpenNMS.

the class SendEventController method buildEventSelect.

private String buildEventSelect() throws IOException, FileNotFoundException {
    List<Event> events = m_eventConfDao.getEventsByLabel();
    StringBuffer buffer = new StringBuffer();
    List<String> excludeList = getExcludeList();
    TreeMap<String, String> sortedMap = new TreeMap<String, String>();
    for (Event e : events) {
        String uei = e.getUei();
        // System.out.println(uei);
        String label = e.getEventLabel();
        // System.out.println(label);
        String trimmedUei = stripUei(uei);
        if (!excludeList.contains(trimmedUei)) {
            sortedMap.put(label, uei);
        // System.out.println("sortedMap.put('"+label+"', '"+uei+"')");
        }
    }
    for (Map.Entry<String, String> me : sortedMap.entrySet()) {
        buffer.append("<option value=" + me.getValue() + ">" + me.getKey() + "</option>");
    }
    return buffer.toString();
}
Also used : Event(org.opennms.netmgt.xml.eventconf.Event) TreeMap(java.util.TreeMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 12 with Event

use of org.opennms.netmgt.xml.eventconf.Event 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)

Example 13 with Event

use of org.opennms.netmgt.xml.eventconf.Event in project opennms by OpenNMS.

the class SpectrumTrapImporter method makeEventConf.

public Event makeEventConf(AlertMapping mapping, EventDisposition dispo) throws IOException {
    Event evt = new Event();
    evt.setMask(makeEventMask(mapping));
    evt.setUei(makeUei(mapping.getEventCode()));
    evt.setEventLabel(makeEventLabel(mapping));
    evt.setDescr(makeDescr(mapping));
    evt.setLogmsg(makeLogMsg(mapping, dispo));
    evt.setSeverity(makeSeverity(mapping, dispo));
    if (makeAlarmData(mapping, dispo) != null) {
        evt.setAlarmData(makeAlarmData(mapping, dispo));
    }
    evt.setVarbindsdecode(makeVarbindsDecodes(mapping));
    if (shouldDiscardEvent(dispo)) {
        LOG.warn("Not creating an OpenNMS event definition corresponding to the following Spectrum event-disposition, because doing so would cause a conflict with an existing alarm-creating event for the same event-code and discriminators: {}. Hand-tweaking the output may be needed to compensate for this omission.", dispo);
        return null;
    }
    return evt;
}
Also used : Event(org.opennms.netmgt.xml.eventconf.Event)

Example 14 with Event

use of org.opennms.netmgt.xml.eventconf.Event in project opennms by OpenNMS.

the class SpectrumTrapImporter method makeEvents.

public Events makeEvents() throws IOException {
    Events events = new Events();
    for (AlertMapping mapping : m_alertMappings) {
        for (EventDisposition dispo : m_eventDispositions) {
            if (dispo.getEventCode().equals(mapping.getEventCode())) {
                Event evt = makeEventConf(mapping, dispo);
                if (evt == null) {
                    continue;
                }
                events.addEvent(evt);
            }
        }
    }
    LOG.debug("Made {} events", events.getEventCollection().size());
    return events;
}
Also used : Events(org.opennms.netmgt.xml.eventconf.Events) Event(org.opennms.netmgt.xml.eventconf.Event)

Example 15 with Event

use of org.opennms.netmgt.xml.eventconf.Event in project opennms by OpenNMS.

the class EventFormTest method testGroupField.

/**
     * Test the group field.
     *
     * @throws Exception the exception
     */
@Test
public void testGroupField() throws Exception {
    EventForm form = new EventForm();
    FieldGroup group = form.eventEditor;
    Field<?> uei = group.getField("uei");
    Assert.assertTrue(uei instanceof TextField);
    Assert.assertEquals("uei.opennms.org/newEvent", uei.getValue());
    Field<?> logMsgDest = group.getField("logmsg.dest");
    Assert.assertNotNull(logMsgDest);
    Assert.assertTrue(logMsgDest instanceof ComboBox);
    Assert.assertEquals(LogDestType.LOGNDISPLAY, logMsgDest.getValue());
    String eventUei = "uei.opennms.org/ietf/mplsTeStdMib/traps/mplsTunnelUp";
    Event event = dao.findByUei(eventUei);
    Assert.assertNotNull(event);
    form.setEvent(event);
    logMsgDest = group.getField("logmsg.dest");
    Assert.assertNotNull(logMsgDest);
    Assert.assertTrue(logMsgDest instanceof ComboBox);
    Assert.assertEquals(event.getLogmsg().getDest(), logMsgDest.getValue());
}
Also used : FieldGroup(com.vaadin.data.fieldgroup.FieldGroup) ComboBox(com.vaadin.ui.ComboBox) TextField(com.vaadin.ui.TextField) Event(org.opennms.netmgt.xml.eventconf.Event) Test(org.junit.Test)

Aggregations

Event (org.opennms.netmgt.xml.eventconf.Event)27 Test (org.junit.Test)15 SyntaxToEvent (org.opennms.netmgt.model.events.snmp.SyntaxToEvent)12 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)6 Events (org.opennms.netmgt.xml.eventconf.Events)4 Varbindsdecode (org.opennms.netmgt.xml.eventconf.Varbindsdecode)4 File (java.io.File)3 List (java.util.List)3 Mask (org.opennms.netmgt.xml.eventconf.Mask)3 Maskelement (org.opennms.netmgt.xml.eventconf.Maskelement)3 ArrayList (java.util.ArrayList)2 TreeMap (java.util.TreeMap)2 FieldGroup (com.vaadin.data.fieldgroup.FieldGroup)1 ComboBox (com.vaadin.ui.ComboBox)1 TextField (com.vaadin.ui.TextField)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 StringWriter (java.io.StringWriter)1 Map (java.util.Map)1 Mib (net.percederberg.mibble.Mib)1 AlarmData (org.opennms.netmgt.xml.eventconf.AlarmData)1