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);
}
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;
}
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());
}
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());
}
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());
}
Aggregations