Search in sources :

Example 46 with OnmsIpInterface

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

the class NotificationDaoIT method testNotificationSave.

@Test
@Transactional
public void testNotificationSave() {
    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/NotificationDaoTest");
    // OnmsAlarm alarm = new OnmsAlarm();
    // event.setAlarm(alarm);
    OnmsNode node = m_nodeDao.findAll().iterator().next();
    OnmsIpInterface iface = node.getIpInterfaces().iterator().next();
    OnmsMonitoredService service = 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/NotificationDaoTest", 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/NotificationDaoTest", newNotification.getEvent().getEventUei());
}
Also used : OnmsEvent(org.opennms.netmgt.model.OnmsEvent) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) 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 47 with OnmsIpInterface

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

the class MockNodeDao method updateSubObjects.

private void updateSubObjects(final OnmsNode node) {
    node.getAssetRecord().setNode(node);
    getAssetRecordDao().saveOrUpdate(node.getAssetRecord());
    for (final OnmsCategory cat : node.getCategories()) {
        getCategoryDao().saveOrUpdate(cat);
    }
    /* not sure if this is necessary */
    /*
        getMonitoringLocationDao().saveOrUpdate(node.getLocation());
        */
    /**
     * delete any interfaces that were removed compared to the database *
     */
    final OnmsNode dbNode = node.getId() == null ? null : get(node.getId());
    if (dbNode != null) {
        for (final OnmsSnmpInterface iface : dbNode.getSnmpInterfaces()) {
            if (!node.getSnmpInterfaces().contains(iface)) {
                getSnmpInterfaceDao().delete(iface);
            }
        }
        for (final OnmsIpInterface iface : dbNode.getIpInterfaces()) {
            if (!node.getIpInterfaces().contains(iface)) {
                getIpInterfaceDao().delete(iface);
            }
        }
    }
    for (final OnmsSnmpInterface iface : node.getSnmpInterfaces()) {
        iface.setNode(node);
        getSnmpInterfaceDao().saveOrUpdate(iface);
    }
    for (final OnmsIpInterface iface : node.getIpInterfaces()) {
        iface.setNode(node);
        getIpInterfaceDao().saveOrUpdate(iface);
    }
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsCategory(org.opennms.netmgt.model.OnmsCategory) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface)

Example 48 with OnmsIpInterface

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

the class IpInterfaceDaoHibernate method findPrimaryInterfaceByNodeId.

/**
 * This function should be kept similar to {@link OnmsNode#getPrimaryInterface()}.
 */
@Override
public OnmsIpInterface findPrimaryInterfaceByNodeId(final Integer nodeId) {
    Assert.notNull(nodeId, "nodeId cannot be null");
    // SELECT ipaddr FROM ipinterface WHERE nodeid = ? AND issnmpprimary = 'P'
    List<OnmsIpInterface> primaryInterfaces = find("from OnmsIpInterface as ipInterface where ipInterface.node.id = ? and ipInterface.isSnmpPrimary = 'P' order by ipLastCapsdPoll desc", nodeId);
    if (primaryInterfaces.size() < 1) {
        return null;
    } else {
        OnmsIpInterface retval = primaryInterfaces.iterator().next();
        if (primaryInterfaces.size() > 1) {
            LOG.warn("Multiple primary SNMP interfaces for node {}, returning most recently scanned interface: {}", nodeId, retval.getInterfaceId());
        }
        return retval;
    }
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface)

Example 49 with OnmsIpInterface

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

the class LocationMonitorDaoHibernate method findStatusChangesForNodeForUniqueMonitorAndInterface.

/**
 * {@inheritDoc}
 */
@Override
public Collection<LocationMonitorIpInterface> findStatusChangesForNodeForUniqueMonitorAndInterface(final int nodeId) {
    @SuppressWarnings("unchecked") final List<Object[]> l = (List<Object[]>) getHibernateTemplate().find("select distinct status.locationMonitor, status.monitoredService.ipInterface from OnmsLocationSpecificStatus as status " + "where status.monitoredService.ipInterface.node.id = ?", nodeId);
    final HashSet<LocationMonitorIpInterface> ret = new HashSet<>();
    for (Object[] tuple : l) {
        OnmsLocationMonitor mon = (OnmsLocationMonitor) tuple[0];
        OnmsIpInterface ip = (OnmsIpInterface) tuple[1];
        ret.add(new LocationMonitorIpInterface(mon, ip));
    }
    return ret;
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) List(java.util.List) LocationMonitorIpInterface(org.opennms.netmgt.model.LocationMonitorIpInterface) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor) HashSet(java.util.HashSet)

Example 50 with OnmsIpInterface

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

the class DistributedStatusResourceType method getResourcesForParent.

/**
 * {@inheritDoc}
 */
@Override
public List<OnmsResource> getResourcesForParent(OnmsResource parent) {
    if (!NodeResourceType.isNode(parent)) {
        return Collections.emptyList();
    }
    final OnmsNode node = ResourceTypeUtils.getNodeFromResource(parent);
    final List<OnmsResource> resources = Lists.newLinkedList();
    final Collection<LocationMonitorIpInterface> statuses = m_locationMonitorDao.findStatusChangesForNodeForUniqueMonitorAndInterface(node.getId());
    for (LocationMonitorIpInterface status : statuses) {
        String definitionName = status.getLocationMonitor().getLocation();
        String id = status.getLocationMonitor().getId();
        final OnmsIpInterface ipInterface = status.getIpInterface();
        String ipAddr = InetAddressUtils.str(ipInterface.getIpAddress());
        if (m_resourceStorageDao.exists(getRelativeInterfacePath(id, ipAddr), 0)) {
            resources.add(createResource(definitionName, id, ipAddr));
        }
    }
    return OnmsResource.sortIntoResourceList(resources);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsResource(org.opennms.netmgt.model.OnmsResource) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) LocationMonitorIpInterface(org.opennms.netmgt.model.LocationMonitorIpInterface)

Aggregations

OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)186 OnmsNode (org.opennms.netmgt.model.OnmsNode)117 Test (org.junit.Test)53 OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)43 InetAddress (java.net.InetAddress)40 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)33 Transactional (org.springframework.transaction.annotation.Transactional)30 ArrayList (java.util.ArrayList)22 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)21 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)20 Date (java.util.Date)17 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)17 File (java.io.File)16 HashMap (java.util.HashMap)15 Before (org.junit.Before)15 LinkedList (java.util.LinkedList)14 IpInterfaceDao (org.opennms.netmgt.dao.api.IpInterfaceDao)14 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)12 OnmsEventParameter (org.opennms.netmgt.model.OnmsEventParameter)12 OnmsResource (org.opennms.netmgt.model.OnmsResource)11