Search in sources :

Example 31 with EventBuilder

use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.

the class SecurityAuthenticationEventOnmsEventBuilder method createEvent.

private EventBuilder createEvent(String uei, AbstractAuthenticationEvent authEvent) {
    EventBuilder builder = new EventBuilder(uei, "OpenNMS.WebUI");
    builder.setTime(new Date(authEvent.getTimestamp()));
    org.springframework.security.core.Authentication auth = authEvent.getAuthentication();
    if (auth != null && auth.getName() != null) {
        builder.addParam("user", WebSecurityUtils.sanitizeString(auth.getName()));
    }
    if (auth != null && auth.getDetails() != null && auth.getDetails() instanceof WebAuthenticationDetails) {
        WebAuthenticationDetails webDetails = (WebAuthenticationDetails) auth.getDetails();
        if (webDetails.getRemoteAddress() != null) {
            builder.addParam("ip", webDetails.getRemoteAddress());
        }
    }
    return builder;
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) WebAuthenticationDetails(org.springframework.security.web.authentication.WebAuthenticationDetails) Date(java.util.Date)

Example 32 with EventBuilder

use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.

the class EventAdminApplication method init.

/* (non-Javadoc)
     * @see com.vaadin.Application#init()
     */
@Override
public void init(VaadinRequest request) {
    if (eventProxy == null)
        throw new RuntimeException("eventProxy cannot be null.");
    if (eventConfDao == null)
        throw new RuntimeException("eventConfDao cannot be null.");
    final VerticalLayout layout = new VerticalLayout();
    final HorizontalLayout toolbar = new HorizontalLayout();
    toolbar.setMargin(true);
    final Label comboLabel = new Label("Select Events Configuration File");
    toolbar.addComponent(comboLabel);
    toolbar.setComponentAlignment(comboLabel, Alignment.MIDDLE_LEFT);
    final File eventsDir = new File(ConfigFileConstants.getFilePathString(), "events");
    final XmlFileContainer container = new XmlFileContainer(eventsDir, true);
    // This is a protected file, should not be updated.
    container.addExcludeFile("default.events.xml");
    final ComboBox eventSource = new ComboBox();
    toolbar.addComponent(eventSource);
    eventSource.setImmediate(true);
    eventSource.setNullSelectionAllowed(false);
    eventSource.setContainerDataSource(container);
    eventSource.setItemCaptionPropertyId(FilesystemContainer.PROPERTY_NAME);
    eventSource.addValueChangeListener(new ComboBox.ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            final File file = (File) event.getProperty().getValue();
            if (file == null)
                return;
            try {
                LOG.info("Loading events from {}", file);
                final Events events = JaxbUtils.unmarshal(Events.class, file);
                addEventPanel(layout, file, events);
            } catch (Exception e) {
                LOG.error("an error ocurred while saving the event configuration {}: {}", file, e.getMessage(), e);
                Notification.show("Can't parse file " + file + " because " + e.getMessage());
            }
        }
    });
    final Button add = new Button("Add New Events File");
    toolbar.addComponent(add);
    add.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            PromptWindow w = new PromptWindow("New Events Configuration", "Events File Name") {

                @Override
                public void textFieldChanged(String fieldValue) {
                    final File file = new File(eventsDir, normalizeFilename(fieldValue));
                    LOG.info("Adding new events file {}", file);
                    final Events events = new Events();
                    addEventPanel(layout, file, events);
                }
            };
            addWindow(w);
        }
    });
    final Button remove = new Button("Remove Selected Events File");
    toolbar.addComponent(remove);
    remove.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(ClickEvent event) {
            if (eventSource.getValue() == null) {
                Notification.show("Please select an event configuration file.");
                return;
            }
            final File file = (File) eventSource.getValue();
            ConfirmDialog.show(getUI(), "Are you sure?", "Do you really want to remove the file " + file.getName() + "?\nThis cannot be undone and OpenNMS won't be able to handle the events configured on this file.", "Yes", "No", new ConfirmDialog.Listener() {

                public void onClose(ConfirmDialog dialog) {
                    if (dialog.isConfirmed()) {
                        LOG.info("deleting file {}", file);
                        if (file.delete()) {
                            try {
                                // Updating eventconf.xml
                                boolean modified = false;
                                File configFile = ConfigFileConstants.getFile(ConfigFileConstants.EVENT_CONF_FILE_NAME);
                                Events config = JaxbUtils.unmarshal(Events.class, configFile);
                                for (Iterator<String> it = config.getEventFiles().iterator(); it.hasNext(); ) {
                                    String fileName = it.next();
                                    if (file.getAbsolutePath().contains(fileName)) {
                                        it.remove();
                                        modified = true;
                                    }
                                }
                                if (modified) {
                                    JaxbUtils.marshal(config, new FileWriter(configFile));
                                    EventBuilder eb = new EventBuilder(EventConstants.EVENTSCONFIG_CHANGED_EVENT_UEI, "WebUI");
                                    eventProxy.send(eb.getEvent());
                                }
                                // Updating UI Components
                                eventSource.select(null);
                                if (layout.getComponentCount() > 1)
                                    layout.removeComponent(layout.getComponent(1));
                            } catch (Exception e) {
                                LOG.error("an error ocurred while saving the event configuration: {}", e.getMessage(), e);
                                Notification.show("Can't save event configuration. " + e.getMessage(), Notification.Type.ERROR_MESSAGE);
                            }
                        } else {
                            Notification.show("Cannot delete file " + file, Notification.Type.WARNING_MESSAGE);
                        }
                    }
                }
            });
        }
    });
    layout.addComponent(toolbar);
    layout.addComponent(new Label(""));
    layout.setComponentAlignment(toolbar, Alignment.MIDDLE_RIGHT);
    setContent(layout);
}
Also used : ComboBox(com.vaadin.ui.ComboBox) ClickEvent(com.vaadin.ui.Button.ClickEvent) FileWriter(java.io.FileWriter) Label(com.vaadin.ui.Label) HorizontalLayout(com.vaadin.ui.HorizontalLayout) ValueChangeEvent(com.vaadin.data.Property.ValueChangeEvent) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Events(org.opennms.netmgt.xml.eventconf.Events) Button(com.vaadin.ui.Button) VerticalLayout(com.vaadin.ui.VerticalLayout) File(java.io.File) ConfirmDialog(org.vaadin.dialogs.ConfirmDialog)

Example 33 with EventBuilder

use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.

the class ProvisionerIT method testProvisionerAddNodeToSchedule.

@Test(timeout = 300000)
public void testProvisionerAddNodeToSchedule() throws Exception {
    final int nextNodeId = m_nodeDao.getNextNodeId();
    m_provisioner.scheduleRescanForExistingNodes();
    assertEquals(0, m_provisioner.getScheduleLength());
    final OnmsNode node = createNode("empty");
    assertEquals(nextNodeId, node.getId().intValue());
    assertNotNull(m_nodeDao.get(nextNodeId));
    final EventBuilder bldr = new EventBuilder(EventConstants.NODE_ADDED_EVENT_UEI, "Tests");
    bldr.setNodeid(nextNodeId);
    m_mockEventIpcManager.broadcastNow(bldr.getEvent());
    assertEquals(1, m_provisioner.getScheduleLength());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Test(org.junit.Test)

Example 34 with EventBuilder

use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.

the class ProvisionerIT method nodeScanAborted.

private Event nodeScanAborted(final int nodeId) {
    final EventBuilder eb = new EventBuilder(EventConstants.PROVISION_SCAN_ABORTED_UEI, "Test");
    eb.setNodeid(nodeId);
    final Event event = eb.getEvent();
    return event;
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Event(org.opennms.netmgt.xml.event.Event)

Example 35 with EventBuilder

use of org.opennms.netmgt.model.events.EventBuilder in project opennms by OpenNMS.

the class ProvisionerIT method nodeScanCompleted.

private Event nodeScanCompleted(final int nodeId) {
    final EventBuilder eb = new EventBuilder(EventConstants.PROVISION_SCAN_COMPLETE_UEI, "Test");
    eb.setNodeid(nodeId);
    final Event event = eb.getEvent();
    return event;
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) Event(org.opennms.netmgt.xml.event.Event)

Aggregations

EventBuilder (org.opennms.netmgt.model.events.EventBuilder)305 Test (org.junit.Test)88 Event (org.opennms.netmgt.xml.event.Event)84 Date (java.util.Date)22 OnmsNode (org.opennms.netmgt.model.OnmsNode)17 InetAddress (java.net.InetAddress)16 EventProxyException (org.opennms.netmgt.events.api.EventProxyException)15 AlarmData (org.opennms.netmgt.xml.event.AlarmData)14 EventAnticipator (org.opennms.netmgt.dao.mock.EventAnticipator)12 ServletException (javax.servlet.ServletException)9 EventHandler (org.opennms.netmgt.events.api.annotations.EventHandler)9 Parm (org.opennms.netmgt.xml.event.Parm)9 Event (org.opennms.netmgt.xml.eventconf.Event)9 File (java.io.File)8 ArrayList (java.util.ArrayList)8 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)7 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)7 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)7 SyntaxToEvent (org.opennms.netmgt.model.events.snmp.SyntaxToEvent)7 Transactional (org.springframework.transaction.annotation.Transactional)6