Search in sources :

Example 1 with OnmsNotification

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

the class AcknowledgmentRestService method acknowledge.

/**
     * <p>acknowledgeAlarm</p>
     *
     * @param alarmId a {@link java.lang.String} object.
     * @param action a {@link java.lang.String} object.
     * @return a {@link javax.ws.rs.core.Response} object.
     */
@POST
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Transactional
public Response acknowledge(@Context final SecurityContext securityContext, MultivaluedMap<String, String> formParams) {
    String alarmId = formParams.getFirst("alarmId");
    String notifId = formParams.getFirst("notifId");
    String action = formParams.getFirst("action");
    String ackUser = formParams.getFirst("ackUser");
    if (action == null) {
        action = "ack";
    }
    if (ackUser == null) {
        ackUser = securityContext.getUserPrincipal().getName();
    }
    AlarmRestService.assertUserEditCredentials(securityContext, ackUser);
    OnmsAcknowledgment ack = null;
    if (alarmId == null && notifId == null) {
        return getBadRequestResponse("You must supply either an alarmId or notifId");
    } else if (alarmId != null && notifId != null) {
        return getBadRequestResponse("You cannot supply both an alarmId and a notifId");
    } else if (alarmId != null) {
        final Integer numericAlarmId = getNumericValue(alarmId);
        if (numericAlarmId == null) {
            return getBadRequestResponse("The alarmId has to be an integer value");
        }
        final OnmsAlarm alarm = m_alarmDao.get(numericAlarmId);
        if (alarm == null) {
            return Response.notModified().build();
        }
        ack = new OnmsAcknowledgment(alarm, ackUser);
    } else if (notifId != null) {
        final Integer numericNotifId = getNumericValue(notifId);
        if (numericNotifId == null) {
            return getBadRequestResponse("The notifId has to be an integer value");
        }
        final OnmsNotification notification = m_notificationDao.get(numericNotifId);
        if (notification == null) {
            return Response.notModified().build();
        }
        ack = new OnmsAcknowledgment(notification, ackUser);
    }
    if ("ack".equals(action)) {
        ack.setAckAction(AckAction.ACKNOWLEDGE);
    } else if ("unack".equals(action)) {
        ack.setAckAction(AckAction.UNACKNOWLEDGE);
    } else if ("clear".equals(action)) {
        ack.setAckAction(AckAction.CLEAR);
    } else if ("esc".equals(action)) {
        ack.setAckAction(AckAction.ESCALATE);
    } else {
        return getBadRequestResponse("Must supply the action parameter, set to either 'ack, 'unack', 'clear', or 'esc'");
    }
    m_ackDao.processAck(ack);
    return Response.ok(ack).build();
}
Also used : OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsNotification(org.opennms.netmgt.model.OnmsNotification) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with OnmsNotification

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

the class SurveillanceViewNotificationTable method refreshDetails.

/**
     * {@inheritDoc}
     */
@Override
public void refreshDetails(final Set<OnmsCategory> rowCategories, final Set<OnmsCategory> colCategories) {
    if (m_future != null && !m_future.isDone()) {
        return;
    }
    m_future = getSurveillanceViewService().getExecutorService().submit(new Callable<List<Notification>>() {

        @Override
        public List<Notification> call() throws Exception {
            /**
                 * create the custom severity map
                 */
            Map<OnmsNotification, String> customSeverity = new HashMap<>();
            /**
                 * retrieve the matching notifications
                 */
            List<OnmsNotification> onmsNotifications = getSurveillanceViewService().getNotificationsForCategories(rowCategories, colCategories, customSeverity);
            /**
                 * create the notifications list
                 */
            List<Notification> notifications = new ArrayList<>();
            for (OnmsNotification onmsNotification : onmsNotifications) {
                notifications.add(new Notification(onmsNotification.getNotifyId(), onmsNotification.getNodeId(), onmsNotification.getNodeLabel(), onmsNotification.getPageTime(), onmsNotification.getRespondTime(), onmsNotification.getAnsweredBy(), onmsNotification.getTextMsg(), onmsNotification.getServiceType() != null ? onmsNotification.getServiceType().getName() : "", customSeverity.get(onmsNotification)));
            }
            return notifications;
        }
    });
    m_future.addListener(new Runnable() {

        @Override
        public void run() {
            try {
                final List<Notification> notifications = m_future.get();
                getUI().access(new Runnable() {

                    @Override
                    public void run() {
                        /**
                             * empty the bean container
                             */
                        m_beanItemContainer.removeAllItems();
                        /**
                             * add items to container
                             */
                        if (notifications != null && !notifications.isEmpty()) {
                            for (Notification notification : notifications) {
                                m_beanItemContainer.addItem(notification);
                            }
                        }
                        /**
                             * sort the items
                             */
                        sort(new Object[] { "pageTime" }, new boolean[] { false });
                        /**
                             * refresh the table
                             */
                        refreshRowCache();
                    }
                });
            } catch (InterruptedException e) {
                LOG.error("Interrupted", e);
            } catch (ExecutionException e) {
                LOG.error("Exception in task", e.getCause());
            }
        }
    }, MoreExecutors.sameThreadExecutor());
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) OnmsNotification(org.opennms.netmgt.model.OnmsNotification) Callable(java.util.concurrent.Callable) OnmsNotification(org.opennms.netmgt.model.OnmsNotification) ArrayList(java.util.ArrayList) List(java.util.List) ExecutionException(java.util.concurrent.ExecutionException)

Example 3 with OnmsNotification

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

the class NotificationDaoIT method testNotificationSave.

@Test
@Transactional
public void testNotificationSave() {
    OnmsEvent event = new OnmsEvent();
    event.setDistPoller(m_distPollerDao.whoami());
    event.setEventCreateTime(new Date());
    event.setEventDescr("event dao test");
    event.setEventHost("localhost");
    event.setEventLog("Y");
    event.setEventDisplay("Y");
    event.setEventLogGroup("event dao test log group");
    event.setEventLogMsg("event dao test log msg");
    event.setEventSeverity(7);
    event.setEventSource("EventDaoTest");
    event.setEventTime(new Date());
    event.setEventUei("uei://org/opennms/test/NotificationDaoTest");
    //        OnmsAlarm alarm = new OnmsAlarm();
    //        event.setAlarm(alarm);
    OnmsNode node = m_nodeDao.findAll().iterator().next();
    OnmsIpInterface iface = node.getIpInterfaces().iterator().next();
    OnmsMonitoredService service = iface.getMonitoredServices().iterator().next();
    event.setNode(node);
    event.setServiceType(service.getServiceType());
    event.setIpAddr(iface.getIpAddress());
    m_eventDao.save(event);
    OnmsEvent newEvent = m_eventDao.load(event.getId());
    assertEquals("uei://org/opennms/test/NotificationDaoTest", newEvent.getEventUei());
    OnmsNotification notification = new OnmsNotification();
    notification.setEvent(newEvent);
    notification.setTextMsg("Tests are fun!");
    m_notificationDao.save(notification);
    OnmsNotification newNotification = m_notificationDao.load(notification.getNotifyId());
    assertEquals("uei://org/opennms/test/NotificationDaoTest", newNotification.getEvent().getEventUei());
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsNotification(org.opennms.netmgt.model.OnmsNotification) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with OnmsNotification

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

the class DaoWebNotificationRepository method getMatchingNotifications.

/** {@inheritDoc} */
@Transactional
@Override
public Notification[] getMatchingNotifications(NotificationCriteria criteria) {
    List<Notification> notifications = new ArrayList<Notification>();
    List<OnmsNotification> onmsNotifs = m_notificationDao.findMatching(getOnmsCriteria(criteria));
    for (OnmsNotification notif : onmsNotifs) {
        notifications.add(mapOnmsNotificationToNotification(notif));
    }
    return notifications.toArray(new Notification[0]);
}
Also used : ArrayList(java.util.ArrayList) OnmsNotification(org.opennms.netmgt.model.OnmsNotification) OnmsUserNotification(org.opennms.netmgt.model.OnmsUserNotification) OnmsNotification(org.opennms.netmgt.model.OnmsNotification) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with OnmsNotification

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

the class NotificationRestService method updateNotifications.

/**
     * <p>updateNotifications</p>
     *
     * @param params a {@link org.opennms.web.rest.support.MultivaluedMapImpl} object.
     */
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Transactional
public Response updateNotifications(@Context final SecurityContext securityContext, final MultivaluedMapImpl params) {
    writeLock();
    try {
        Boolean ack = false;
        if (params.containsKey("ack")) {
            ack = "true".equals(params.getFirst("ack"));
            params.remove("ack");
        }
        final CriteriaBuilder builder = getCriteriaBuilder(params);
        for (final OnmsNotification notif : m_notifDao.findMatching(builder.toCriteria())) {
            processNotifAck(securityContext, notif, ack);
        }
        return Response.noContent().build();
    } finally {
        writeUnlock();
    }
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsNotification(org.opennms.netmgt.model.OnmsNotification) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

OnmsNotification (org.opennms.netmgt.model.OnmsNotification)20 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)9 Transactional (org.springframework.transaction.annotation.Transactional)7 Test (org.junit.Test)6 OnmsAcknowledgment (org.opennms.netmgt.model.OnmsAcknowledgment)6 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)6 OnmsNode (org.opennms.netmgt.model.OnmsNode)6 OnmsUserNotification (org.opennms.netmgt.model.OnmsUserNotification)6 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 Consumes (javax.ws.rs.Consumes)3 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)3 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)3 PUT (javax.ws.rs.PUT)2 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)2 Acknowledgeable (org.opennms.netmgt.model.Acknowledgeable)2 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)2 OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1