Search in sources :

Example 6 with OnmsUserNotification

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

the class AckdIT method createAckStructure.

private VerificationObject createAckStructure() {
    final Date time = new Date();
    VerificationObject vo = new VerificationObject();
    List<OnmsNode> nodes = m_nodeDao.findAll();
    Assert.assertTrue("List of nodes should not be empty", nodes.size() > 0);
    OnmsNode node = m_nodeDao.get(nodes.get(0).getId());
    vo.m_nodeId = node.getId();
    OnmsEvent event = new OnmsEvent();
    event.setDistPoller(m_populator.getDistPollerDao().whoami());
    event.setNode(node);
    event.setEventCreateTime(time);
    event.setEventDescr("Test node down event.");
    event.setEventSeverity(OnmsSeverity.MAJOR.getId());
    event.setEventSource("AckdTest");
    event.setEventTime(time);
    event.setEventUei(EventConstants.NODE_DOWN_EVENT_UEI);
    event.setIpAddr(node.getPrimaryInterface().getIpAddress());
    event.setEventLog("Y");
    event.setEventDisplay("Y");
    event.setEventLogMsg("Testing node down event from AckdTest.");
    m_eventDao.save(event);
    m_eventDao.flush();
    vo.m_eventID = event.getId();
    OnmsAlarm alarm = new OnmsAlarm();
    alarm.setAlarmType(OnmsAlarm.PROBLEM_TYPE);
    alarm.setClearKey(EventConstants.NODE_UP_EVENT_UEI + ":localhost:1");
    alarm.setCounter(1);
    alarm.setDescription(event.getEventDescr());
    alarm.setDistPoller(event.getDistPoller());
    alarm.setFirstEventTime(event.getEventTime());
    alarm.setIpAddr(event.getIpAddr());
    alarm.setLastEvent(event);
    alarm.setLastEventTime(event.getEventTime());
    alarm.setLogMsg("Some Log Message");
    alarm.setNode(event.getNode());
    alarm.setReductionKey("xyz");
    alarm.setServiceType(event.getServiceType());
    alarm.setSeverity(OnmsSeverity.get(event.getEventSeverity()));
    alarm.setUei(event.getEventUei());
    m_alarmDao.save(alarm);
    m_alarmDao.flush();
    vo.m_alarmId = alarm.getId();
    event.setAlarm(alarm);
    OnmsNotification notif = new OnmsNotification();
    notif.setEvent(event);
    notif.setEventUei(event.getEventUei());
    notif.setIpAddress(event.getIpAddr());
    notif.setNode(event.getNode());
    notif.setNotifConfigName("abc");
    notif.setNumericMsg(event.getEventLogMsg());
    notif.setPageTime(event.getEventTime());
    notif.setServiceType(event.getServiceType());
    notif.setSubject("notifyid: 1, node down");
    notif.setTextMsg(event.getEventLogMsg());
    m_notificationDao.save(notif);
    vo.m_notifId = notif.getNotifyId();
    OnmsUserNotification userNotif = new OnmsUserNotification();
    userNotif.setAutoNotify("Y");
    userNotif.setContactInfo("me@yourock.com");
    userNotif.setMedia("page");
    userNotif.setNotification(notif);
    userNotif.setNotifyTime(event.getEventTime());
    userNotif.setUserId("me");
    Set<OnmsUserNotification> usersnotifieds = new HashSet<>();
    usersnotifieds.add(userNotif);
    m_userNotificationDao.save(userNotif);
    vo.m_userNotifId = userNotif.getId();
    notif.setUsersNotified(usersnotifieds);
    m_notificationDao.update(notif);
    m_eventDao.update(event);
    m_eventDao.flush();
    return vo;
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsUserNotification(org.opennms.netmgt.model.OnmsUserNotification) OnmsNotification(org.opennms.netmgt.model.OnmsNotification) Date(java.util.Date) HashSet(java.util.HashSet)

Example 7 with OnmsUserNotification

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

the class DefaultAckServiceIT method getUserNotification.

@SuppressWarnings("unused")
private OnmsUserNotification getUserNotification(OnmsNotification notif) {
    OnmsUserNotification un = new OnmsUserNotification();
    un.setUserId("admin");
    un.setNotification(notif);
    Set<OnmsUserNotification> usersNotified = new HashSet<>();
    usersNotified.add(un);
    notif.setUsersNotified(usersNotified);
    m_notifDao.save(notif);
    m_notifDao.flush();
    return un;
}
Also used : OnmsUserNotification(org.opennms.netmgt.model.OnmsUserNotification) HashSet(java.util.HashSet)

Example 8 with OnmsUserNotification

use of org.opennms.netmgt.model.OnmsUserNotification 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<>();
        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;
    }
}
Also used : ArrayList(java.util.ArrayList) OnmsUserNotification(org.opennms.netmgt.model.OnmsUserNotification) OnmsUserNotification(org.opennms.netmgt.model.OnmsUserNotification) OnmsNotification(org.opennms.netmgt.model.OnmsNotification)

Aggregations

OnmsUserNotification (org.opennms.netmgt.model.OnmsUserNotification)8 OnmsNotification (org.opennms.netmgt.model.OnmsNotification)5 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)4 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)4 OnmsNode (org.opennms.netmgt.model.OnmsNode)4 Date (java.util.Date)3 HashSet (java.util.HashSet)2 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)2 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)2 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)2 OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 NetworkBuilder (org.opennms.netmgt.model.NetworkBuilder)1 OnmsAcknowledgment (org.opennms.netmgt.model.OnmsAcknowledgment)1 OnmsCategory (org.opennms.netmgt.model.OnmsCategory)1 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)1 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)1 Transactional (org.springframework.transaction.annotation.Transactional)1