Search in sources :

Example 1 with Acknowledgeable

use of org.opennms.netmgt.model.Acknowledgeable 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)

Example 2 with Acknowledgeable

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

the class AcknowledgmentDaoHibernate method findAcknowledgables.

/** {@inheritDoc} */
@Override
public List<Acknowledgeable> findAcknowledgables(final OnmsAcknowledgment ack) {
    List<Acknowledgeable> ackables = new ArrayList<Acknowledgeable>();
    if (ack == null || ack.getAckType() == null) {
        return ackables;
    }
    if (ack.getAckType().equals(AckType.ALARM)) {
        final OnmsAlarm alarm = findAlarm(ack);
        try {
            if (alarm != null && alarm.getAckId() != null) {
                ackables.add(alarm);
                List<OnmsNotification> notifs = findRelatedNotifications(alarm);
                if (notifs != null) {
                    for (OnmsNotification notif : notifs) {
                        try {
                            if (notif.getAckId() != null) {
                                ackables.add(notif);
                            }
                        } catch (final ObjectNotFoundException e) {
                            LOG.warn("found ackables for alarm #{} but ackable was invalid", ack.getRefId(), e);
                        }
                    }
                }
            }
        } catch (final ObjectNotFoundException e) {
            LOG.warn("unable to find alarm with ID {}", ack.getRefId(), e);
        }
    } else if (ack.getAckType().equals(AckType.NOTIFICATION)) {
        final OnmsNotification notif = findNotification(ack);
        try {
            if (notif != null && notif.getAckId() != null) {
                ackables.add(notif);
                try {
                    if (notif.getEvent() != null) {
                        final OnmsAlarm alarm = notif.getEvent().getAlarm();
                        if (alarm != null) {
                            ackables.add(alarm);
                        }
                    }
                } catch (final ObjectNotFoundException e) {
                    LOG.warn("unable to find alarm for notification #{}", notif.getNotifyId(), e);
                }
            }
        } catch (final ObjectNotFoundException e) {
            LOG.warn("unable to find notification with ID {}", ack.getRefId(), e);
        }
    }
    return ackables;
}
Also used : Acknowledgeable(org.opennms.netmgt.model.Acknowledgeable) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) ObjectNotFoundException(org.hibernate.ObjectNotFoundException) ArrayList(java.util.ArrayList) OnmsNotification(org.opennms.netmgt.model.OnmsNotification)

Example 3 with Acknowledgeable

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

the class AcknowledgmentDaoHibernate method processAck.

/** {@inheritDoc} */
@Transactional(readOnly = false)
@Override
public void processAck(OnmsAcknowledgment ack) {
    LOG.info("processAck: Searching DB for acknowledgables for ack: {}", ack);
    List<Acknowledgeable> ackables = findAcknowledgables(ack);
    if (ackables == null || ackables.size() < 1) {
        LOG.debug("processAck: No acknowledgables found.");
        throw new IllegalStateException("No acknowlegables in the database for ack: " + ack);
    }
    LOG.debug("processAck: Found {}. Acknowledging...", ackables.size());
    Iterator<Acknowledgeable> it = ackables.iterator();
    while (it.hasNext()) {
        try {
            Acknowledgeable ackable = it.next();
            switch(ack.getAckAction()) {
                case ACKNOWLEDGE:
                    LOG.debug("processAck: Acknowledging ackable: {}...", ackable);
                    ackable.acknowledge(ack.getAckUser());
                    LOG.debug("processAck: Acknowledged ackable: {}", ackable);
                    break;
                case UNACKNOWLEDGE:
                    LOG.debug("processAck: Unacknowledging ackable: {}...", ackable);
                    ackable.unacknowledge(ack.getAckUser());
                    LOG.debug("processAck: Unacknowledged ackable: {}", ackable);
                    break;
                case CLEAR:
                    LOG.debug("processAck: Clearing ackable: {}...", ackable);
                    ackable.clear(ack.getAckUser());
                    LOG.debug("processAck: Cleared ackable: {}", ackable);
                    break;
                case ESCALATE:
                    LOG.debug("processAck: Escalating ackable: {}...", ackable);
                    ackable.escalate(ack.getAckUser());
                    LOG.debug("processAck: Escalated ackable: {}", ackable);
                    break;
                default:
                    break;
            }
            updateAckable(ackable);
            save(ack);
            flush();
        } catch (Throwable t) {
            LOG.error("processAck: exception while processing: {}; {}", ack, t);
        }
    }
    LOG.info("processAck: Found and processed acknowledgables for the acknowledgement: {}", ack);
}
Also used : Acknowledgeable(org.opennms.netmgt.model.Acknowledgeable) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Acknowledgeable (org.opennms.netmgt.model.Acknowledgeable)3 OnmsNotification (org.opennms.netmgt.model.OnmsNotification)2 ArrayList (java.util.ArrayList)1 ObjectNotFoundException (org.hibernate.ObjectNotFoundException)1 Test (org.junit.Test)1 OnmsAcknowledgment (org.opennms.netmgt.model.OnmsAcknowledgment)1 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)1 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)1 OnmsNode (org.opennms.netmgt.model.OnmsNode)1 Transactional (org.springframework.transaction.annotation.Transactional)1