Search in sources :

Example 11 with OnmsEvent

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

the class OutageRestServiceIT method setUp.

@Before
@Override
public void setUp() throws Throwable {
    super.setUp();
    Assert.assertNotNull(populator);
    Assert.assertNotNull(applicationDao);
    populator.addExtension(new DatabasePopulator.Extension<ApplicationDao>() {

        private OnmsOutage unresolvedOutage;

        private OnmsEvent outageEvent;

        private OnmsApplication application;

        @Override
        public DatabasePopulator.DaoSupport<ApplicationDao> getDaoSupport() {
            return new DatabasePopulator.DaoSupport<>(ApplicationDao.class, applicationDao);
        }

        @Override
        public void onPopulate(DatabasePopulator populator, ApplicationDao dao) {
            OnmsDistPoller distPoller = populator.getDistPollerDao().whoami();
            outageEvent = populator.buildEvent(distPoller);
            outageEvent.setEventSeverity(OnmsSeverity.MINOR.getId());
            outageEvent.setEventCreateTime(new Date(1436881548292L));
            outageEvent.setEventTime(new Date(1436881548292L));
            populator.getEventDao().save(outageEvent);
            populator.getEventDao().flush();
            // create the application
            application = new OnmsApplication();
            application.setName("Awesome Application");
            dao.save(application);
            // get the SNMP service from node 1 and assign the application to it
            final OnmsMonitoredService svc = populator.getMonitoredServiceDao().get(populator.getNode1().getId(), InetAddressUtils.addr("192.168.1.2"), "HTTP");
            svc.addApplication(application);
            application.addMonitoredService(svc);
            populator.getMonitoredServiceDao().saveOrUpdate(svc);
            populator.getMonitoredServiceDao().flush();
            // create a unresolved outage
            unresolvedOutage = new OnmsOutage(new Date(1436881548292L), outageEvent, svc);
            populator.getOutageDao().save(unresolvedOutage);
            populator.getOutageDao().flush();
        }

        @Override
        public void onShutdown(DatabasePopulator populator, ApplicationDao dao) {
            // Delete OnmsApplications
            for (OnmsApplication application : dao.findAll()) {
                dao.delete(application);
            }
        }
    });
    populator.populateDatabase();
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsDistPoller(org.opennms.netmgt.model.OnmsDistPoller) ApplicationDao(org.opennms.netmgt.dao.api.ApplicationDao) OnmsApplication(org.opennms.netmgt.model.OnmsApplication) DatabasePopulator(org.opennms.netmgt.dao.DatabasePopulator) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Before(org.junit.Before)

Example 12 with OnmsEvent

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

the class EventdIT method testPersistEvent.

@Test(timeout = 30000)
public void testPersistEvent() throws Exception {
    CriteriaBuilder cb = new CriteriaBuilder(OnmsEvent.class);
    cb.eq("eventUei", EventConstants.NODE_DOWN_EVENT_UEI);
    assertEquals(0, m_eventDao.countMatching(cb.toCriteria()));
    OnmsNode node = m_databasePopulator.getNode1();
    assertNotNull(node);
    sendNodeDownEvent(null, node);
    while (m_eventDao.countMatching(cb.toCriteria()) < 1) {
        Thread.sleep(SLEEP_TIME);
    }
    final List<OnmsEvent> matching = m_eventDao.findMatching(cb.toCriteria());
    System.err.println("matching = " + matching);
    assertEquals(1, m_eventDao.countMatching(cb.toCriteria()));
    node = m_databasePopulator.getNode2();
    assertNotNull(node);
    Event generatedEvent = sendNodeDownEvent(null, node);
    while (m_eventDao.countMatching(cb.toCriteria()) < 2) {
        Thread.sleep(SLEEP_TIME);
    }
    assertEquals(2, m_eventDao.countMatching(cb.toCriteria()));
    assertNull(generatedEvent.getInterfaceAddress());
    cb.isNull("ipAddr");
    assertEquals("failed, found: " + m_eventDao.findMatching(cb.toCriteria()), 2, m_eventDao.countMatching(cb.toCriteria()));
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) Event(org.opennms.netmgt.xml.event.Event) Test(org.junit.Test)

Example 13 with OnmsEvent

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

the class IfTttDaemonTest method addAlarm.

private void addAlarm(Integer id, Integer nodeId, OnmsSeverity onmsSeverity, final boolean acknowledged) {
    final OnmsAlarm onmsAlarm = new OnmsAlarm(id, EventConstants.NODE_LOST_SERVICE_EVENT_UEI, null, null, onmsSeverity.getId(), new Date(), new OnmsEvent()) {

        @Override
        public boolean isAcknowledged() {
            return acknowledged;
        }
    };
    onmsAlarm.setNode(nodeMap.get(nodeId));
    alarmMap.put(id, onmsAlarm);
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Date(java.util.Date)

Example 14 with OnmsEvent

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

the class AlarmDaoIT method testWithoutDistPoller.

@Test
@Transactional
@Ignore
public void testWithoutDistPoller() {
    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);
    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(new DataIntegrityViolationException("not-null property references a null or transient value: org.opennms.netmgt.model.OnmsAlarm.distPoller; nested exception is org.hibernate.PropertyValueException: not-null property references a null or transient value: org.opennms.netmgt.model.OnmsAlarm.distPoller"));
    try {
        m_alarmDao.save(alarm);
    } catch (Throwable t) {
        ta.throwableReceived(t);
    }
    ta.verifyAnticipated();
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Date(java.util.Date) ThrowableAnticipator(org.opennms.test.ThrowableAnticipator) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Ignore(org.junit.Ignore) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with OnmsEvent

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

the class AlarmDaoIT method testActions.

@Test
@Transactional
public void testActions() {
    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.MAJOR.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.setSeverity(OnmsSeverity.get(event.getEventSeverity()));
    alarm.setSeverityId(event.getEventSeverity());
    alarm.setFirstEventTime(event.getEventTime());
    alarm.setLastEvent(event);
    alarm.setCounter(1);
    alarm.setDistPoller(m_distPollerDao.whoami());
    m_alarmDao.save(alarm);
    OnmsAlarm newAlarm = m_alarmDao.load(alarm.getId());
    assertEquals("uei://org/opennms/test/EventDaoTest", newAlarm.getUei());
    assertEquals(alarm.getLastEvent().getId(), newAlarm.getLastEvent().getId());
    assertEquals(OnmsSeverity.MAJOR, newAlarm.getSeverity());
    newAlarm.escalate("admin");
    assertEquals(OnmsSeverity.CRITICAL, newAlarm.getSeverity());
    newAlarm.clear("admin");
    assertEquals(OnmsSeverity.CLEARED, newAlarm.getSeverity());
    newAlarm.unacknowledge("admin");
    assertNull(newAlarm.getAckUser());
    assertNull(newAlarm.getAlarmAckTime());
}
Also used : 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)

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