use of org.opennms.netmgt.model.OnmsNotification in project opennms by OpenNMS.
the class AckdIT method testHandelEvent.
@Test
public void testHandelEvent() throws InterruptedException {
VerificationObject vo = createAckStructure();
EventBuilder bldr = new EventBuilder(EventConstants.ACKNOWLEDGE_EVENT_UEI, "AckdTest");
bldr.addParam("ackType", String.valueOf(AckType.ALARM));
bldr.addParam("refId", vo.m_alarmId);
final String user = "ackd-test-user";
bldr.addParam("user", user);
m_daemon.handleAckEvent(bldr.getEvent());
OnmsNotification notif = m_notificationDao.get(vo.m_notifId);
Assert.assertEquals(notif.getAckUser(), user);
// Assert.assertEquals(notif.getAckTime(), bldr.getEvent().getTime());
OnmsAlarm alarm = m_alarmDao.get(vo.m_alarmId);
Assert.assertEquals(alarm.getAckUser(), user);
// Assert.assertEquals(alarm.getAckTime(), bldr.getEvent().getTime());
}
use of org.opennms.netmgt.model.OnmsNotification in project opennms by OpenNMS.
the class DefaultSurveillanceViewService method getNotificationsWithCriterias.
/**
* Returns a list of notifications for a given list of nodes.
*
* @param rowCategories the row catgories
* @param colCategories the column categories
* @param customSeverity the custom severity mapping for notifications
* @param severity the severity for these nodes
* @param criterias the restrictions to use
* @return the list of notifications
*/
private List<OnmsNotification> getNotificationsWithCriterias(final Set<OnmsCategory> rowCategories, final Set<OnmsCategory> colCategories, final Map<OnmsNotification, String> customSeverity, final String severity, final Restriction... criterias) {
CriteriaBuilder criteriaBuilder = new CriteriaBuilder(OnmsNotification.class);
criteriaBuilder.alias("node", "node");
// Restrict on OnmsNotification.nodeId
criteriaBuilder.sql(createQuery("{alias}.nodeId", rowCategories, colCategories));
criteriaBuilder.ne("node.type", "D");
criteriaBuilder.orderBy("pageTime", false);
Criteria myCriteria = criteriaBuilder.toCriteria();
for (Restriction criteria : criterias) {
myCriteria.addRestriction(criteria);
}
List<OnmsNotification> notifications = m_notificationDao.findMatching(myCriteria);
for (OnmsNotification onmsNotification : notifications) {
customSeverity.put(onmsNotification, severity);
}
return notifications;
}
use of org.opennms.netmgt.model.OnmsNotification 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(7);
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.OnmsNotification in project opennms by OpenNMS.
the class DaoWebNotificationRepository method acknowledgeMatchingNotification.
/** {@inheritDoc} */
@Transactional
@Override
public void acknowledgeMatchingNotification(String user, Date timestamp, NotificationCriteria criteria) {
List<OnmsNotification> notifs = m_notificationDao.findMatching(getOnmsCriteria(criteria));
for (OnmsNotification notif : notifs) {
OnmsAcknowledgment ack = new OnmsAcknowledgment(notif, user);
ack.setAckAction(AckAction.ACKNOWLEDGE);
ack.setAckTime(timestamp);
m_ackDao.processAck(ack);
}
}
use of org.opennms.netmgt.model.OnmsNotification in project opennms by OpenNMS.
the class DaoWebNotificationRepository method mapOnmsNotificationToNotification.
private static Notification mapOnmsNotificationToNotification(OnmsNotification onmsNotification) {
if (onmsNotification != null) {
Notification notif = new Notification();
notif.m_eventId = onmsNotification.getEvent() != null ? onmsNotification.getEvent().getId() : 0;
notif.m_interfaceID = onmsNotification.getIpAddress() == null ? null : InetAddressUtils.toIpAddrString(onmsNotification.getIpAddress());
notif.m_nodeID = onmsNotification.getNode() != null ? onmsNotification.getNode().getId() : 0;
notif.m_notifyID = onmsNotification.getNotifyId();
notif.m_numMsg = onmsNotification.getNumericMsg();
notif.m_responder = onmsNotification.getAnsweredBy();
notif.m_serviceId = onmsNotification.getServiceType() != null ? onmsNotification.getServiceType().getId() : 0;
notif.m_serviceName = onmsNotification.getServiceType() != null ? onmsNotification.getServiceType().getName() : "";
notif.m_timeReply = onmsNotification.getRespondTime() != null ? onmsNotification.getRespondTime().getTime() : 0;
notif.m_timeSent = onmsNotification.getPageTime() != null ? onmsNotification.getPageTime().getTime() : 0;
notif.m_txtMsg = onmsNotification.getTextMsg();
// Add the OnmsUserNotifications as NoticeSentTo instances
final List<NoticeSentTo> sentToList = new ArrayList<NoticeSentTo>();
for (OnmsUserNotification userNotified : onmsNotification.getUsersNotified()) {
NoticeSentTo newSentTo = new NoticeSentTo();
newSentTo.setUserId(userNotified.getUserId());
// Can be null
if (userNotified.getNotifyTime() == null) {
newSentTo.setTime(0);
} else {
newSentTo.setTime(userNotified.getNotifyTime().getTime());
}
// Can be null
newSentTo.setMedia(userNotified.getMedia());
// Can be null
newSentTo.setContactInfo(userNotified.getContactInfo());
sentToList.add(newSentTo);
}
notif.m_sentTo = sentToList;
return notif;
} else {
return null;
}
}
Aggregations