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