Search in sources :

Example 16 with OnmsNotification

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());
}
Also used : EventBuilder(org.opennms.netmgt.model.events.EventBuilder) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsNotification(org.opennms.netmgt.model.OnmsNotification) Test(org.junit.Test)

Example 17 with OnmsNotification

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;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) Restriction(org.opennms.core.criteria.restrictions.Restriction) Criteria(org.opennms.core.criteria.Criteria) OnmsNotification(org.opennms.netmgt.model.OnmsNotification)

Example 18 with OnmsNotification

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");
}
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 19 with OnmsNotification

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);
    }
}
Also used : OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) OnmsNotification(org.opennms.netmgt.model.OnmsNotification) Transactional(org.springframework.transaction.annotation.Transactional)

Example 20 with OnmsNotification

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

OnmsNotification (org.opennms.netmgt.model.OnmsNotification)20 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)9 Transactional (org.springframework.transaction.annotation.Transactional)7 Test (org.junit.Test)6 OnmsAcknowledgment (org.opennms.netmgt.model.OnmsAcknowledgment)6 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)6 OnmsNode (org.opennms.netmgt.model.OnmsNode)6 OnmsUserNotification (org.opennms.netmgt.model.OnmsUserNotification)6 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 Consumes (javax.ws.rs.Consumes)3 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)3 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)3 PUT (javax.ws.rs.PUT)2 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)2 Acknowledgeable (org.opennms.netmgt.model.Acknowledgeable)2 OnmsOutage (org.opennms.netmgt.model.OnmsOutage)2 OnmsMonitoringLocation (org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1