use of org.opennms.netmgt.model.OnmsAlarm in project opennms by OpenNMS.
the class OnmsDaoContainerTest method testGetItemIdsWithOnlyOneItem.
@Test
public void testGetItemIdsWithOnlyOneItem() {
MockTransactionTemplate transactionTemplate = new MockTransactionTemplate();
transactionTemplate.afterPropertiesSet();
List<OnmsAlarm> alarmList = new ArrayList<>();
OnmsAlarm alarm = new OnmsAlarm();
alarm.setId(102);
alarmList.add(alarm);
final AlarmDao alarmDaoMock = EasyMock.createNiceMock(AlarmDao.class);
EasyMock.expect(alarmDaoMock.countMatching((Criteria) EasyMock.anyObject())).andReturn(1);
EasyMock.expect(alarmDaoMock.findMatching((Criteria) EasyMock.anyObject())).andReturn(alarmList);
EasyMock.replay(alarmDaoMock);
AlarmDaoContainer container = new AlarmDaoContainer(alarmDaoMock, transactionTemplate);
List<Integer> items = container.getItemIds(0, 1);
Assert.assertNotNull(items);
Assert.assertEquals(1, items.size());
}
use of org.opennms.netmgt.model.OnmsAlarm 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.OnmsAlarm 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());
}
use of org.opennms.netmgt.model.OnmsAlarm 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());
}
use of org.opennms.netmgt.model.OnmsAlarm 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));
}
Aggregations