Search in sources :

Example 11 with OnmsNotification

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

the class DatabasePopulator method buildTestNotification.

private OnmsNotification buildTestNotification(final NetworkBuilder builder, final OnmsEvent event) {
    final OnmsNotification notif = new OnmsNotification();
    notif.setEvent(event);
    notif.setTextMsg("This is a test notification");
    notif.setIpAddress(InetAddressUtils.getInetAddress("192.168.1.1"));
    notif.setNode(m_node1);
    notif.setServiceType(getService("ICMP"));
    return notif;
}
Also used : OnmsNotification(org.opennms.netmgt.model.OnmsNotification)

Example 12 with OnmsNotification

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

the class DatabasePopulator method doResetDatabase.

private void doResetDatabase() {
    LOG.debug("==== DatabasePopulator Reset ====");
    for (final OnmsOutage outage : m_outageDao.findAll()) {
        m_outageDao.delete(outage);
    }
    for (final OnmsUserNotification not : m_userNotificationDao.findAll()) {
        m_userNotificationDao.delete(not);
    }
    for (final OnmsNotification not : m_notificationDao.findAll()) {
        m_notificationDao.delete(not);
    }
    for (final OnmsAlarm alarm : m_alarmDao.findAll()) {
        m_alarmDao.delete(alarm);
    }
    for (final OnmsEvent event : m_eventDao.findAll()) {
        m_eventDao.delete(event);
    }
    for (final OnmsSnmpInterface snmpIface : m_snmpInterfaceDao.findAll()) {
        for (OnmsIpInterface eachIf : snmpIface.getIpInterfaces()) {
            eachIf.setSnmpInterface(null);
            snmpIface.getNode().getIpInterfaces().remove(eachIf);
        }
        snmpIface.getNode().getSnmpInterfaces().remove(snmpIface);
        m_snmpInterfaceDao.delete(snmpIface);
    }
    for (final OnmsIpInterface iface : m_ipInterfaceDao.findAll()) {
        iface.setSnmpInterface(null);
        iface.getNode().getIpInterfaces().remove(iface);
        m_ipInterfaceDao.delete(iface);
    }
    for (final OnmsNode node : m_nodeDao.findAll()) {
        m_nodeDao.delete(node);
    }
    for (final OnmsServiceType service : m_serviceTypeDao.findAll()) {
        m_serviceTypeDao.delete(service);
    }
    for (final OnmsMonitoringLocation location : m_monitoringLocationDao.findAll()) {
        // Don't delete the default localhost monitoring location
        if (!MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID.equals(location.getLocationName())) {
            m_monitoringLocationDao.delete(location);
        }
    }
    for (final OnmsCategory category : m_categoryDao.findAll()) {
        m_categoryDao.delete(category);
    }
    LOG.debug("= DatabasePopulatorExtension Reset Starting =");
    for (Extension eachExtension : extensions) {
        DaoSupport daoSupport = eachExtension.getDaoSupport();
        OnmsDao<?, ?> dao = daoSupport != null && daoSupport.getDaoClass() != null ? lookupDao(daoSupport.getDaoClass()) : null;
        eachExtension.onShutdown(this, dao);
        if (dao != null) {
            dao.flush();
        }
    }
    LOG.debug("= DatabasePopulatorExtension Reset Finished =");
    m_outageDao.flush();
    m_userNotificationDao.flush();
    m_notificationDao.flush();
    m_alarmDao.flush();
    m_eventDao.flush();
    m_snmpInterfaceDao.flush();
    m_ipInterfaceDao.flush();
    m_nodeDao.flush();
    m_serviceTypeDao.flush();
    LOG.debug("==== DatabasePopulator Reset Finished ====");
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) OnmsUserNotification(org.opennms.netmgt.model.OnmsUserNotification) OnmsNotification(org.opennms.netmgt.model.OnmsNotification) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)

Example 13 with OnmsNotification

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

the class DatabasePopulator method doPopulateDatabase.

private void doPopulateDatabase() {
    LOG.debug("==== DatabasePopulator Starting ====");
    final NetworkBuilder builder = new NetworkBuilder();
    final OnmsNode node1 = buildNode1(builder);
    getNodeDao().save(node1);
    getNodeDao().flush();
    OnmsNode node2 = buildNode2(builder);
    getNodeDao().save(node2);
    getNodeDao().flush();
    setNode2(node2);
    OnmsNode node3 = buildNode3(builder);
    getNodeDao().save(node3);
    getNodeDao().flush();
    setNode3(node3);
    OnmsNode node4 = buildNode4(builder);
    getNodeDao().save(node4);
    getNodeDao().flush();
    setNode4(node4);
    OnmsNode node5 = buildNode5(builder);
    getNodeDao().save(node5);
    getNodeDao().flush();
    setNode5(node5);
    OnmsNode node6 = buildNode6(builder);
    getNodeDao().save(node6);
    getNodeDao().flush();
    setNode6(node6);
    final OnmsEvent event = buildEvent(builder.getDistPoller());
    event.setEventCreateTime(new Date(1436881548292L));
    event.setEventTime(new Date(1436881548292L));
    getEventDao().save(event);
    getEventDao().flush();
    final OnmsNotification notif = buildTestNotification(builder, event);
    getNotificationDao().save(notif);
    getNotificationDao().flush();
    final OnmsUserNotification userNotif = buildTestUserNotification(notif);
    getUserNotificationDao().save(userNotif);
    getUserNotificationDao().flush();
    final OnmsUserNotification userNotif2 = buildTestUser2Notification(notif);
    getUserNotificationDao().save(userNotif2);
    getUserNotificationDao().flush();
    final OnmsMonitoredService svc = getMonitoredServiceDao().get(node1.getId(), InetAddressUtils.addr("192.168.1.1"), "SNMP");
    final OnmsOutage resolved = new OnmsOutage(new Date(1436881548292L), new Date(1436881548292L), event, event, svc, null, null);
    getOutageDao().save(resolved);
    getOutageDao().flush();
    final OnmsOutage unresolved = new OnmsOutage(new Date(1436881548292L), event, svc);
    getOutageDao().save(unresolved);
    getOutageDao().flush();
    final OnmsAlarm alarm = buildAlarm(event);
    getAlarmDao().save(alarm);
    getAlarmDao().flush();
    final OnmsAcknowledgment ack = new OnmsAcknowledgment();
    ack.setAckTime(new Date(1437073152156L));
    ack.setAckType(AckType.UNSPECIFIED);
    ack.setAckAction(AckAction.UNSPECIFIED);
    ack.setAckUser("admin");
    getAcknowledgmentDao().save(ack);
    getAcknowledgmentDao().flush();
    final OnmsMonitoringLocation def = new OnmsMonitoringLocation();
    def.setLocationName("RDU");
    def.setMonitoringArea("East Coast");
    def.setPollingPackageNames(Collections.singletonList("example1"));
    def.setCollectionPackageNames(Collections.singletonList("example1"));
    def.setGeolocation("Research Triangle Park, NC");
    def.setLatitude(35.715751f);
    def.setLongitude(-79.16262f);
    def.setPriority(1L);
    def.setTags(Collections.singletonList("blah"));
    m_monitoringLocationDao.save(def);
    LOG.debug("= DatabasePopulatorExtension Populate Starting =");
    for (Extension eachExtension : extensions) {
        DaoSupport daoSupport = eachExtension.getDaoSupport();
        OnmsDao<?, ?> dao = daoSupport != null ? daoSupport.getDao() : null;
        Class<? super OnmsDao<?, ?>> daoClass = daoSupport != null ? daoSupport.getDaoClass() : null;
        registerDao(daoClass, dao);
        dao = lookupDao(daoClass);
        eachExtension.onPopulate(this, dao);
        if (dao != null) {
            dao.flush();
        }
    }
    LOG.debug("= DatabasePopulatorExtension Populate Finished =");
    LOG.debug("==== DatabasePopulator Finished ====");
}
Also used : OnmsOutage(org.opennms.netmgt.model.OnmsOutage) OnmsAcknowledgment(org.opennms.netmgt.model.OnmsAcknowledgment) 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) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) OnmsEvent(org.opennms.netmgt.model.OnmsEvent) NetworkBuilder(org.opennms.netmgt.model.NetworkBuilder) OnmsMonitoringLocation(org.opennms.netmgt.model.monitoringLocations.OnmsMonitoringLocation)

Example 14 with OnmsNotification

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

the class AcknowledgmentDaoHibernate method findAcknowledgables.

/** {@inheritDoc} */
@Override
public List<Acknowledgeable> findAcknowledgables(final OnmsAcknowledgment ack) {
    List<Acknowledgeable> ackables = new ArrayList<Acknowledgeable>();
    if (ack == null || ack.getAckType() == null) {
        return ackables;
    }
    if (ack.getAckType().equals(AckType.ALARM)) {
        final OnmsAlarm alarm = findAlarm(ack);
        try {
            if (alarm != null && alarm.getAckId() != null) {
                ackables.add(alarm);
                List<OnmsNotification> notifs = findRelatedNotifications(alarm);
                if (notifs != null) {
                    for (OnmsNotification notif : notifs) {
                        try {
                            if (notif.getAckId() != null) {
                                ackables.add(notif);
                            }
                        } catch (final ObjectNotFoundException e) {
                            LOG.warn("found ackables for alarm #{} but ackable was invalid", ack.getRefId(), e);
                        }
                    }
                }
            }
        } catch (final ObjectNotFoundException e) {
            LOG.warn("unable to find alarm with ID {}", ack.getRefId(), e);
        }
    } else if (ack.getAckType().equals(AckType.NOTIFICATION)) {
        final OnmsNotification notif = findNotification(ack);
        try {
            if (notif != null && notif.getAckId() != null) {
                ackables.add(notif);
                try {
                    if (notif.getEvent() != null) {
                        final OnmsAlarm alarm = notif.getEvent().getAlarm();
                        if (alarm != null) {
                            ackables.add(alarm);
                        }
                    }
                } catch (final ObjectNotFoundException e) {
                    LOG.warn("unable to find alarm for notification #{}", notif.getNotifyId(), e);
                }
            }
        } catch (final ObjectNotFoundException e) {
            LOG.warn("unable to find notification with ID {}", ack.getRefId(), e);
        }
    }
    return ackables;
}
Also used : Acknowledgeable(org.opennms.netmgt.model.Acknowledgeable) OnmsAlarm(org.opennms.netmgt.model.OnmsAlarm) ObjectNotFoundException(org.hibernate.ObjectNotFoundException) ArrayList(java.util.ArrayList) OnmsNotification(org.opennms.netmgt.model.OnmsNotification)

Example 15 with OnmsNotification

use of org.opennms.netmgt.model.OnmsNotification 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(6);
    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(1);
    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<OnmsUserNotification>();
    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)

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