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);
}
}
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);
}
}
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();
}
}
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;
}
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);
}
}
Aggregations