Search in sources :

Example 31 with OnmsAlarm

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());
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) ArrayList(java.util.ArrayList) MockTransactionTemplate(org.opennms.netmgt.dao.mock.MockTransactionTemplate) AlarmDao(org.opennms.netmgt.dao.api.AlarmDao) Test(org.junit.Test)

Example 32 with OnmsAlarm

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();
}
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 33 with OnmsAlarm

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

Example 34 with OnmsAlarm

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());
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) AlarmSummary(org.opennms.netmgt.model.alarm.AlarmSummary) Date(java.util.Date) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 35 with OnmsAlarm

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));
}
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) OnmsEventParameter(org.opennms.netmgt.model.OnmsEventParameter) Date(java.util.Date) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)143 Test (org.junit.Test)58 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)41 Date (java.util.Date)36 OnmsNode (org.opennms.netmgt.model.OnmsNode)36 Transactional (org.springframework.transaction.annotation.Transactional)35 OnmsEventParameter (org.opennms.netmgt.model.OnmsEventParameter)19 JUnitTemporaryDatabase (org.opennms.core.test.db.annotations.JUnitTemporaryDatabase)18 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)18 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)17 ArrayList (java.util.ArrayList)14 OnmsAcknowledgment (org.opennms.netmgt.model.OnmsAcknowledgment)14 InetAddress (java.net.InetAddress)13 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)11 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)10 OnmsNotification (org.opennms.netmgt.model.OnmsNotification)9 OnmsSeverity (org.opennms.netmgt.model.OnmsSeverity)9 AlarmDao (org.opennms.netmgt.dao.api.AlarmDao)8 AlarmCriteria (org.opennms.web.alarm.filter.AlarmCriteria)8 LinkedList (java.util.LinkedList)7