Search in sources :

Example 96 with OnmsAlarm

use of org.opennms.netmgt.model.OnmsAlarm 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 97 with OnmsAlarm

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

the class AlarmRepositoryHibernate method clearAlarms.

/**
 * {@inheritDoc}
 */
@Transactional
@Override
public void clearAlarms(int[] alarmIds, String user, Date timestamp) {
    OnmsCriteria criteria = new OnmsCriteria(OnmsAlarm.class);
    criteria.add(Restrictions.in("id", Arrays.asList(ArrayUtils.toObject(alarmIds))));
    List<OnmsAlarm> alarms = m_alarmDao.findMatching(criteria);
    Iterator<OnmsAlarm> alarmsIt = alarms.iterator();
    while (alarmsIt.hasNext()) {
        OnmsAlarm alarm = alarmsIt.next();
        OnmsAcknowledgment ack = new OnmsAcknowledgment(alarm, user);
        ack.setAckTime(timestamp);
        ack.setAckAction(AckAction.CLEAR);
        m_ackDao.processAck(ack);
    }
}
Also used : OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria) Transactional(org.springframework.transaction.annotation.Transactional)

Example 98 with OnmsAlarm

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

the class AlarmRepositoryHibernate method acknowledgeMatchingAlarms.

/**
 * {@inheritDoc}
 */
@Transactional
@Override
public void acknowledgeMatchingAlarms(String user, Date timestamp, OnmsCriteria criteria) {
    List<OnmsAlarm> alarms = m_alarmDao.findMatching(criteria);
    Iterator<OnmsAlarm> alarmsIt = alarms.iterator();
    while (alarmsIt.hasNext()) {
        OnmsAlarm alarm = alarmsIt.next();
        OnmsAcknowledgment ack = new OnmsAcknowledgment(alarm, user);
        ack.setAckTime(timestamp);
        ack.setAckAction(AckAction.ACKNOWLEDGE);
        m_ackDao.processAck(ack);
    }
}
Also used : OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) Transactional(org.springframework.transaction.annotation.Transactional)

Example 99 with OnmsAlarm

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

the class AlarmRepositoryHibernate method updateReductionKeyMemo.

/**
 * {@inheritDoc}
 */
@Override
@Transactional
public void updateReductionKeyMemo(Integer alarmId, String body, String user) {
    OnmsAlarm onmsAlarm = m_alarmDao.get(alarmId);
    if (onmsAlarm != null) {
        OnmsReductionKeyMemo memo = onmsAlarm.getReductionKeyMemo();
        if (memo == null) {
            memo = new OnmsReductionKeyMemo();
            memo.setCreated(new Date());
        }
        memo.setBody(body);
        memo.setAuthor(user);
        memo.setReductionKey(onmsAlarm.getReductionKey());
        memo.setUpdated(new Date());
        m_memoDao.saveOrUpdate(memo);
        onmsAlarm.setReductionKeyMemo(memo);
    }
}
Also used : OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsReductionKeyMemo(org.opennms.netmgt.model.OnmsReductionKeyMemo) Date(java.util.Date) Transactional(org.springframework.transaction.annotation.Transactional)

Example 100 with OnmsAlarm

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

the class BsmdIT method verifyNoDaoLookupsWhenNoRulesAreDefined.

@Test
public void verifyNoDaoLookupsWhenNoRulesAreDefined() throws Exception {
    // Mock the DAO
    AlarmDao alarmDao = mock(AlarmDao.class);
    m_bsmd.setAlarmDao(alarmDao);
    // Start up without any business services
    m_bsmd.start();
    assertThat("Alarm polling should be disabled where there are no services.", m_bsmd.isAlarmPolling(), equalTo(false));
    // Create the alarm
    OnmsAlarm alarm = createAlarm();
    m_alarmDao.save(alarm);
    // Send alarm created event
    EventBuilder ebldr = new EventBuilder(EventConstants.ALARM_CREATED_UEI, "test");
    ebldr.addParam(EventConstants.PARM_ALARM_ID, alarm.getId());
    m_bsmd.handleAlarmLifecycleEvents(ebldr.getEvent());
    // The AlarmDAO should not have any lookups
    verify(alarmDao, never()).get(anyObject());
    // Now let's add a rule
    createBusinessService("svc");
    // Reload the daemon
    reloadBsmd();
    assertThat("Alarm polling should be enabled when there are 1+ services.", m_bsmd.isAlarmPolling(), equalTo(true));
    // Send alarm updated event
    ebldr = new EventBuilder(EventConstants.ALARM_UPDATED_WITH_REDUCED_EVENT_UEI, "test");
    ebldr.addParam(EventConstants.PARM_ALARM_ID, alarm.getId());
    m_bsmd.handleAlarmLifecycleEvents(ebldr.getEvent());
    // The AlarmDAO should have a single lookup
    verify(alarmDao, times(1)).get(anyObject());
    // Clear all of the BSs and reload
    deleteAllBusinessServices();
    reloadBsmd();
    assertThat("Alarm polling should be disabled where there are no services.", m_bsmd.isAlarmPolling(), equalTo(false));
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) AlarmDao(org.opennms.netmgt.dao.api.AlarmDao) Test(org.junit.Test)

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