Search in sources :

Example 36 with OnmsAlarm

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

the class MemoDaoIT method testAddStickyMemoToExistingAlarm.

@Test
@Transactional
public void testAddStickyMemoToExistingAlarm() {
    OnmsEvent event = new OnmsEvent();
    event.setEventLog("Y");
    event.setEventDisplay("Y");
    event.setEventCreateTime(new Date());
    event.setDistPoller(m_distPollerDao.whoami());
    event.setEventTime(new Date());
    event.setEventSeverity(OnmsSeverity.CRITICAL.getId());
    event.setEventUei("uei://org/opennms/test/EventDaoTest");
    event.setEventSource("test");
    m_eventDao.save(event);
    OnmsNode node = m_nodeDao.findAll().iterator().next();
    OnmsAlarm alarm = new OnmsAlarm();
    alarm.setNode(node);
    alarm.setUei(event.getEventUei());
    alarm.setSeverityId(event.getEventSeverity());
    alarm.setFirstEventTime(event.getEventTime());
    alarm.setLastEvent(event);
    alarm.setCounter(1);
    alarm.setDistPoller(m_distPollerDao.whoami());
    alarm.setReductionKey("fristReductionKey");
    m_alarmDao.save(alarm);
    // It works we're so smart! hehe
    OnmsAlarm newAlarm = m_alarmDao.load(alarm.getId());
    assertEquals("uei://org/opennms/test/EventDaoTest", newAlarm.getUei());
    assertEquals(alarm.getLastEvent().getId(), newAlarm.getLastEvent().getId());
    final OnmsMemo memo = new OnmsMemo();
    memo.setBody("Call me Ishmael...");
    memo.setAuthor("Herman Melville");
    Date memoCreation = new Date();
    memo.setCreated(memoCreation);
    newAlarm.setStickyMemo(memo);
    m_alarmDao.update(newAlarm);
    m_alarmDao.flush();
    assertNotNull(newAlarm.getStickyMemo().getId());
    assertNotNull(newAlarm.getStickyMemo().getCreated());
    assertNotNull(newAlarm.getStickyMemo().getAuthor());
    assertNotNull(newAlarm.getStickyMemo().getBody());
    assertNotNull(alarm.getStickyMemo().getId());
    assertNotNull(alarm.getStickyMemo().getCreated());
    assertNotNull(alarm.getStickyMemo().getAuthor());
    assertNotNull(alarm.getStickyMemo().getBody());
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsMemo(org.opennms.netmgt.model.OnmsMemo) Date(java.util.Date) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 37 with OnmsAlarm

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

the class DatabasePopulator method buildAlarm.

private OnmsAlarm buildAlarm(final OnmsEvent event) {
    // TODO: Add reductionKey, suppressedTime, suppressedUntil to this object?
    final OnmsAlarm alarm = new OnmsAlarm();
    alarm.setDistPoller(getDistPollerDao().whoami());
    alarm.setUei(event.getEventUei());
    alarm.setAlarmType(OnmsAlarm.PROBLEM_TYPE);
    alarm.setNode(m_node1);
    alarm.setDescription("This is a test alarm");
    alarm.setLogMsg("this is a test alarm log message");
    alarm.setCounter(1);
    alarm.setIpAddr(InetAddressUtils.getInetAddress("192.168.1.1"));
    alarm.setSeverity(OnmsSeverity.NORMAL);
    alarm.setFirstEventTime(event.getEventTime());
    alarm.setLastEvent(event);
    alarm.setServiceType(m_serviceTypeDao.findByName("ICMP"));
    return alarm;
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm)

Example 38 with OnmsAlarm

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

the class AcknowledgmentDaoHibernate method findAcknowledgables.

/**
 * {@inheritDoc}
 */
@Override
public List<Acknowledgeable> findAcknowledgables(final OnmsAcknowledgment ack) {
    List<Acknowledgeable> ackables = new ArrayList<>();
    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 39 with OnmsAlarm

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

the class AlarmRepositoryHibernate method removeReductionKeyMemo.

/**
 * {@inheritDoc}
 */
@Override
@Transactional
public void removeReductionKeyMemo(int alarmId) {
    OnmsAlarm onmsAlarm = m_alarmDao.get(alarmId);
    if (onmsAlarm != null && onmsAlarm.getReductionKeyMemo() != null) {
        m_memoDao.delete(onmsAlarm.getReductionKeyMemo());
        onmsAlarm.setReductionKeyMemo(null);
    }
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Transactional(org.springframework.transaction.annotation.Transactional)

Example 40 with OnmsAlarm

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

the class AlarmRepositoryHibernate method updateStickyMemo.

/**
 * {@inheritDoc}
 */
@Override
@Transactional
public void updateStickyMemo(Integer alarmId, String body, String user) {
    OnmsAlarm onmsAlarm = m_alarmDao.get(alarmId);
    if (onmsAlarm != null) {
        if (onmsAlarm.getStickyMemo() == null) {
            onmsAlarm.setStickyMemo(new OnmsMemo());
            onmsAlarm.getStickyMemo().setCreated(new Date());
        }
        onmsAlarm.getStickyMemo().setBody(body);
        onmsAlarm.getStickyMemo().setAuthor(user);
        onmsAlarm.getStickyMemo().setUpdated(new Date());
        m_alarmDao.saveOrUpdate(onmsAlarm);
    }
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsMemo(org.opennms.netmgt.model.OnmsMemo) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)143 Test (org.junit.Test)58 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)41 Date (java.util.Date)36 OnmsNode (org.opennms.netmgt.model.OnmsNode)36 Transactional (org.springframework.transaction.annotation.Transactional)35 OnmsEventParameter (org.opennms.netmgt.model.OnmsEventParameter)19 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)18 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)18 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)17 ArrayList (java.util.ArrayList)14 OnmsAcknowledgment (org.opennms.netmgt.model.OnmsAcknowledgment)14 InetAddress (java.net.InetAddress)13 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)11 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)10 OnmsNotification (org.opennms.netmgt.model.OnmsNotification)9 OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)9 AlarmDao (org.opennms.netmgt.dao.api.AlarmDao)8 AlarmCriteria (org.opennms.web.alarm.filter.AlarmCriteria)8 LinkedList (java.util.LinkedList)7