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