Search in sources :

Example 6 with OnmsSnmpInterface

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

the class EnLinkdElementFactory method convertFromModel.

@Transactional
@SuppressWarnings("deprecation")
private BridgeLinkNode convertFromModel(int nodeid, SharedSegment segment) {
    final BridgeLinkNode linknode = new BridgeLinkNode();
    for (BridgePort link : segment.getBridgePortsOnSegment()) {
        final Integer rempnodeId = link.getNode().getId();
        final Integer rembridgePortIfIndex = link.getBridgePortIfIndex();
        final OnmsSnmpInterface remiface = rembridgePortIfIndex == null ? null : m_snmpInterfaceDao.findByNodeIdAndIfIndex(rempnodeId, rembridgePortIfIndex);
        if (link.getNode().getId().intValue() == nodeid) {
            if (remiface != null) {
                linknode.setNodeLocalPort(getPortString(rembridgePortIfIndex, remiface.getIfName(), remiface.getIfAlias()));
            } else {
                linknode.setNodeLocalPort(getPortString(rembridgePortIfIndex, null, null));
            }
            linknode.setBridgeLocalVlan(link.getVlan());
            continue;
        }
        final BridgeLinkRemoteNode remlinknode = new BridgeLinkRemoteNode();
        remlinknode.setBridgeRemoteNode(link.getNode().getLabel());
        remlinknode.setBridgeRemoteUrl(getNodeUrl(rempnodeId));
        if (remiface != null) {
            remlinknode.setBridgeRemotePort(getPortString(rembridgePortIfIndex, remiface.getIfName(), remiface.getIfAlias()));
        } else {
            remlinknode.setBridgeRemotePort(getPortString(rembridgePortIfIndex, null, null));
        }
        remlinknode.setBridgeRemotePortUrl(getSnmpInterfaceUrl(rempnodeId, rembridgePortIfIndex));
        remlinknode.setBridgeRemoteVlan(link.getVlan());
        linknode.getBridgeLinkRemoteNodes().add(remlinknode);
    }
    if (segment.getBridgeBridgeLinks().isEmpty()) {
        for (BridgeMacLink link : segment.getBridgeMacLinks()) {
            if (link.getNode().getId().intValue() == nodeid) {
                linknode.setBridgeLinkCreateTime(Util.formatDateToUIString(link.getBridgeMacLinkCreateTime()));
                linknode.setBridgeLinkLastPollTime(Util.formatDateToUIString(link.getBridgeMacLinkLastPollTime()));
                break;
            }
        }
    } else {
        for (BridgeBridgeLink link : segment.getBridgeBridgeLinks()) {
            if (link.getNode().getId().intValue() == nodeid || link.getDesignatedNode().getId().intValue() == nodeid) {
                linknode.setBridgeLinkCreateTime(Util.formatDateToUIString(link.getBridgeBridgeLinkCreateTime()));
                linknode.setBridgeLinkLastPollTime(Util.formatDateToUIString(link.getBridgeBridgeLinkLastPollTime()));
                break;
            }
        }
    }
    Map<String, List<IpNetToMedia>> sharedmacs = new HashMap<String, List<IpNetToMedia>>();
    for (String shredmac : segment.getMacsOnSegment()) {
        sharedmacs.put(shredmac, new ArrayList<IpNetToMedia>());
        sharedmacs.get(shredmac).addAll(m_ipNetToMediaDao.findByPhysAddress(shredmac));
    }
    Map<String, List<OnmsIpInterface>> sharedhosts = new HashMap<String, List<OnmsIpInterface>>();
    for (String shredmac : sharedmacs.keySet()) {
        if (sharedmacs.get(shredmac).isEmpty()) {
            BridgeLinkSharedHost remlinknode = new BridgeLinkSharedHost();
            OnmsSnmpInterface snmp = getFromPhysAddress(shredmac);
            if (snmp == null) {
                remlinknode.setSharedHost(shredmac + " No ip address found");
            } else {
                remlinknode.setSharedHost(snmp.getNode().getLabel());
                remlinknode.setSharedHostUrl(getNodeUrl(snmp.getNode().getId()));
                remlinknode.setSharedHostPort(getPortString(snmp.getIfIndex(), snmp.getIfName(), snmp.getIfAlias()));
                remlinknode.setSharedHostPortUrl(getSnmpInterfaceUrl(snmp.getNode().getId(), snmp.getIfIndex()));
            }
            linknode.getBridgeLinkSharedHost().add(remlinknode);
            continue;
        }
        sharedhosts.put(shredmac, new ArrayList<OnmsIpInterface>());
        for (IpNetToMedia ipnettomedia : sharedmacs.get(shredmac)) sharedhosts.get(shredmac).addAll(m_ipInterfaceDao.findByIpAddress(ipnettomedia.getNetAddress().getHostAddress()));
    }
    for (String shredmac : sharedhosts.keySet()) {
        BridgeLinkSharedHost remlinknode = new BridgeLinkSharedHost();
        Set<InetAddress> ips = new HashSet<InetAddress>();
        if (sharedhosts.get(shredmac).isEmpty()) {
            for (IpNetToMedia ipnettomedia : sharedmacs.get(shredmac)) {
                ips.add(ipnettomedia.getNetAddress());
            }
            remlinknode.setSharedHost(getNodePortString(ips, shredmac) + " No node found");
            linknode.getBridgeLinkSharedHost().add(remlinknode);
            continue;
        }
        OnmsIpInterface first = null;
        boolean multiplenodeids = false;
        for (OnmsIpInterface ip : sharedhosts.get(shredmac)) {
            if (first == null)
                first = ip;
            if (first.getNode().getId().intValue() != ip.getNode().getId().intValue())
                multiplenodeids = true;
            ips.add(ip.getIpAddress());
        }
        if (multiplenodeids) {
            remlinknode.setSharedHost(getNodePortString(ips, shredmac) + " duplicated ip multiple node associated in db");
        } else {
            remlinknode.setSharedHost(first.getNode().getLabel());
            remlinknode.setSharedHostUrl(getNodeUrl(first.getNode().getId()));
        }
        remlinknode.setSharedHostPort(getNodePortString(ips, shredmac));
        if (ips.size() == 1) {
            remlinknode.setSharedHostPortUrl(getIpInterfaceUrl(first));
        }
        linknode.getBridgeLinkSharedHost().add(remlinknode);
    }
    return linknode;
}
Also used : BridgePort(org.opennms.netmgt.model.topology.BridgePort) HashMap(java.util.HashMap) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) IpNetToMedia(org.opennms.netmgt.model.IpNetToMedia) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) BridgeBridgeLink(org.opennms.netmgt.model.BridgeBridgeLink) List(java.util.List) ArrayList(java.util.ArrayList) BridgeMacLink(org.opennms.netmgt.model.BridgeMacLink) InetAddress(java.net.InetAddress) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with OnmsSnmpInterface

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

the class EnLinkdElementFactory method convertFromModel.

@Transactional
@SuppressWarnings("deprecation")
private IsisLinkNode convertFromModel(int nodeid, IsIsLink link) {
    IsisLinkNode linknode = new IsisLinkNode();
    linknode.setIsisCircIfIndex(link.getIsisCircIfIndex());
    linknode.setIsisCircAdminState(IsisAdminState.getTypeString(link.getIsisCircAdminState().getValue()));
    IsIsElement isiselement = m_isisElementDao.findByIsIsSysId(link.getIsisISAdjNeighSysID());
    if (isiselement != null) {
        linknode.setIsisISAdjNeighSysID(getAdjSysIDString(link.getIsisISAdjNeighSysID(), isiselement.getNode().getLabel()));
        linknode.setIsisISAdjUrl(getNodeUrl(isiselement.getNode().getId()));
    } else {
        linknode.setIsisISAdjNeighSysID(link.getIsisISAdjNeighSysID());
    }
    linknode.setIsisISAdjNeighSysType(IsisISAdjNeighSysType.getTypeString(link.getIsisISAdjNeighSysType().getValue()));
    linknode.setIsisISAdjNeighSNPAAddress(link.getIsisISAdjNeighSNPAAddress());
    linknode.setIsisISAdjState(IsisISAdjState.get(link.getIsisISAdjState().getValue()).toString());
    linknode.setIsisISAdjNbrExtendedCircID(link.getIsisISAdjNbrExtendedCircID());
    OnmsSnmpInterface remiface = null;
    if (isiselement != null) {
        IsIsLink adjLink = m_isisLinkDao.get(isiselement.getNode().getId(), link.getIsisISAdjIndex(), link.getIsisCircIndex());
        if (adjLink != null) {
            remiface = m_snmpInterfaceDao.findByNodeIdAndIfIndex(isiselement.getNode().getId(), adjLink.getIsisCircIfIndex());
        }
    }
    if (remiface == null) {
        remiface = getFromPhysAddress(link.getIsisISAdjNeighSNPAAddress());
    }
    if (remiface != null) {
        linknode.setIsisISAdjNeighPort(getPortString(remiface.getIfIndex(), remiface.getIfName(), remiface.getIfAlias()));
        linknode.setIsisISAdjUrl(getSnmpInterfaceUrl(remiface.getNode().getId(), remiface.getIfIndex()));
    } else {
        linknode.setIsisISAdjNeighPort("(Isis IS Adj Index: " + link.getIsisISAdjIndex() + ")");
    }
    linknode.setIsisLinkCreateTime(Util.formatDateToUIString(link.getIsisLinkCreateTime()));
    linknode.setIsisLinkLastPollTime(Util.formatDateToUIString(link.getIsisLinkLastPollTime()));
    return linknode;
}
Also used : IsIsLink(org.opennms.netmgt.model.IsIsLink) IsIsElement(org.opennms.netmgt.model.IsIsElement) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with OnmsSnmpInterface

use of org.opennms.netmgt.model.OnmsSnmpInterface 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 9 with OnmsSnmpInterface

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

the class PollerServiceTest method testPoll.

public void testPoll() throws EventProxyException {
    final int expectedPolldId = 7;
    OnmsServiceType svcType = new OnmsServiceType();
    svcType.setId(3);
    svcType.setName("HTTP");
    OnmsNode node = new OnmsNode();
    node.setId(1);
    OnmsSnmpInterface snmpIface = new OnmsSnmpInterface(node, 1);
    OnmsIpInterface iface = new OnmsIpInterface("192.168.1.1", node);
    iface.setSnmpInterface(snmpIface);
    final OnmsMonitoredService monSvc = new OnmsMonitoredService(iface, svcType);
    m_eventProxy.send(isA(Event.class));
    expectLastCall().andAnswer(new IAnswer<Object>() {

        @Override
        public Object answer() throws Throwable {
            Event event = (Event) getCurrentArguments()[0];
            assertEquals("Incorrect uei for demandPollService event", EventConstants.DEMAND_POLL_SERVICE_EVENT_UEI, event.getUei());
            assertEquals("Incorrect nodeid for demandPollService event", monSvc.getNodeId().longValue(), event.getNodeid().longValue());
            assertEquals("Incorrect ipadr for demandPollService event", InetAddressUtils.str(monSvc.getIpAddress()), event.getInterface());
            assertEquals("Incorrect ifIndex for demandPollService event", monSvc.getIfIndex(), Integer.valueOf(event.getIfIndex()));
            assertEquals("Incorrect service for demandPollService event", monSvc.getServiceType().getName(), event.getService());
            EventUtils.requireParm(event, EventConstants.PARM_DEMAND_POLL_ID);
            assertEquals(expectedPolldId, EventUtils.getIntParm(event, EventConstants.PARM_DEMAND_POLL_ID, -1));
            return null;
        }
    });
    replay(m_eventProxy);
    m_pollerService.poll(monSvc, expectedPolldId);
    verify(m_eventProxy);
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsServiceType(org.opennms.netmgt.model.OnmsServiceType) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) Event(org.opennms.netmgt.xml.event.Event) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 10 with OnmsSnmpInterface

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

the class InterfaceToNodeCacheDaoImplIT method setUp.

@Before
public void setUp() throws Exception {
    m_databasePopulator.populateDatabase();
    m_cache.dataSourceSync();
    OnmsNode n = new OnmsNode(m_databasePopulator.getMonitoringLocationDao().getDefaultLocation(), "my-new-node");
    n.setForeignSource("junit");
    n.setForeignId("10001");
    OnmsIpInterface iface = new OnmsIpInterface(InetAddress.getByName("192.168.1.3"), n);
    iface.setIsManaged("M");
    iface.setIsSnmpPrimary(PrimaryType.PRIMARY);
    OnmsSnmpInterface snmpIf = new OnmsSnmpInterface(n, 1001);
    iface.setSnmpInterface(snmpIf);
    snmpIf.getIpInterfaces().add(iface);
    n.addIpInterface(iface);
    m_databasePopulator.getNodeDao().save(n);
    m_testNodeId = n.getId();
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) Before(org.junit.Before)

Aggregations

OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)73 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)39 OnmsNode (org.opennms.netmgt.model.OnmsNode)38 Test (org.junit.Test)17 InetAddress (java.net.InetAddress)16 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)10 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)9 OnmsEvent (org.opennms.netmgt.model.OnmsEvent)9 Transactional (org.springframework.transaction.annotation.Transactional)9 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 OnmsEventParameter (org.opennms.netmgt.model.OnmsEventParameter)8 LinkedHashSet (java.util.LinkedHashSet)5 LinkedList (java.util.LinkedList)5 HashSet (java.util.HashSet)4 List (java.util.List)4 Before (org.junit.Before)4 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)4 IpNetToMedia (org.opennms.netmgt.model.IpNetToMedia)4 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)4