Search in sources :

Example 61 with OnmsSnmpInterface

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

the class NodeDaoHibernate method getHierarchy.

/** {@inheritDoc} */
@Override
public OnmsNode getHierarchy(Integer id) {
    OnmsNode node = findUnique("select distinct n from OnmsNode as n " + "left join fetch n.assetRecord " + "where n.id = ?", id);
    initialize(node.getIpInterfaces());
    for (OnmsIpInterface i : node.getIpInterfaces()) {
        initialize(i.getMonitoredServices());
    }
    initialize(node.getSnmpInterfaces());
    for (OnmsSnmpInterface i : node.getSnmpInterfaces()) {
        initialize(i.getIpInterfaces());
    }
    return node;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface)

Example 62 with OnmsSnmpInterface

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

the class PollableSnmpInterface method setSnmpinterfaces.

/**
     * <p>setSnmpinterfaces</p>
     *
     * @param snmpinterfaces a {@link java.util.List} object.
     */
public void setSnmpinterfaces(List<OnmsSnmpInterface> snmpinterfaces) {
    if (snmpinterfaces == null) {
        LOG.debug("setting snmpinterfaces: got null, thread instantiated but at moment no interface found");
        return;
    }
    // ifIndex -> operstatus
    final Map<Integer, Integer> oldStatuses = new HashMap<Integer, Integer>();
    for (final Integer ifIndex : m_snmpinterfaces.keySet()) {
        final OnmsSnmpInterface iface = m_snmpinterfaces.get(ifIndex);
        if (iface != null && iface.getIfOperStatus() != null) {
            oldStatuses.put(ifIndex, iface.getIfOperStatus());
        }
    }
    m_snmpinterfaces.clear();
    for (OnmsSnmpInterface iface : snmpinterfaces) {
        LOG.debug("setting snmpinterface:", iface.toString());
        if (iface != null && iface.getIfIndex() != null && iface.getIfIndex() > 0) {
            final Integer oldStatus = oldStatuses.get(iface.getIfIndex());
            LOG.debug("setting snmpinterface (oldStatus={}):{}", oldStatus, iface.toString());
            // Note: If OpenNMS is restarted, the event is going to be sent no matter if it was sent before, if the current status of the interface is down.        
            m_snmpinterfaces.put(iface.getIfIndex(), iface);
            if (iface.getIfAdminStatus() != null && iface.getIfAdminStatus().equals(SnmpMinimalPollInterface.IF_UP) && iface.getIfOperStatus() != null && iface.getIfOperStatus().equals(SnmpMinimalPollInterface.IF_DOWN) && (oldStatus == null || (iface.getIfOperStatus().intValue() != oldStatus.intValue()))) {
                sendOperDownEvent(iface);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface)

Example 63 with OnmsSnmpInterface

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

the class EnLinkdElementFactory method getFromCdpCacheDevicePort.

private OnmsSnmpInterface getFromCdpCacheDevicePort(Integer nodeid, String cdpCacheDevicePort) {
    final CriteriaBuilder builder = new CriteriaBuilder(OnmsSnmpInterface.class);
    builder.alias("node", "node", JoinType.LEFT_JOIN);
    builder.sql("snmpifalias = '" + cdpCacheDevicePort + "' OR snmpifname = '" + cdpCacheDevicePort + "' OR snmpifdescr = '" + cdpCacheDevicePort + "'").eq("node.id", nodeid);
    final List<OnmsSnmpInterface> nodes = m_snmpInterfaceDao.findMatching(builder.toCriteria());
    if (nodes.size() == 1)
        return nodes.get(0);
    return null;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface)

Example 64 with OnmsSnmpInterface

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

the class EnLinkdElementFactory method convertFromModel.

@Transactional
@SuppressWarnings("deprecation")
private CdpLinkNode convertFromModel(int nodeid, CdpLink link) {
    CdpLinkNode linknode = new CdpLinkNode();
    linknode.setCdpLocalPort(getPortString(link.getCdpCacheIfIndex(), link.getCdpInterfaceName(), null));
    if (link.getCdpCacheIfIndex() != null)
        linknode.setCdpLocalPortUrl(getSnmpInterfaceUrl(nodeid, link.getCdpCacheIfIndex()));
    linknode.setCdpCacheAddressType(CiscoNetworkProtocolType.getTypeString(link.getCdpCacheAddressType().getValue()));
    linknode.setCdpCacheAddress(link.getCdpCacheAddress());
    linknode.setCdpCacheDeviceId(link.getCdpCacheDeviceId());
    linknode.setCdpCacheDevicePlatform(link.getCdpCacheDevicePlatform());
    linknode.setCdpCacheVersion(link.getCdpCacheVersion());
    linknode.setCdpCacheDevicePort(link.getCdpCacheDevicePort());
    CdpElement cdpCacheElement = m_cdpElementDao.findByGlobalDeviceId(link.getCdpCacheDeviceId());
    if (cdpCacheElement != null) {
        linknode.setCdpCacheDeviceUrl(getNodeUrl(cdpCacheElement.getNode().getId()));
        OnmsSnmpInterface cdpcachesnmp = getFromCdpCacheDevicePort(cdpCacheElement.getNode().getId(), link.getCdpCacheDevicePort());
        if (cdpcachesnmp != null) {
            linknode.setCdpCacheDevicePort(getPortString(cdpcachesnmp.getIfIndex(), link.getCdpCacheDevicePort(), cdpcachesnmp.getIfAlias()));
            linknode.setCdpCacheDevicePortUrl(getSnmpInterfaceUrl(cdpCacheElement.getNode().getId(), cdpcachesnmp.getIfIndex()));
        }
    }
    linknode.setCdpCreateTime(Util.formatDateToUIString(link.getCdpLinkCreateTime()));
    linknode.setCdpLastPollTime(Util.formatDateToUIString(link.getCdpLinkLastPollTime()));
    return linknode;
}
Also used : OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) CdpElement(org.opennms.netmgt.model.CdpElement) Transactional(org.springframework.transaction.annotation.Transactional)

Example 65 with OnmsSnmpInterface

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

the class EnLinkdElementFactory method getFromPhysAddress.

private OnmsSnmpInterface getFromPhysAddress(String physAddress) {
    final CriteriaBuilder builder = new CriteriaBuilder(OnmsSnmpInterface.class);
    builder.eq("physAddr", physAddress);
    final List<OnmsSnmpInterface> nodes = m_snmpInterfaceDao.findMatching(builder.toCriteria());
    if (nodes.size() == 1)
        return nodes.get(0);
    return null;
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface)

Aggregations

OnmsSnmpInterface (org.opennms.netmgt.model.OnmsSnmpInterface)65 OnmsIpInterface (org.opennms.netmgt.model.OnmsIpInterface)34 OnmsNode (org.opennms.netmgt.model.OnmsNode)30 Test (org.junit.Test)14 InetAddress (java.net.InetAddress)12 OnmsAlarm (org.opennms.netmgt.model.OnmsAlarm)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 NorthboundAlarm (org.opennms.netmgt.alarmd.api.NorthboundAlarm)7 Transactional (org.springframework.transaction.annotation.Transactional)6 LinkedList (java.util.LinkedList)5 LinkedHashSet (java.util.LinkedHashSet)4 CriteriaBuilder (org.opennms.core.criteria.CriteriaBuilder)4 OnmsMonitoredService (org.opennms.netmgt.model.OnmsMonitoredService)4 OnmsServiceType (org.opennms.netmgt.model.OnmsServiceType)4 HashSet (java.util.HashSet)3 List (java.util.List)3 Before (org.junit.Before)3 IpNetToMedia (org.opennms.netmgt.model.IpNetToMedia)3 BufferedReader (java.io.BufferedReader)2