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