Search in sources :

Example 56 with OnmsSnmpInterface

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

the class SnmpCollectorITCase method createAgent.

protected void createAgent(int ifIndex, PrimaryType ifCollType) {
    m_node = new OnmsNode();
    m_node.setSysObjectId(".1.2.3.4.5.6.7");
    OnmsSnmpInterface snmpIface = new OnmsSnmpInterface(m_node, ifIndex);
    m_iface = new OnmsIpInterface();
    m_iface.setId(123);
    m_iface.setIpAddress(myLocalHost());
    m_iface.setIsSnmpPrimary(ifCollType);
    m_iface.setSnmpInterface(snmpIface);
    m_node.addIpInterface(m_iface);
    EasyMock.expect(m_ifaceDao.load(m_iface.getId())).andReturn(m_iface).anyTimes();
    m_easyMockUtils.replayAll();
    m_agent = DefaultSnmpCollectionAgent.create(m_iface.getId(), m_ifaceDao, new MockPlatformTransactionManager());
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) MockPlatformTransactionManager(org.opennms.core.test.MockPlatformTransactionManager)

Example 57 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 58 with OnmsSnmpInterface

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

the class DefaultSnmpCollectionAgentService method getSnmpInterfaces.

private Set<OnmsSnmpInterface> getSnmpInterfaces() {
    OnmsNode node = getNode();
    Set<OnmsSnmpInterface> snmpIfs = node.getSnmpInterfaces();
    if (snmpIfs.size() == 0) {
        LOG.debug("no known SNMP interfaces for node {}", node);
    }
    return snmpIfs;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface)

Example 59 with OnmsSnmpInterface

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

the class InsAbstractSession method getIfAlias.

/**
 * @param nodeid
 * @param ifindex
 * @return
 */
protected String getIfAlias(final int nodeid, final int ifindex) {
    LOG.debug("getting ifalias for nodeid: {} and ifindex: {}", nodeid, ifindex);
    setCriteria("nodeid = " + nodeid + " AND snmpifindex = " + ifindex);
    BeanFactoryReference bf = BeanUtils.getBeanFactory("daoContext");
    final SnmpInterfaceDao snmpInterfaceDao = BeanUtils.getBean(bf, "snmpInterfaceDao", SnmpInterfaceDao.class);
    final TransactionTemplate transTemplate = BeanUtils.getBean(bf, "transactionTemplate", TransactionTemplate.class);
    final OnmsSnmpInterface iface = transTemplate.execute(new TransactionCallback<OnmsSnmpInterface>() {

        public OnmsSnmpInterface doInTransaction(final TransactionStatus status) {
            return snmpInterfaceDao.findByNodeIdAndIfIndex(nodeid, ifindex);
        }
    });
    if (iface == null) {
        return "-1";
    } else {
        final String ifAlias = iface.getIfAlias();
        LOG.debug("ifalias found: {}", ifAlias);
        return ifAlias;
    }
}
Also used : BeanFactoryReference(org.springframework.beans.factory.access.BeanFactoryReference) SnmpInterfaceDao(org.opennms.netmgt.dao.api.SnmpInterfaceDao) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) TransactionStatus(org.springframework.transaction.TransactionStatus)

Example 60 with OnmsSnmpInterface

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

the class OnmsSnmpInterfaceResource method getSnmpInterface.

/**
 * <p>getSnmpInterface</p>
 *
 * @param nodeCriteria a {@link java.lang.String} object.
 * @param ifIndex a int.
 * @return a {@link org.opennms.netmgt.model.OnmsSnmpInterface} object.
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("{ifIndex}")
public OnmsSnmpInterface getSnmpInterface(@PathParam("nodeCriteria") final String nodeCriteria, @PathParam("ifIndex") final int ifIndex) {
    final OnmsNode node = m_nodeDao.get(nodeCriteria);
    if (node == null) {
        throw getException(Status.BAD_REQUEST, "Node {} was not found.", nodeCriteria);
    }
    final OnmsSnmpInterface iface = node.getSnmpInterfaceWithIfIndex(ifIndex);
    if (iface == null) {
        throw getException(Status.NOT_FOUND, "SNMP Interface {} was not found on node {}.", Integer.toString(ifIndex), nodeCriteria);
    }
    return iface;
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

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