Search in sources :

Example 16 with OnmsEvent

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());
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) AlarmSummary(org.opennms.netmgt.model.alarm.AlarmSummary) Date(java.util.Date) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 17 with OnmsEvent

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));
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsEventParameter(org.opennms.netmgt.model.OnmsEventParameter) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with OnmsEvent

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());
}
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 19 with OnmsEvent

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());
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsNotification(org.opennms.netmgt.model.OnmsNotification) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 20 with OnmsEvent

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;
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) ArrayList(java.util.ArrayList)

Aggregations

OnmsEvent (org.opennms.netmgt.model.OnmsEvent)94 Date (java.util.Date)49 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)41 OnmsNode (org.opennms.netmgt.model.OnmsNode)37 Test (org.junit.Test)36 OnmsEventParameter (org.opennms.netmgt.model.OnmsEventParameter)22 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)21 Transactional (org.springframework.transaction.annotation.Transactional)19 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)16 InetAddress (java.net.InetAddress)13 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)13 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)13 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)9 ArrayList (java.util.ArrayList)7 Before (org.junit.Before)6 OnmsNotification (org.opennms.netmgt.model.OnmsNotification)6 Event (org.opennms.netmgt.xml.event.Event)6 LinkedList (java.util.LinkedList)5 List (java.util.List)5 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)5