use of org.opennms.netmgt.model.OnmsAcknowledgment in project opennms by OpenNMS.
the class AckdIT method testAcknowledgeAlarm.
/**
* This tests the acknowledgment of an alarm and any related notifications.
*/
@Test
public void testAcknowledgeAlarm() {
VerificationObject vo = createAckStructure();
Assert.assertTrue(vo.m_nodeId > 0);
Assert.assertTrue(vo.m_alarmId > 0);
Assert.assertTrue(vo.m_eventID > 0);
Assert.assertTrue(vo.m_userNotifId > 0);
OnmsAlarm alarm = m_alarmDao.get(vo.m_alarmId);
OnmsAcknowledgment ack = new OnmsAcknowledgment(m_alarmDao.get(vo.m_alarmId));
m_ackDao.save(ack);
m_ackDao.flush();
m_ackDao.processAck(ack);
alarm = m_alarmDao.get(ack.getRefId());
Assert.assertNotNull(alarm.getAlarmAckUser());
Assert.assertEquals("admin", alarm.getAlarmAckUser());
OnmsNotification notif = m_notificationDao.get(vo.m_notifId);
Assert.assertNotNull(notif);
Assert.assertEquals("admin", notif.getAnsweredBy());
Assert.assertTrue(alarm.getAlarmAckTime().before(notif.getRespondTime()));
}
use of org.opennms.netmgt.model.OnmsAcknowledgment in project opennms by OpenNMS.
the class JavaMailAckReaderIT method workingWithSimpleTextMessages.
/**
* tests the ability to create acknowledgments from an email for plain text. This test
* creates a message from scratch rather than reading from an inbox.
*/
@Test
public void workingWithSimpleTextMessages() {
Properties props = new Properties();
Message msg = new MimeMessage(Session.getDefaultInstance(props));
try {
Address[] addrs = new Address[1];
addrs[0] = new InternetAddress("david@opennms.org");
msg.addFrom(addrs);
msg.addRecipient(javax.mail.internet.MimeMessage.RecipientType.TO, addrs[0]);
msg.setSubject("Re: Notice #1234 JavaMailReaderImplTest Test Message");
msg.setText("ACK");
} catch (AddressException e) {
e.printStackTrace();
} catch (MessagingException e) {
e.printStackTrace();
}
List<Message> msgs = new ArrayList<Message>(1);
msgs.add(msg);
List<OnmsAcknowledgment> acks = m_processor.createAcks(msgs);
Assert.assertEquals(1, acks.size());
Assert.assertEquals(AckType.NOTIFICATION, acks.get(0).getAckType());
Assert.assertEquals("david@opennms.org", acks.get(0).getAckUser());
Assert.assertEquals(AckAction.ACKNOWLEDGE, acks.get(0).getAckAction());
Assert.assertEquals(new Integer(1234), acks.get(0).getRefId());
}
use of org.opennms.netmgt.model.OnmsAcknowledgment in project opennms by OpenNMS.
the class JavaMailAckReaderIT method workingWithMultiPartMessages.
/**
* tests the ability to create acknowledgments from an email for a multi-part text. This test
* creates a message from scratch rather than reading from an inbox. This message creation
* may not actually represent what comes from a mail server.
*/
@Test
public void workingWithMultiPartMessages() throws JavaMailerException, MessagingException {
List<Message> msgs = new ArrayList<>();
Properties props = new Properties();
Message msg = new MimeMessage(Session.getDefaultInstance(props));
Address[] addrs = new Address[1];
addrs[0] = new InternetAddress("david@opennms.org");
msg.addFrom(addrs);
msg.addRecipient(RecipientType.TO, new InternetAddress("david@opennms.org"));
msg.setSubject("Re: Notice #1234 JavaMailReaderImplTest Test Message");
Multipart mpContent = new MimeMultipart();
BodyPart textBp = new MimeBodyPart();
BodyPart htmlBp = new MimeBodyPart();
textBp.setText("ack");
htmlBp.setContent("<html>\n" + " <head>\n" + " <title>\n" + " Acknowledge\n" + " </title>\n" + " </head>\n" + " <body>\n" + " <h1>\n" + " ack\n" + " </h1>\n" + " </body>\n" + "</html>", "text/html");
mpContent.addBodyPart(textBp);
mpContent.addBodyPart(htmlBp);
msg.setContent(mpContent);
msgs.add(msg);
List<OnmsAcknowledgment> acks = m_processor.createAcks(msgs);
Assert.assertEquals(1, acks.size());
Assert.assertEquals(AckType.NOTIFICATION, acks.get(0).getAckType());
Assert.assertEquals("david@opennms.org", acks.get(0).getAckUser());
Assert.assertEquals(AckAction.ACKNOWLEDGE, acks.get(0).getAckAction());
Assert.assertEquals(new Integer(1234), acks.get(0).getRefId());
}
use of org.opennms.netmgt.model.OnmsAcknowledgment in project opennms by OpenNMS.
the class AlarmRestService method doUpdateProperties.
@Override
protected Response doUpdateProperties(SecurityContext securityContext, UriInfo uriInfo, OnmsAlarm alarm, MultivaluedMapImpl params) {
boolean isProcessAck = true;
final String ackValue = params.getFirst("ack");
final String escalateValue = params.getFirst("escalate");
final String clearValue = params.getFirst("clear");
final String ackUserValue = params.getFirst("ackUser");
final String ticketIdValue = params.getFirst("ticketId");
final String ticketStateValue = params.getFirst("ticketState");
final String ackUser = ackUserValue == null ? securityContext.getUserPrincipal().getName() : ackUserValue;
SecurityHelper.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 {
throw getException(Status.BAD_REQUEST, "Must supply one of the 'ack', 'escalate', or 'clear' parameters, set to either 'true' or 'false'.");
}
if (isProcessAck) {
m_ackDao.processAck(acknowledgement);
} else {
getDao().saveOrUpdate(alarm);
}
return Response.noContent().build();
}
use of org.opennms.netmgt.model.OnmsAcknowledgment 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();
}
SecurityHelper.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();
}
Aggregations