use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class AlarmDaoIT method testAlarmSummary.
@Test
@Transactional
public void testAlarmSummary() {
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);
List<AlarmSummary> summary = m_alarmDao.getNodeAlarmSummaries();
Assert.assertNotNull(summary);
Assert.assertEquals(1, summary.size());
AlarmSummary sum = summary.get(0);
Assert.assertEquals(node.getLabel(), sum.getNodeLabel());
Assert.assertEquals(alarm.getSeverity().getId(), sum.getMaxSeverity().getId());
Assert.assertNotSame("N/A", sum.getFuzzyTimeDown());
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class EventDaoIT method testSave.
@Test
@Transactional
public void testSave() {
OnmsEvent event = new OnmsEvent();
event.setDistPoller(m_distPollerDao.whoami());
event.setEventCreateTime(new Date());
event.setEventDescr("event dao test");
event.setEventHost("localhost");
event.setEventLog("Y");
event.setEventDisplay("Y");
event.setEventLogGroup("event dao test log group");
event.setEventLogMsg("event dao test log msg");
event.setEventSeverity(OnmsSeverity.CRITICAL.getId());
event.setEventSource("EventDaoTest");
event.setEventTime(new Date());
event.setEventUei("uei://org/opennms/test/EventDaoTest");
OnmsNode node = (OnmsNode) m_nodeDao.findAll().iterator().next();
OnmsIpInterface iface = (OnmsIpInterface) node.getIpInterfaces().iterator().next();
OnmsMonitoredService service = (OnmsMonitoredService) iface.getMonitoredServices().iterator().next();
event.setNode(node);
event.setServiceType(service.getServiceType());
OnmsAlarm alarm = new OnmsAlarm();
event.setAlarm(alarm);
event.setIpAddr(iface.getIpAddress());
event.setEventParameters(Lists.newArrayList(new OnmsEventParameter(event, "label", "node", "string"), new OnmsEventParameter(event, "ds", "(memAvailReal + memCached) / memTotalReal * 100.0", "string"), new OnmsEventParameter(event, "description", "(memAvailReal + memCached) / memTotalReal * 100.0", "string"), new OnmsEventParameter(event, "value", "4.7", "string"), new OnmsEventParameter(event, "instance", "node", "string"), new OnmsEventParameter(event, "instanceLabel", "node", "string"), new OnmsEventParameter(event, "resourceId", "node[70].nodeSnmp[]", "string"), new OnmsEventParameter(event, "threshold", "5.0", "string"), new OnmsEventParameter(event, "trigger", "2", "string"), new OnmsEventParameter(event, "rearm", "10.0", "string")));
m_eventDao.save(event);
OnmsEvent newEvent = m_eventDao.load(event.getId());
assertEquals("uei://org/opennms/test/EventDaoTest", newEvent.getEventUei());
assertNotNull(newEvent.getServiceType());
assertEquals(service.getNodeId(), newEvent.getNode().getId());
assertEquals(event.getIpAddr(), newEvent.getIpAddr());
System.err.println(JaxbUtils.marshal(event));
}
use of org.opennms.netmgt.model.OnmsEvent 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.OnmsEvent in project opennms by OpenNMS.
the class NotificationDaoIT method testNotificationSave.
@Test
@Transactional
public void testNotificationSave() {
OnmsEvent event = new OnmsEvent();
event.setDistPoller(m_distPollerDao.whoami());
event.setEventCreateTime(new Date());
event.setEventDescr("event dao test");
event.setEventHost("localhost");
event.setEventLog("Y");
event.setEventDisplay("Y");
event.setEventLogGroup("event dao test log group");
event.setEventLogMsg("event dao test log msg");
event.setEventSeverity(OnmsSeverity.CRITICAL.getId());
event.setEventSource("EventDaoTest");
event.setEventTime(new Date());
event.setEventUei("uei://org/opennms/test/NotificationDaoTest");
// OnmsAlarm alarm = new OnmsAlarm();
// event.setAlarm(alarm);
OnmsNode node = m_nodeDao.findAll().iterator().next();
OnmsIpInterface iface = node.getIpInterfaces().iterator().next();
OnmsMonitoredService service = iface.getMonitoredServices().iterator().next();
event.setNode(node);
event.setServiceType(service.getServiceType());
event.setIpAddr(iface.getIpAddress());
m_eventDao.save(event);
OnmsEvent newEvent = m_eventDao.load(event.getId());
assertEquals("uei://org/opennms/test/NotificationDaoTest", newEvent.getEventUei());
OnmsNotification notification = new OnmsNotification();
notification.setEvent(newEvent);
notification.setTextMsg("Tests are fun!");
m_notificationDao.save(notification);
OnmsNotification newNotification = m_notificationDao.load(notification.getNotifyId());
assertEquals("uei://org/opennms/test/NotificationDaoTest", newNotification.getEvent().getEventUei());
}
use of org.opennms.netmgt.model.OnmsEvent in project opennms by OpenNMS.
the class MockEventDao method getEventsAfterDate.
@Override
public List<OnmsEvent> getEventsAfterDate(List<String> ueiList, Date date) {
List<OnmsEvent> matchingEvents = new ArrayList<OnmsEvent>();
List<OnmsEvent> allEvents = findAll();
for (OnmsEvent eachEvent : allEvents) {
if (ueiList.contains(eachEvent.getEventUei()) && eachEvent.getEventTime().after(date)) {
matchingEvents.add(eachEvent);
}
}
return matchingEvents;
}
Aggregations