Search in sources :

Example 11 with Events

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

the class SPC592Test method testIsisMibTrapOids.

/**
     * Test trap-OIDs in events from ISIS-MIB notifications.
     *
     * @throws Exception the exception
     */
@Test
public void testIsisMibTrapOids() throws Exception {
    if (!parser.parseMib(new File(MIB_DIR, "ISIS-MIB.mib"))) {
        Assert.fail("The ISIS-MIB.mib must parse successfully");
    } else {
        Assert.assertTrue(parser.getMissingDependencies().isEmpty());
    }
    Events isisEvents = parser.getEvents("uei.opennms.org/issues/SPC592/");
    assertEquals(isisEvents.getEvents().size(), 18);
    assertEquals("uei.opennms.org/issues/SPC592/isisAdjacencyChange", isisEvents.getEvents().get(16).getUei());
    boolean foundId = false;
    for (final Maskelement me : isisEvents.getEvents().get(16).getMask().getMaskelements()) {
        if ("id".equals(me.getMename())) {
            foundId = true;
        }
        if (foundId) {
            assertEquals("Only one me-value should be present for trap OID", 1, me.getMevalues().size());
            assertFalse("The 'id' mask-element value for the isisAdjacencyChange event must not end in .0", me.getMevalues().get(0).endsWith(".0"));
            assertEquals("The 'id' mask-element value for the isisAdjacencyChange event is incorrect", me.getMevalues().get(0), ".1.3.6.1.2.1.138");
            break;
        }
    }
    if (!foundId) {
        Assert.fail("Never found the 'id' mask-element in the isisAdjacencyChange event");
    }
    boolean foundSpecific = false;
    for (final Maskelement me : isisEvents.getEvents().get(16).getMask().getMaskelements()) {
        if ("specific".equals(me.getMename())) {
            foundSpecific = true;
        }
        if (foundSpecific) {
            assertEquals("Only one me-value should be present for the specific-type", 1, me.getMevalues().size());
            assertEquals("The 'specific' mask-element value for the isisAdjacencyChange event must be 17", me.getMevalues().get(0), "17");
        }
    }
    if (!foundSpecific) {
        Assert.fail("Never found the 'specific' mask-element in the isisAdjacencyChange event");
    }
}
Also used : Events(org.opennms.netmgt.xml.eventconf.Events) Maskelement(org.opennms.netmgt.xml.eventconf.Maskelement) File(java.io.File) Test(org.junit.Test)

Example 12 with Events

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

the class JsmiMibParserTest method testTraps.

/**
     * Test generate events from traps.
     */
@Test
public void testTraps() {
    if (parser.parseMib(new File(MIB_DIR, "RFC1269-MIB.txt"))) {
        Assert.assertEquals("RFC1269-MIB", parser.getMibName());
        Events events = parser.getEvents("uei.opennms.org/traps/RFC1269");
        Assert.assertNotNull(events);
        Assert.assertEquals(2, events.getEvents().size());
        System.out.println(JaxbUtils.marshal(events));
        Assert.assertEquals(2, events.getEvents().size());
        Event event = null;
        for (Event e : events.getEvents()) {
            if (e.getUei().contains("bgpBackwardTransition"))
                event = e;
        }
        Assert.assertNotNull(event);
        // TODO Must be more specific
        Assert.assertNotNull(event.getDescr());
        Assert.assertNotNull(event.getLogmsg());
        // TODO Must be more specific
        Assert.assertNotNull(event.getLogmsg().getContent());
        Assert.assertEquals("Indeterminate", event.getSeverity());
        Assert.assertEquals("RFC1269-MIB defined trap event: bgpBackwardTransition", event.getEventLabel());
        Assert.assertNotNull(event.getMask());
        for (final Maskelement me : event.getMask().getMaskelements()) {
            if (me.getMename().equals("id"))
                Assert.assertEquals(".1.3.6.1.2.1.15", me.getMevalues().get(0));
            if (me.getMename().equals("generic"))
                Assert.assertEquals("6", me.getMevalues().get(0));
            if (me.getMename().equals("specific"))
                Assert.assertEquals("2", me.getMevalues().get(0));
        }
        Assert.assertEquals(1, event.getVarbindsdecodes().size());
        for (Varbindsdecode vb : event.getVarbindsdecodes()) {
            if (vb.getParmid().equals("parm[#3]"))
                Assert.assertEquals(6, vb.getDecodes().size());
        }
    } else {
        Assert.fail("The RFC1269-MIB.txt file couldn't be parsed successfully.");
    }
}
Also used : Events(org.opennms.netmgt.xml.eventconf.Events) Varbindsdecode(org.opennms.netmgt.xml.eventconf.Varbindsdecode) Event(org.opennms.netmgt.xml.eventconf.Event) Maskelement(org.opennms.netmgt.xml.eventconf.Maskelement) File(java.io.File) Test(org.junit.Test)

Example 13 with Events

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

the class MibCompilerPanel method showEventsWindow.

/**
     * Shows the events window.
     *
     * @param logger the logger
     * @param fileName the file name
     * @param ueiBase the UEI base
     */
private void showEventsWindow(final Logger logger, final String fileName, final String ueiBase) {
    final Events events = mibParser.getEvents(ueiBase);
    if (events == null) {
        Notification.show("The MIB couldn't be processed for events because: " + mibParser.getFormattedErrors(), Notification.Type.ERROR_MESSAGE);
    } else {
        if (events.getEvents().size() > 0) {
            try {
                logger.info("Found " + events.getEvents().size() + " events.");
                final String eventsFileName = fileName.replaceFirst("\\..*$", ".events.xml");
                final File configDir = new File(ConfigFileConstants.getHome(), "etc" + File.separatorChar + "events");
                final File eventFile = new File(configDir, eventsFileName);
                final EventWindow w = new EventWindow(eventsDao, eventsProxy, eventFile, events, logger);
                getUI().addWindow(w);
            } catch (Throwable t) {
                Notification.show(t.getMessage(), Notification.Type.ERROR_MESSAGE);
            }
        } else {
            Notification.show("The MIB doesn't contain any notification/trap", Notification.Type.WARNING_MESSAGE);
        }
    }
}
Also used : Events(org.opennms.netmgt.xml.eventconf.Events) EventWindow(org.opennms.features.vaadin.events.EventWindow) File(java.io.File)

Example 14 with Events

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

the class EventPanel method saveFile.

/**
     * Save file.
     *
     * @param file the file
     * @param logger the logger
     */
private void saveFile(final File file, final Logger logger) {
    try {
        // Updating the base events object with the new events set.
        baseEventsObject.setEvents(eventTable.getOnmsEvents());
        // TODO Are other normalizations required ?
        for (org.opennms.netmgt.xml.eventconf.Event event : baseEventsObject.getEvents()) {
            logger.debug("Normalizing event " + event.getUei());
            final AlarmData ad = event.getAlarmData();
            if (ad != null && (ad.getReductionKey() == null || ad.getReductionKey().trim().isEmpty())) {
                event.setAlarmData(null);
            }
            final Mask m = event.getMask();
            if (m != null && m.getMaskelements().isEmpty()) {
                event.setMask(null);
            }
        }
        // Save the XML of the new events
        saveEvents(baseEventsObject, file, logger);
        // Add a reference to the new file into eventconf.xml if there are events
        String fileName = file.getAbsolutePath().replaceFirst(".*\\" + File.separatorChar + "events\\" + File.separatorChar + "(.*)", "events" + File.separatorChar + "$1");
        final Events rootEvents = eventConfDao.getRootEvents();
        final File rootFile = ConfigFileConstants.getFile(ConfigFileConstants.EVENT_CONF_FILE_NAME);
        if (baseEventsObject.getEvents().size() > 0) {
            if (!rootEvents.getEventFiles().contains(fileName)) {
                logger.info("Adding a reference to " + fileName + " inside eventconf.xml.");
                rootEvents.getEventFiles().add(0, fileName);
                saveEvents(rootEvents, rootFile, logger);
            }
        } else {
            // If a reference to an empty events file exist, it should be removed.
            if (rootEvents.getEventFiles().contains(fileName)) {
                logger.info("Removing a reference to " + fileName + " inside eventconf.xml because there are no events.");
                rootEvents.getEventFiles().remove(fileName);
                saveEvents(rootEvents, rootFile, logger);
            }
        }
        EventBuilder eb = new EventBuilder(EventConstants.EVENTSCONFIG_CHANGED_EVENT_UEI, "WebUI");
        eventProxy.send(eb.getEvent());
        logger.info("The event's configuration reload operation is being performed.");
        success();
    } catch (Exception e) {
        logger.error(e.getClass() + ": " + (e.getMessage() == null ? "[No Details]" : e.getMessage()));
        if (e.getMessage() == null) {
            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);
            logger.error(sw.toString());
        }
        failure(e.getMessage());
    }
}
Also used : Mask(org.opennms.netmgt.xml.eventconf.Mask) IOException(java.io.IOException) CommitException(com.vaadin.data.fieldgroup.FieldGroup.CommitException) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) StringWriter(java.io.StringWriter) Events(org.opennms.netmgt.xml.eventconf.Events) File(java.io.File) AlarmData(org.opennms.netmgt.xml.eventconf.AlarmData) PrintWriter(java.io.PrintWriter)

Example 15 with Events

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

the class EventconfFactoryIT method testIncludedEventFilesExistAndNoExtras.

/**
     * Test that every file included in eventconf.xml actually exists on disk
     * and that there are no files on disk that aren't included. 
     */
@Test
public void testIncludedEventFilesExistAndNoExtras() throws Exception {
    File eventConfFile = ConfigurationTestUtils.getFileForConfigFile("eventconf.xml");
    File eventsDirFile = new File(eventConfFile.getParentFile(), "events");
    assertTrue("events directory exists at " + eventsDirFile.getAbsolutePath(), eventsDirFile.exists());
    assertTrue("events directory is a directory at " + eventsDirFile.getAbsolutePath(), eventsDirFile.isDirectory());
    File[] eventFilesOnDiskArray = eventsDirFile.listFiles(new FilenameFilter() {

        @Override
        public boolean accept(File file, String name) {
            return name.endsWith(".xml");
        }
    });
    Set<File> eventFilesOnDisk = new HashSet<File>(Arrays.asList(eventFilesOnDiskArray));
    Reader r = new FileReader(eventConfFile);
    Events events = JaxbUtils.unmarshal(Events.class, r);
    r.close();
    Set<File> eventFilesIncluded = new HashSet<File>(events.getEventFiles().size());
    for (String eventFile : events.getEventFiles()) {
        eventFilesIncluded.add(new File(eventConfFile.getParentFile(), eventFile));
    }
    Set<File> includedNotOnDisk = new HashSet<File>(eventFilesIncluded);
    includedNotOnDisk.removeAll(eventFilesOnDisk);
    if (!includedNotOnDisk.isEmpty()) {
        fail("Event configuration file " + eventConfFile.getAbsolutePath() + " references included files that could not be found:\n\t" + StringUtils.collectionToDelimitedString(includedNotOnDisk, "\n\t"));
    }
    Set<File> onDiskNotIncluded = new HashSet<File>(eventFilesOnDisk);
    onDiskNotIncluded.removeAll(eventFilesIncluded);
    if (!onDiskNotIncluded.isEmpty()) {
        fail("Events directory " + eventsDirFile.getAbsolutePath() + " contains event files that are not referenced in event configuration file " + eventConfFile.getAbsolutePath() + ":\n\t" + StringUtils.collectionToDelimitedString(onDiskNotIncluded, "\n\t"));
    }
}
Also used : FilenameFilter(java.io.FilenameFilter) Events(org.opennms.netmgt.xml.eventconf.Events) Reader(java.io.Reader) FileReader(java.io.FileReader) FileReader(java.io.FileReader) File(java.io.File) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

Events (org.opennms.netmgt.xml.eventconf.Events)16 File (java.io.File)8 Test (org.junit.Test)5 IOException (java.io.IOException)4 Event (org.opennms.netmgt.xml.eventconf.Event)4 EventOrdering (org.opennms.netmgt.xml.eventconf.EventOrdering)4 StringWriter (java.io.StringWriter)3 Maskelement (org.opennms.netmgt.xml.eventconf.Maskelement)3 HashSet (java.util.HashSet)2 EventBuilder (org.opennms.netmgt.model.events.EventBuilder)2 Varbindsdecode (org.opennms.netmgt.xml.eventconf.Varbindsdecode)2 DataAccessException (org.springframework.dao.DataAccessException)2 DataRetrievalFailureException (org.springframework.dao.DataRetrievalFailureException)2 ValueChangeEvent (com.vaadin.data.Property.ValueChangeEvent)1 CommitException (com.vaadin.data.fieldgroup.FieldGroup.CommitException)1 Button (com.vaadin.ui.Button)1 ClickEvent (com.vaadin.ui.Button.ClickEvent)1 ComboBox (com.vaadin.ui.ComboBox)1 HorizontalLayout (com.vaadin.ui.HorizontalLayout)1 Label (com.vaadin.ui.Label)1