use of org.opennms.netmgt.model.OnmsNotification in project opennms by OpenNMS.
the class NotificationRestService method updateNotification.
/**
* <p>updateNotification</p>
*
* @param notifId a {@link java.lang.String} object.
* @param ack a {@link java.lang.Boolean} object.
*/
@PUT
@Path("{notifId}")
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Transactional
public Response updateNotification(@Context final SecurityContext securityContext, @PathParam("notifId") final Integer notifId, @FormParam("ack") final Boolean ack) {
writeLock();
try {
if (ack == null) {
throw getException(Status.BAD_REQUEST, "Must supply the 'ack' parameter, set to either 'true' or 'false'");
}
OnmsNotification notif = getNotification(notifId);
processNotifAck(securityContext, notif, ack);
return Response.noContent().build();
} finally {
writeUnlock();
}
}
use of org.opennms.netmgt.model.OnmsNotification 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.OnmsNotification in project opennms by OpenNMS.
the class AckdIT method testAcknowledgeNotification.
/**
* This tests acknowledging a notification and a related alarm. If events are being deduplicated
* they should all have the same alarm ID.
* @throws InterruptedException
*/
@Test
public void testAcknowledgeNotification() throws InterruptedException {
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);
OnmsAcknowledgment ack = new OnmsAcknowledgment(m_notificationDao.get(vo.m_notifId));
m_ackDao.save(ack);
m_ackDao.flush();
Thread.sleep(1);
m_ackDao.processAck(ack);
OnmsNotification notif = m_notificationDao.get(ack.getRefId());
Assert.assertNotNull(notif.getAnsweredBy());
Assert.assertEquals("admin", notif.getAnsweredBy());
OnmsAlarm alarm = m_alarmDao.get(vo.m_alarmId);
Assert.assertNotNull(alarm);
Assert.assertEquals("admin", alarm.getAlarmAckUser());
long ackTime = ack.getAckTime().getTime();
long respondTime = notif.getRespondTime().getTime();
//the DAOs now set the acknowledgment time for each Acknowledgable and should
//be later (by a few millis in this test) than the time the acknowledgment was created
//this will give us an idea about the processing time of an acknowledgment
Assert.assertTrue(ackTime < respondTime);
}
use of org.opennms.netmgt.model.OnmsNotification in project opennms by OpenNMS.
the class DefaultAckServiceIT method getNotification.
private OnmsNotification getNotification(OnmsEvent event) {
OnmsNotification notif = new OnmsNotification();
notif.setEvent(event);
notif.setNode(event.getNode());
notif.setNumericMsg("123456");
notif.setPageTime(Calendar.getInstance().getTime());
notif.setSubject("ackd notif test");
notif.setTextMsg("ackd notif test");
m_notifDao.save(notif);
m_notifDao.flush();
return notif;
}
use of org.opennms.netmgt.model.OnmsNotification in project opennms by OpenNMS.
the class DefaultAckServiceIT method processAck.
@Test
public void processAck() {
OnmsNode dbNode = m_nodeDao.get(m_populator.getNode1().getId());
OnmsEvent event = getEvent(dbNode);
OnmsNotification notif = getNotification(event);
// OnmsUserNotification un = getUserNotification(notif);
Assert.assertTrue(m_notifDao.countAll() > 0);
List<OnmsNotification> notifs = m_notifDao.findAll();
Assert.assertTrue((notifs.contains(notif)));
OnmsAcknowledgment ack = new OnmsAcknowledgment();
ack.setRefId(notif.getNotifyId());
ack.setAckType(AckType.NOTIFICATION);
m_ackDao.processAck(ack);
List<Acknowledgeable> ackables = m_ackDao.findAcknowledgables(ack);
Assert.assertEquals(1, ackables.size());
Acknowledgeable ackable = ackables.get(0);
Assert.assertEquals("admin", ackable.getAckUser());
}
Aggregations