Search in sources :

Example 61 with OnmsEvent

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

the class OutageDaoIT method getEvent.

private OnmsEvent getEvent() {
    OnmsEvent event = new OnmsEvent();
    event.setDistPoller(getLocalHostDistPoller());
    event.setEventUei("foo!");
    event.setEventTime(new Date());
    event.setEventCreateTime(new Date());
    event.setEventSeverity(OnmsSeverity.INDETERMINATE.getId());
    event.setEventSource("your mom");
    event.setEventLog("Y");
    event.setEventDisplay("Y");
    m_eventDao.save(event);
    return event;
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) Date(java.util.Date)

Example 62 with OnmsEvent

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

the class OutageDaoIT method testSave.

@Test
@Transactional
public void testSave() {
    OnmsNode node = new OnmsNode(m_locationDao.getDefaultLocation(), "localhost");
    m_nodeDao.save(node);
    OnmsIpInterface ipInterface = new OnmsIpInterface(addr("172.16.1.1"), node);
    OnmsServiceType serviceType = m_serviceTypeDao.findByName("ICMP");
    assertNotNull(serviceType);
    OnmsMonitoredService monitoredService = new OnmsMonitoredService(ipInterface, serviceType);
    OnmsEvent event = new OnmsEvent();
    OnmsOutage outage = new OnmsOutage(new Date(), monitoredService);
    outage.setServiceLostEvent(event);
    m_outageDao.save(outage);
    // it works we're so smart! hehe
    outage = m_outageDao.load(outage.getId());
    assertEquals("ICMP", outage.getMonitoredService().getServiceType().getName());
// outage.setEventBySvcRegainedEvent();
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 63 with OnmsEvent

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

the class UserNotificationDaoIT method testSaveUserNotification.

@Test
@Transactional
public void testSaveUserNotification() {
    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/UserNotificationDaoTest");
    OnmsAlarm alarm = new OnmsAlarm();
    event.setAlarm(alarm);
    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());
    event.setIpAddr(iface.getIpAddress());
    m_eventDao.save(event);
    OnmsEvent newEvent = m_eventDao.load(event.getId());
    assertEquals("uei://org/opennms/test/UserNotificationDaoTest", 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/UserNotificationDaoTest", newNotification.getEvent().getEventUei());
    OnmsUserNotification userNotif = new OnmsUserNotification();
    userNotif.setNotification(notification);
    userNotif.setNotifyTime(new Date());
    userNotif.setUserId("OpenNMS User");
    userNotif.setMedia("E-mail");
    userNotif.setContactInfo("test@opennms.org");
    m_userNotificationDao.save(userNotif);
    assertNotNull(userNotif.getNotification());
    assertEquals(userNotif.getUserId(), "OpenNMS User");
}
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) OnmsUserNotification(org.opennms.netmgt.model.OnmsUserNotification) 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 64 with OnmsEvent

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

the class EventDaoHibernate method getEventsForEventParameters.

public List<OnmsEvent> getEventsForEventParameters(final Map<String, String> eventParameters) {
    final StringBuffer hqlStringBuffer = new StringBuffer("From OnmsEvent e where ");
    for (int i = 0; i < eventParameters.size(); i++) {
        if (i > 0) {
            hqlStringBuffer.append(" and ");
        }
        hqlStringBuffer.append("exists (select p.event from OnmsEventParameter p where e=p.event and p.name = :name" + i + " and p.value like :value" + i + ")");
    }
    return (List<OnmsEvent>) getHibernateTemplate().executeFind(new HibernateCallback<List<OnmsEvent>>() {

        @Override
        public List<OnmsEvent> doInHibernate(Session session) throws HibernateException, SQLException {
            Query q = session.createQuery(hqlStringBuffer.toString());
            int i = 0;
            for (final Map.Entry<String, String> entry : eventParameters.entrySet()) {
                q = q.setParameter("name" + i, entry.getKey()).setParameter("value" + i, entry.getValue());
                i++;
            }
            return q.list();
        }
    });
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) Query(org.hibernate.Query) List(java.util.List) HibernateCallback(org.springframework.orm.hibernate3.HibernateCallback) Map(java.util.Map) Session(org.hibernate.Session)

Example 65 with OnmsEvent

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

the class BeanWrapperVisitorTest method testEventsMatching.

@Test
public void testEventsMatching() {
    final CriteriaBuilder cb = new CriteriaBuilder(OnmsEvent.class);
    cb.eq("eventuei", EventConstants.NODE_DOWN_EVENT_UEI);
    cb.isNull("ipaddr");
    final List<OnmsEvent> events = new ArrayList<>();
    events.add(createEvent(1, "uei.opennms.org/test"));
    events.add(createEvent(2, EventConstants.NODE_DOWN_EVENT_UEI));
    events.add(createEvent(3, EventConstants.NODE_DOWN_EVENT_UEI));
    final BeanWrapperCriteriaVisitor visitor = new BeanWrapperCriteriaVisitor(events);
    cb.toCriteria().visit(visitor);
    assertEquals(2, visitor.getMatches().size());
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) ArrayList(java.util.ArrayList) Test(org.junit.Test)

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