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