Search in sources :

Example 6 with OnmsAlarm

use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.

the class AlarmIdColumnLinkGenerator method generateCell.

@Override
public Object generateCell(final Table source, Object itemId, Object columnId) {
    // no source
    if (source == null)
        return null;
    Property<Integer> alarmIdProperty = source.getContainerProperty(itemId, alarmIdPropertyName);
    final Integer alarmId = alarmIdProperty.getValue();
    // no value
    if (alarmId == null)
        return null;
    // create Link
    Button button = new Button("" + alarmId);
    button.setStyleName(BaseTheme.BUTTON_LINK);
    button.addClickListener(new ClickListener() {

        private static final long serialVersionUID = 3698209256202413810L;

        @Override
        public void buttonClick(ClickEvent event) {
            // try if alarm is there, otherwise show information dialog
            OnmsAlarm alarm = alarmDao.get(alarmId);
            if (alarm == null) {
                new DialogWindow(source.getUI(), "Alarm does not exist!", "The alarm information cannot be shown. \nThe alarm does not exist anymore. \n\nPlease refresh the Alarm Table.");
                return;
            }
            // alarm still exists, show alarm details
            final URI currentLocation = Page.getCurrent().getLocation();
            final String contextRoot = VaadinServlet.getCurrent().getServletContext().getContextPath();
            final String redirectFragment = contextRoot + "/alarm/detail.htm?quiet=true&id=" + alarmId;
            LOG.debug("alarm {} clicked, current location = {}, uri = {}", alarmId, currentLocation, redirectFragment);
            try {
                source.getUI().addWindow(new InfoWindow(new URL(currentLocation.toURL(), redirectFragment), new LabelCreator() {

                    @Override
                    public String getLabel() {
                        return "Alarm Info " + alarmId;
                    }
                }));
            } catch (MalformedURLException e) {
                LOG.error(e.getMessage(), e);
            }
        }
    });
    return button;
}
Also used : MalformedURLException(java.net.MalformedURLException) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) ClickEvent(com.vaadin.ui.Button.ClickEvent) InfoWindow(org.opennms.features.topology.api.support.InfoWindow) URI(java.net.URI) URL(java.net.URL) Button(com.vaadin.ui.Button) DialogWindow(org.opennms.features.topology.api.support.DialogWindow) ClickListener(com.vaadin.ui.Button.ClickListener) LabelCreator(org.opennms.features.topology.api.support.InfoWindow.LabelCreator)

Example 7 with OnmsAlarm

use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.

the class AlarmLifecycleEventsIT method canGenerateAlarmDeletedLifecycleEvents.

@Test
public void canGenerateAlarmDeletedLifecycleEvents() {
    // Expect an alarmCreated event
    m_eventMgr.getEventAnticipator().resetAnticipated();
    m_eventMgr.getEventAnticipator().anticipateEvent(new EventBuilder(EventConstants.ALARM_CREATED_UEI, "alarmd").getEvent());
    m_eventMgr.getEventAnticipator().setDiscardUnanticipated(true);
    // Send a nodeDown
    sendNodeDownEvent(1);
    // Wait until we've received the alarmCreated event
    await().until(allAnticipatedEventsWereReceived());
    // Expect an alarmCreated and a alarmCleared event
    m_eventMgr.getEventAnticipator().resetAnticipated();
    m_eventMgr.getEventAnticipator().anticipateEvent(new EventBuilder(EventConstants.ALARM_CREATED_UEI, "alarmd").getEvent());
    m_eventMgr.getEventAnticipator().anticipateEvent(new EventBuilder(EventConstants.ALARM_CLEARED_UEI, "alarmd").getEvent());
    m_eventMgr.getEventAnticipator().setDiscardUnanticipated(true);
    // Send a nodeUp
    sendNodeUpEvent(1);
    // Wait until we've received the alarmCreated and alarmCleared events
    // We need to wait for the cosmicClear automation, which currently runs every 30 seconds
    await().atMost(1, MINUTES).until(allAnticipatedEventsWereReceived());
    // Expect an alarmDeleted event
    m_eventMgr.getEventAnticipator().anticipateEvent(new EventBuilder(EventConstants.ALARM_DELETED_EVENT_UEI, "alarmd").getEvent());
    m_eventMgr.getEventAnticipator().setDiscardUnanticipated(true);
    // We need to wait for the cleanUp automation, which currently runs every 60 seconds
    // but it will only trigger then 'lastautomationtime' and 'lasteventtime' < "5 minutes ago"
    // so we cheat a little and update the timestamps ourselves instead of waiting
    transactionTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        protected void doInTransactionWithoutResult(TransactionStatus status) {
            Criteria criteria = new Criteria(OnmsAlarm.class);
            criteria.addRestriction(new EqRestriction("node.id", 1));
            criteria.addRestriction(new EqRestriction("uei", EventConstants.NODE_DOWN_EVENT_UEI));
            for (OnmsAlarm alarm : m_alarmDao.findMatching(criteria)) {
                LocalDateTime tenMinutesAgo = LocalDateTime.now().minusMinutes(10);
                Date then = Date.from(tenMinutesAgo.toInstant(ZoneOffset.UTC));
                alarm.setLastAutomationTime(then);
                alarm.setLastEventTime(then);
                m_alarmDao.save(alarm);
            }
            m_alarmDao.flush();
        }
    });
    // Wait until we've received the alarmDeleted event
    await().atMost(2, MINUTES).until(allAnticipatedEventsWereReceived());
}
Also used : LocalDateTime(java.time.LocalDateTime) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) EqRestriction(org.opennms.core.criteria.restrictions.EqRestriction) TransactionStatus(org.springframework.transaction.TransactionStatus) Criteria(org.opennms.core.criteria.Criteria) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) Date(java.util.Date) Test(org.junit.Test)

Example 8 with OnmsAlarm

use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.

the class AlarmPersisterImpl method addOrReduceEventAsAlarm.

private OnmsAlarmAndLifecycleEvent addOrReduceEventAsAlarm(Event event) {
    // 2012-03-11 pbrane: for some reason when we get here the event from the DB doesn't have the LogMsg (in my tests anyway)
    OnmsEvent e = m_eventDao.get(event.getDbid());
    Assert.notNull(e, "Event was deleted before we could retrieve it and create an alarm.");
    String reductionKey = event.getAlarmData().getReductionKey();
    LOG.debug("addOrReduceEventAsAlarm: looking for existing reduction key: {}", reductionKey);
    OnmsAlarm alarm = m_alarmDao.findByReductionKey(reductionKey);
    EventBuilder ebldr = null;
    if (alarm == null) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("addOrReduceEventAsAlarm: reductionKey:{} not found, instantiating new alarm", reductionKey);
        }
        alarm = createNewAlarm(e, event);
        //FIXME: this should be a cascaded save
        m_alarmDao.save(alarm);
        m_eventDao.saveOrUpdate(e);
        ebldr = new EventBuilder(EventConstants.ALARM_CREATED_UEI, Alarmd.NAME);
    } else {
        if (LOG.isDebugEnabled()) {
            LOG.debug("addOrReduceEventAsAlarm: reductionKey:{} found, reducing event to existing alarm: {}", reductionKey, alarm.getIpAddr());
        }
        reduceEvent(e, alarm, event);
        m_alarmDao.update(alarm);
        m_eventDao.update(e);
        if (event.getAlarmData().isAutoClean()) {
            m_eventDao.deletePreviousEventsForAlarm(alarm.getId(), e);
        }
        ebldr = new EventBuilder(EventConstants.ALARM_UPDATED_WITH_REDUCED_EVENT_UEI, Alarmd.NAME);
    }
    if (alarm.getNodeId() != null) {
        // This should trigger the lazy loading of the node object, to properly populate the NorthboundAlarm class.
        alarm.getNode().getForeignSource();
    }
    ebldr.addParam(EventConstants.PARM_ALARM_UEI, alarm.getUei());
    ebldr.addParam(EventConstants.PARM_ALARM_ID, alarm.getId());
    return new OnmsAlarmAndLifecycleEvent(alarm, ebldr.getEvent());
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) EventBuilder(org.opennms.netmgt.model.events.EventBuilder) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm)

Example 9 with OnmsAlarm

use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.

the class DatabasePopulator method doResetDatabase.

private void doResetDatabase() {
    LOG.debug("==== DatabasePopulator Reset ====");
    for (final OnmsOutage outage : m_outageDao.findAll()) {
        m_outageDao.delete(outage);
    }
    for (final OnmsUserNotification not : m_userNotificationDao.findAll()) {
        m_userNotificationDao.delete(not);
    }
    for (final OnmsNotification not : m_notificationDao.findAll()) {
        m_notificationDao.delete(not);
    }
    for (final OnmsAlarm alarm : m_alarmDao.findAll()) {
        m_alarmDao.delete(alarm);
    }
    for (final OnmsEvent event : m_eventDao.findAll()) {
        m_eventDao.delete(event);
    }
    for (final OnmsSnmpInterface snmpIface : m_snmpInterfaceDao.findAll()) {
        for (OnmsIpInterface eachIf : snmpIface.getIpInterfaces()) {
            eachIf.setSnmpInterface(null);
            snmpIface.getNode().getIpInterfaces().remove(eachIf);
        }
        snmpIface.getNode().getSnmpInterfaces().remove(snmpIface);
        m_snmpInterfaceDao.delete(snmpIface);
    }
    for (final OnmsIpInterface iface : m_ipInterfaceDao.findAll()) {
        iface.setSnmpInterface(null);
        iface.getNode().getIpInterfaces().remove(iface);
        m_ipInterfaceDao.delete(iface);
    }
    for (final OnmsNode node : m_nodeDao.findAll()) {
        m_nodeDao.delete(node);
    }
    for (final OnmsServiceType service : m_serviceTypeDao.findAll()) {
        m_serviceTypeDao.delete(service);
    }
    for (final OnmsMonitoringLocation location : m_monitoringLocationDao.findAll()) {
        // Don't delete the default localhost monitoring location
        if (!MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID.equals(location.getLocationName())) {
            m_monitoringLocationDao.delete(location);
        }
    }
    for (final OnmsCategory category : m_categoryDao.findAll()) {
        m_categoryDao.delete(category);
    }
    LOG.debug("= DatabasePopulatorExtension Reset Starting =");
    for (Extension eachExtension : extensions) {
        DaoSupport daoSupport = eachExtension.getDaoSupport();
        OnmsDao<?, ?> dao = daoSupport != null && daoSupport.getDaoClass() != null ? lookupDao(daoSupport.getDaoClass()) : null;
        eachExtension.onShutdown(this, dao);
        if (dao != null) {
            dao.flush();
        }
    }
    LOG.debug("= DatabasePopulatorExtension Reset Finished =");
    m_outageDao.flush();
    m_userNotificationDao.flush();
    m_notificationDao.flush();
    m_alarmDao.flush();
    m_eventDao.flush();
    m_snmpInterfaceDao.flush();
    m_ipInterfaceDao.flush();
    m_nodeDao.flush();
    m_serviceTypeDao.flush();
    LOG.debug("==== DatabasePopulator Reset Finished ====");
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) OnmsUserNotification(org.opennms.netmgt.model.OnmsUserNotification) OnmsNotification(org.opennms.netmgt.model.OnmsNotification) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)

Example 10 with OnmsAlarm

use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.

the class DatabasePopulator method doPopulateDatabase.

private void doPopulateDatabase() {
    LOG.debug("==== DatabasePopulator Starting ====");
    final NetworkBuilder builder = new NetworkBuilder();
    final OnmsNode node1 = buildNode1(builder);
    getNodeDao().save(node1);
    getNodeDao().flush();
    OnmsNode node2 = buildNode2(builder);
    getNodeDao().save(node2);
    getNodeDao().flush();
    setNode2(node2);
    OnmsNode node3 = buildNode3(builder);
    getNodeDao().save(node3);
    getNodeDao().flush();
    setNode3(node3);
    OnmsNode node4 = buildNode4(builder);
    getNodeDao().save(node4);
    getNodeDao().flush();
    setNode4(node4);
    OnmsNode node5 = buildNode5(builder);
    getNodeDao().save(node5);
    getNodeDao().flush();
    setNode5(node5);
    OnmsNode node6 = buildNode6(builder);
    getNodeDao().save(node6);
    getNodeDao().flush();
    setNode6(node6);
    final OnmsEvent event = buildEvent(builder.getDistPoller());
    event.setEventCreateTime(new Date(1436881548292L));
    event.setEventTime(new Date(1436881548292L));
    getEventDao().save(event);
    getEventDao().flush();
    final OnmsNotification notif = buildTestNotification(builder, event);
    getNotificationDao().save(notif);
    getNotificationDao().flush();
    final OnmsUserNotification userNotif = buildTestUserNotification(notif);
    getUserNotificationDao().save(userNotif);
    getUserNotificationDao().flush();
    final OnmsUserNotification userNotif2 = buildTestUser2Notification(notif);
    getUserNotificationDao().save(userNotif2);
    getUserNotificationDao().flush();
    final OnmsMonitoredService svc = getMonitoredServiceDao().get(node1.getId(), InetAddressUtils.addr("192.168.1.1"), "SNMP");
    final OnmsOutage resolved = new OnmsOutage(new Date(1436881548292L), new Date(1436881548292L), event, event, svc, null, null);
    getOutageDao().save(resolved);
    getOutageDao().flush();
    final OnmsOutage unresolved = new OnmsOutage(new Date(1436881548292L), event, svc);
    getOutageDao().save(unresolved);
    getOutageDao().flush();
    final OnmsAlarm alarm = buildAlarm(event);
    getAlarmDao().save(alarm);
    getAlarmDao().flush();
    final OnmsAcknowledgment ack = new OnmsAcknowledgment();
    ack.setAckTime(new Date(1437073152156L));
    ack.setAckType(AckType.UNSPECIFIED);
    ack.setAckAction(AckAction.UNSPECIFIED);
    ack.setAckUser("admin");
    getAcknowledgmentDao().save(ack);
    getAcknowledgmentDao().flush();
    final OnmsMonitoringLocation def = new OnmsMonitoringLocation();
    def.setLocationName("RDU");
    def.setMonitoringArea("East Coast");
    def.setPollingPackageNames(Collections.singletonList("example1"));
    def.setCollectionPackageNames(Collections.singletonList("example1"));
    def.setGeolocation("Research Triangle Park, NC");
    def.setLatitude(35.715751f);
    def.setLongitude(-79.16262f);
    def.setPriority(1L);
    def.setTags(Collections.singletonList("blah"));
    m_monitoringLocationDao.save(def);
    LOG.debug("= DatabasePopulatorExtension Populate Starting =");
    for (Extension eachExtension : extensions) {
        DaoSupport daoSupport = eachExtension.getDaoSupport();
        OnmsDao<?, ?> dao = daoSupport != null ? daoSupport.getDao() : null;
        Class<? super OnmsDao<?, ?>> daoClass = daoSupport != null ? daoSupport.getDaoClass() : null;
        registerDao(daoClass, dao);
        dao = lookupDao(daoClass);
        eachExtension.onPopulate(this, dao);
        if (dao != null) {
            dao.flush();
        }
    }
    LOG.debug("= DatabasePopulatorExtension Populate Finished =");
    LOG.debug("==== DatabasePopulator Finished ====");
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsUserNotification(org.opennms.netmgt.model.OnmsUserNotification) OnmsNotification(org.opennms.netmgt.model.OnmsNotification) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)

Aggregations

OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)143 Test (org.junit.Test)58 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)41 Date (java.util.Date)36 OnmsNode (org.opennms.netmgt.model.OnmsNode)36 Transactional (org.springframework.transaction.annotation.Transactional)35 OnmsEventParameter (org.opennms.netmgt.model.OnmsEventParameter)19 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)18 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)18 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)17 ArrayList (java.util.ArrayList)14 OnmsAcknowledgment (org.opennms.netmgt.model.OnmsAcknowledgment)14 InetAddress (java.net.InetAddress)13 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)11 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)10 OnmsNotification (org.opennms.netmgt.model.OnmsNotification)9 OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)9 AlarmDao (org.opennms.netmgt.dao.api.AlarmDao)8 AlarmCriteria (org.opennms.web.alarm.filter.AlarmCriteria)8 LinkedList (java.util.LinkedList)7