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();
}
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);
}
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()));
}
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;
}
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());
}
Aggregations