Search in sources :

Example 26 with OnmsIpInterface

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

the class NodeDaoIT method simulateScan.

private void simulateScan(Date timestamp) {
    OnmsNode n = getNodeDao().get(getNode1().getId());
    assertEquals(4, n.getIpInterfaces().size());
    assertEquals(4, n.getSnmpInterfaces().size());
    OnmsIpInterface iface = n.getIpInterfaceByIpAddress("192.168.1.1");
    assertNotNull(iface);
    iface.setIpLastCapsdPoll(timestamp);
    OnmsSnmpInterface snmpIface = n.getSnmpInterfaceWithIfIndex(1);
    assertNotNull(snmpIface);
    snmpIface.setLastCapsdPoll(timestamp);
    getNodeDao().saveOrUpdate(n);
    getNodeDao().flush();
}
Also used : OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface)

Example 27 with OnmsIpInterface

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

the class NodeDaoIT method validateNode.

private void validateNode(OnmsNode n) throws Exception {
    assertNotNull("Expected node to be non-null", n);
    assertNotNull("Expected location to be non-null", n.getLocation());
    assertNotNull("Expected node " + n.getId() + " to have interfaces", n.getIpInterfaces());
    assertEquals("Unexpected number of interfaces for node " + n.getId(), 4, n.getIpInterfaces().size());
    for (Object o : n.getIpInterfaces()) {
        OnmsIpInterface iface = (OnmsIpInterface) o;
        assertNotNull(iface);
        assertNotNull(InetAddressUtils.str(iface.getIpAddress()));
    }
    assertNodeEquals(getNode1(), n);
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface)

Example 28 with OnmsIpInterface

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

the class IpInterfaceDaoIT method testGetIPv6Interfaces.

@Test
@Transactional
public void testGetIPv6Interfaces() {
    if (Boolean.getBoolean("skipIpv6Tests")) {
        return;
    }
    OnmsCriteria crit = new OnmsCriteria(OnmsIpInterface.class);
    crit.add(Restrictions.like("ipAddress", "fe80:%dddd\\%5"));
    List<OnmsIpInterface> ifaces = m_ipInterfaceDao.findMatching(crit);
    assertEquals(1, ifaces.size());
    OnmsIpInterface iface = ifaces.get(0);
    assertTrue(iface.getIpAddress() instanceof Inet6Address);
    Inet6Address v6address = (Inet6Address) iface.getIpAddress();
    assertEquals(5, v6address.getScopeId());
    assertEquals("fe80:0000:0000:0000:aaaa:bbbb:cccc:dddd%5", InetAddressUtils.str(iface.getIpAddress()));
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsCriteria(org.opennms.netmgt.model.OnmsCriteria) Inet6Address(java.net.Inet6Address) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 29 with OnmsIpInterface

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

the class NetworkElementFactory method getInterfaceForLink.

private Interface getInterfaceForLink(int nodeid, int ifindex) {
    Interface iface = null;
    if (ifindex > 0) {
        iface = getSnmpInterface(nodeid, ifindex);
        final org.opennms.core.criteria.Criteria criteria = new org.opennms.core.criteria.Criteria(OnmsIpInterface.class).setAliases(Arrays.asList(new Alias[] { new Alias("node", "node", JoinType.LEFT_JOIN), new Alias("snmpInterface", "snmpInterface", JoinType.LEFT_JOIN) })).addRestriction(new EqRestriction("node.id", nodeid)).addRestriction(new EqRestriction("snmpInterface.ifIndex", ifindex));
        List<String> addresses = new ArrayList<String>();
        for (OnmsIpInterface onmsIpInterface : m_ipInterfaceDao.findMatching(criteria)) {
            addresses.add(onmsIpInterface.getIpAddress().getHostAddress());
        }
        if (addresses.size() > 0) {
            if (iface == null) {
                iface = new Interface();
                iface.m_nodeId = nodeid;
                iface.m_ifIndex = ifindex;
            }
            iface.setIpaddresses(addresses);
        } else {
            if (iface != null) {
                iface.setIpaddresses(addresses);
            }
        }
    }
    return iface;
}
Also used : OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) Alias(org.opennms.core.criteria.Alias) EqRestriction(org.opennms.core.criteria.restrictions.EqRestriction) ArrayList(java.util.ArrayList) OnmsSnmpInterface(org.opennms.netmgt.model.OnmsSnmpInterface) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface)

Example 30 with OnmsIpInterface

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

the class EventdIT method testPersistEventWithService.

/**
 * Test that eventd's service ID lookup works properly.
 */
@Test(timeout = 30000)
public void testPersistEventWithService() throws Exception {
    CriteriaBuilder cb = new CriteriaBuilder(OnmsEvent.class);
    cb.eq("eventUei", EventConstants.SERVICE_UNRESPONSIVE_EVENT_UEI);
    assertEquals(0, m_eventDao.countMatching(cb.toCriteria()));
    assertNotNull(m_serviceTypeDao.findByName("ICMP"));
    OnmsNode node = m_databasePopulator.getNode1();
    assertNotNull(node);
    OnmsIpInterface intf = node.getIpInterfaceByIpAddress("192.168.1.1");
    assertNotNull(intf);
    System.err.println("services = " + intf.getMonitoredServices());
    OnmsMonitoredService svc = intf.getMonitoredServiceByServiceType("ICMP");
    assertNotNull(svc);
    assertEquals("192.168.1.1", str(svc.getIpAddress()));
    final Integer serviceId = svc.getServiceId();
    sendServiceDownEvent(null, svc);
    while (m_eventDao.countMatching(cb.toCriteria()) != 1) {
        Thread.sleep(SLEEP_TIME);
    }
    assertEquals(1, m_eventDao.countMatching(cb.toCriteria()));
    assertEquals("service ID for event", serviceId, m_eventDao.findMatching(cb.toCriteria()).get(0).getServiceType().getId());
}
Also used : CriteriaBuilder(org.opennms.core.criteria.CriteriaBuilder) OnmsNode(org.opennms.netmgt.model.OnmsNode) OnmsIpInterface(org.opennms.netmgt.model.OnmsIpInterface) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService) Test(org.junit.Test)

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