Search in sources :

Example 91 with OnmsAlarm

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

the class DefaultTicketerServiceLayer method cancelTicketForAlarm.

/*
     * (non-Javadoc)
     * @see org.opennms.netmgt.ticketd.TicketerServiceLayer#cancelTicketForAlarm(int, java.lang.String)
     */
/**
 * {@inheritDoc}
 */
@Override
public void cancelTicketForAlarm(int alarmId, String ticketId) {
    OnmsAlarm alarm = m_alarmDao.get(alarmId);
    if (alarm == null) {
        LOG.error("No alarm with id {} was found. Ticket with id '{}' will not be canceled.", alarmId, ticketId);
        return;
    }
    try {
        setTicketState(ticketId, Ticket.State.CANCELLED);
        alarm.setTTicketState(TroubleTicketState.CANCELLED);
    } catch (PluginException e) {
        alarm.setTTicketState(TroubleTicketState.CANCEL_FAILED);
        LOG.error("Unable to cancel ticket for alarm: {}", e.getMessage(), e);
        m_eventIpcManager.sendNow(createEvent(e.getMessage()));
    }
    m_alarmDao.saveOrUpdate(alarm);
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) PluginException(org.opennms.api.integration.ticketing.PluginException)

Example 92 with OnmsAlarm

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

the class DefaultNodeStatusCalculatorIT method createAndPersistAlarm.

private OnmsAlarm createAndPersistAlarm(OnmsNode node, OnmsSeverity severity) {
    OnmsAlarm alarm = TestUtils.createAlarm(node, severity, distPollerDao.whoami());
    alarmDao.save(alarm);
    alarmDao.flush();
    return alarm;
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm)

Example 93 with OnmsAlarm

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

the class AcknowledgmentDaoIT method testSaveWithAlarm.

@Test
@Transactional
public void testSaveWithAlarm() {
    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(new Integer(1));
    alarm.setDistPoller(m_distPollerDao.whoami());
    alarm.setAlarmAckTime(new Date());
    alarm.setAlarmAckUser("not-admin");
    m_alarmDao.save(alarm);
    m_alarmDao.flush();
    OnmsAcknowledgment ack = new OnmsAcknowledgment(alarm);
    getAcknowledgmentDao().save(ack);
    Integer ackId = new Integer(ack.getId());
    ack = null;
    OnmsAcknowledgment ack2 = getAcknowledgmentDao().get(ackId);
    OnmsAlarm alarm2 = m_alarmDao.get(ack2.getRefId());
    assertEquals(ack2.getAckUser(), alarm2.getAlarmAckUser());
    assertEquals(ack2.getAckTime(), alarm2.getAlarmAckTime());
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Date(java.util.Date) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 94 with OnmsAlarm

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

the class AlarmDaoIT method testParameterizedSql.

/**
 * @see https://issues.opennms.org/browse/NMS-9480
 */
@Test
@Transactional
public void testParameterizedSql() {
    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());
    m_alarmDao.save(alarm);
    CriteriaBuilder cb = new CriteriaBuilder(OnmsAlarm.class);
    cb.sql("{alias}.alarmid in (?)", alarm.getId(), Type.INTEGER);
    List<OnmsAlarm> alarms = m_alarmDao.findMatching(cb.toCriteria());
    assertEquals(alarm.getId(), alarms.get(0).getId());
    assertEquals(event.getEventTime(), alarms.get(0).getFirstEventTime());
    assertEquals(event.getEventUei(), alarms.get(0).getUei());
    cb = new CriteriaBuilder(OnmsAlarm.class);
    cb.sql("{alias}.firsteventtime = ?", event.getEventTime(), Type.TIMESTAMP);
    m_alarmDao.findMatching(cb.toCriteria());
    assertEquals(alarm.getId(), alarms.get(0).getId());
    assertEquals(event.getEventTime(), alarms.get(0).getFirstEventTime());
    assertEquals(event.getEventUei(), alarms.get(0).getUei());
    cb = new CriteriaBuilder(OnmsAlarm.class);
    cb.sql("{alias}.eventuei = ?", event.getEventUei(), Type.STRING);
    m_alarmDao.findMatching(cb.toCriteria());
    assertEquals(alarm.getId(), alarms.get(0).getId());
    assertEquals(event.getEventTime(), alarms.get(0).getFirstEventTime());
    assertEquals(event.getEventUei(), alarms.get(0).getUei());
    cb = new CriteriaBuilder(OnmsAlarm.class);
    cb.sql("{alias}.alarmid = ? and {alias}.eventuei like ?", new Object[] { alarm.getId(), "%uei.opennms.org%" }, new Type[] { Type.INTEGER, Type.STRING });
    m_alarmDao.findMatching(cb.toCriteria());
    assertEquals(alarm.getId(), alarms.get(0).getId());
    assertEquals(event.getEventTime(), alarms.get(0).getFirstEventTime());
    assertEquals(event.getEventUei(), alarms.get(0).getUei());
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Date(java.util.Date) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 95 with OnmsAlarm

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

the class AlarmDaoIT method testSave.

@Test
@Transactional
public void testSave() {
    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());
    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());
    Collection<OnmsAlarm> alarms;
    Criteria criteria = new Criteria(OnmsAlarm.class);
    criteria.addRestriction(new EqRestriction("node.id", node.getId()));
    alarms = m_alarmDao.findMatching(criteria);
    assertEquals(1, alarms.size());
    newAlarm = alarms.iterator().next();
    assertEquals("uei://org/opennms/test/EventDaoTest", newAlarm.getUei());
    assertEquals(alarm.getLastEvent().getId(), newAlarm.getLastEvent().getId());
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) EqRestriction(org.opennms.core.criteria.restrictions.EqRestriction) Criteria(org.opennms.core.criteria.Criteria) Date(java.util.Date) Test(org.junit.Test) 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