Search in sources :

Example 21 with OnmsAcknowledgment

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

the class AlarmRepositoryHibernate method acknowledgeMatchingAlarms.

/**
     * {@inheritDoc}
     */
@Transactional
@Override
public void acknowledgeMatchingAlarms(String user, Date timestamp, OnmsCriteria criteria) {
    List<OnmsAlarm> alarms = m_alarmDao.findMatching(criteria);
    Iterator<OnmsAlarm> alarmsIt = alarms.iterator();
    while (alarmsIt.hasNext()) {
        OnmsAlarm alarm = alarmsIt.next();
        OnmsAcknowledgment ack = new OnmsAcknowledgment(alarm, user);
        ack.setAckTime(timestamp);
        ack.setAckAction(AckAction.ACKNOWLEDGE);
        m_ackDao.processAck(ack);
    }
}
Also used : OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Transactional(org.springframework.transaction.annotation.Transactional)

Example 22 with OnmsAcknowledgment

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

the class AlarmRepositoryHibernate method clearAlarms.

/**
     * {@inheritDoc}
     */
@Transactional
@Override
public void clearAlarms(int[] alarmIds, String user, Date timestamp) {
    OnmsCriteria criteria = new OnmsCriteria(OnmsAlarm.class);
    criteria.add(Restrictions.in("id", Arrays.asList(ArrayUtils.toObject(alarmIds))));
    List<OnmsAlarm> alarms = m_alarmDao.findMatching(criteria);
    Iterator<OnmsAlarm> alarmsIt = alarms.iterator();
    while (alarmsIt.hasNext()) {
        OnmsAlarm alarm = alarmsIt.next();
        OnmsAcknowledgment ack = new OnmsAcknowledgment(alarm, user);
        ack.setAckTime(timestamp);
        ack.setAckAction(AckAction.CLEAR);
        m_ackDao.processAck(ack);
    }
}
Also used : OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria) Transactional(org.springframework.transaction.annotation.Transactional)

Example 23 with OnmsAcknowledgment

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

the class AlarmRestService method updateAlarm.

/**
     * <p>
     * updateAlarm
     * </p>
     * 
     * @param alarmId
     *            a {@link java.lang.String} object.
     * @param ack
     *            a {@link java.lang.Boolean} object.
     */
@PUT
@Path("{alarmId}")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Transactional
public Response updateAlarm(@Context final SecurityContext securityContext, @PathParam("alarmId") final Integer alarmId, final MultivaluedMapImpl formProperties) {
    writeLock();
    try {
        boolean isProcessAck = true;
        if (alarmId == null) {
            return getBadRequestResponse("Unable to determine alarm ID to update based on query path.");
        }
        final String ackValue = formProperties.getFirst("ack");
        formProperties.remove("ack");
        final String escalateValue = formProperties.getFirst("escalate");
        formProperties.remove("escalate");
        final String clearValue = formProperties.getFirst("clear");
        formProperties.remove("clear");
        final String ackUserValue = formProperties.getFirst("ackUser");
        formProperties.remove("ackUser");
        final String ticketIdValue = formProperties.getFirst("ticketId");
        formProperties.remove("ticketId");
        final String ticketStateValue = formProperties.getFirst("ticketState");
        formProperties.remove("ticketState");
        final OnmsAlarm alarm = m_alarmDao.get(alarmId);
        if (alarm == null) {
            return getBadRequestResponse("Unable to locate alarm with ID '" + alarmId + "'");
        }
        final String ackUser = ackUserValue == null ? securityContext.getUserPrincipal().getName() : ackUserValue;
        assertUserEditCredentials(securityContext, ackUser);
        final OnmsAcknowledgment acknowledgement = new OnmsAcknowledgment(alarm, ackUser);
        acknowledgement.setAckAction(AckAction.UNSPECIFIED);
        if (ackValue != null) {
            if (Boolean.parseBoolean(ackValue)) {
                acknowledgement.setAckAction(AckAction.ACKNOWLEDGE);
            } else {
                acknowledgement.setAckAction(AckAction.UNACKNOWLEDGE);
            }
        } else if (escalateValue != null) {
            if (Boolean.parseBoolean(escalateValue)) {
                acknowledgement.setAckAction(AckAction.ESCALATE);
            }
        } else if (clearValue != null) {
            if (Boolean.parseBoolean(clearValue)) {
                acknowledgement.setAckAction(AckAction.CLEAR);
            }
        } else if (StringUtils.isNotBlank(ticketIdValue)) {
            isProcessAck = false;
            alarm.setTTicketId(ticketIdValue);
        } else if (EnumUtils.isValidEnum(TroubleTicketState.class, ticketStateValue)) {
            isProcessAck = false;
            alarm.setTTicketState(TroubleTicketState.valueOf(ticketStateValue));
        } else {
            return getBadRequestResponse("Must supply one of the 'ack', 'escalate', or 'clear' parameters, set to either 'true' or 'false'.");
        }
        if (isProcessAck) {
            m_ackDao.processAck(acknowledgement);
        } else {
            m_alarmDao.saveOrUpdate(alarm);
        }
        return Response.noContent().build();
    } finally {
        writeUnlock();
    }
}
Also used : OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT) Transactional(org.springframework.transaction.annotation.Transactional)

Example 24 with OnmsAcknowledgment

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

the class AlarmDetailController method detail.

/**
     * {@inheritDoc}
     *
     * Display alarm detail page
     */
public ModelAndView detail(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
    OnmsAlarm m_alarm = null;
    XssRequestWrapper safeRequest = new XssRequestWrapper(httpServletRequest);
    String alarmIdString = "";
    List<OnmsAcknowledgment> acknowledgments = Collections.emptyList();
    // Try to parse alarm ID as string to integer
    try {
        alarmIdString = safeRequest.getParameter("id");
        int alarmId = Integer.parseInt(alarmIdString);
        acknowledgments = m_webAlarmRepository.getAcknowledgments(alarmId);
        // Get alarm by ID
        m_alarm = m_webAlarmRepository.getAlarm(alarmId);
        logger.debug("Alarm retrieved: '{}'", m_alarm.toString());
    } catch (NumberFormatException e) {
        logger.error("Could not parse alarm ID '{}' to integer.", safeRequest.getParameter("id"));
    } catch (Throwable e) {
        logger.error("Could not retrieve alarm from webAlarmRepository for ID='{}'", alarmIdString);
    }
    if (m_alarm == null) {
        throw new AlarmIdNotFoundException("Could not find alarm with ID: " + alarmIdString, alarmIdString);
    }
    // return to view WEB-INF/jsp/alarm/detail.jsp
    ModelAndView mv = new ModelAndView("alarm/detail");
    mv.addObject("alarm", m_alarm);
    mv.addObject("alarmId", alarmIdString);
    mv.addObject("acknowledgments", acknowledgments);
    return mv;
}
Also used : OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) XssRequestWrapper(org.opennms.web.servlet.XssRequestWrapper) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) ModelAndView(org.springframework.web.servlet.ModelAndView) AlarmIdNotFoundException(org.opennms.web.alarm.AlarmIdNotFoundException)

Example 25 with OnmsAcknowledgment

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

the class DaoWebNotificationRepository method acknowledgeMatchingNotification.

/** {@inheritDoc} */
@Transactional
@Override
public void acknowledgeMatchingNotification(String user, Date timestamp, NotificationCriteria criteria) {
    List<OnmsNotification> notifs = m_notificationDao.findMatching(getOnmsCriteria(criteria));
    for (OnmsNotification notif : notifs) {
        OnmsAcknowledgment ack = new OnmsAcknowledgment(notif, user);
        ack.setAckAction(AckAction.ACKNOWLEDGE);
        ack.setAckTime(timestamp);
        m_ackDao.processAck(ack);
    }
}
Also used : OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) OnmsNotification(org.opennms.netmgt.model.OnmsNotification) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

OnmsAcknowledgment (org.opennms.netmgt.model.OnmsAcknowledgment)25 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)14 Test (org.junit.Test)11 Transactional (org.springframework.transaction.annotation.Transactional)10 Date (java.util.Date)6 OnmsNotification (org.opennms.netmgt.model.OnmsNotification)6 Message (javax.mail.Message)4 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)4 OnmsNode (org.opennms.netmgt.model.OnmsNode)4 ArrayList (java.util.ArrayList)3 InternetAddress (javax.mail.internet.InternetAddress)3 MimeMessage (javax.mail.internet.MimeMessage)3 Consumes (javax.ws.rs.Consumes)3 SendmailMessage (org.opennms.netmgt.config.javamail.SendmailMessage)3 Properties (java.util.Properties)2 Address (javax.mail.Address)2 MessagingException (javax.mail.MessagingException)2 PUT (javax.ws.rs.PUT)2 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)2 OnmsCriteria (org.opennms.netmgt.model.OnmsCriteria)2