Search in sources :

Example 6 with OnmsNotification

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();
    }
}
Also used : OnmsNotification(org.opennms.netmgt.model.OnmsNotification) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with OnmsNotification

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()));
}
Also used : OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsNotification(org.opennms.netmgt.model.OnmsNotification) Test(org.junit.Test)

Example 8 with OnmsNotification

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);
}
Also used : OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsNotification(org.opennms.netmgt.model.OnmsNotification) Test(org.junit.Test)

Example 9 with OnmsNotification

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;
}
Also used : OnmsNotification(org.opennms.netmgt.model.OnmsNotification)

Example 10 with OnmsNotification

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());
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) OnmsNode(org.opennms.netmgt.model.OnmsNode) Acknowledgeable(org.opennms.netmgt.model.Acknowledgeable) OnmsNotification(org.opennms.netmgt.model.OnmsNotification) Test(org.junit.Test)

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