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