@Override public Set<OnmsIpInterface> unmarshal(final ArrayList<Integer> ids) throws Exception { final Set<OnmsIpInterface> ret = new TreeSet<>(); for (final Integer id : ids) { final OnmsIpInterface iface = new OnmsIpInterface(); iface.setId(id); ret.add(iface); } return ret; }
public InterfaceBuilder addInterface(final InetAddress ipAddr) { m_currentIf = new OnmsIpInterface(ipAddr, m_currentNode); return new InterfaceBuilder(m_currentIf); }
/** * <p>addInterface</p> * * @param ipAddr a {@link java.lang.String} object. * @param snmpInterface a {@link org.opennms.netmgt.model.OnmsSnmpInterface} object. * @return a {@link org.opennms.netmgt.model.NetworkBuilder.InterfaceBuilder} object. */ public InterfaceBuilder addInterface(final String ipAddr, final OnmsSnmpInterface snmpInterface) { m_currentIf = new OnmsIpInterface(addr(ipAddr), m_currentNode); m_currentIf.setSnmpInterface(snmpInterface); return new InterfaceBuilder(m_currentIf); }
private OnmsIpInterface createIpInterface(OnmsSnmpInterface snmp, InetAddress inetAddress) { OnmsIpInterface ip = new OnmsIpInterface(); ip.setSnmpInterface(snmp); ip.setIpLastCapsdPoll(new Date()); ip.setNode(snmp.getNode()); ip.setIpAddress(inetAddress); return ip; }
public InterfaceBuilder addIpInterface(final String ipAddress) { final OnmsIpInterface iface = new OnmsIpInterface(InetAddressUtils.addr(ipAddress), m_snmpIf.getNode()); m_snmpIf.addIpInterface(iface); return new InterfaceBuilder(iface); } }
/** {@inheritDoc} */ public void foundInterface(final String ipAddr, final Object descr, final InterfaceSnmpPrimaryType snmpPrimary, final boolean managed, final int status) { if ("".equals(ipAddr)) { log().error("Found interface on node "+m_node.getLabel()+" with an empty ipaddr! Ignoring!"); // create a bogus OnmsIpInterface and set it to current to services we run across get ignored as well m_currentInterface = new OnmsIpInterface(); return; } m_currentInterface = new OnmsIpInterface(ipAddr, m_node); m_currentInterface.setIsManaged(status == 3 ? "U" : "M"); m_currentInterface.setIsSnmpPrimary(PrimaryType.get(snmpPrimary.toString())); //m_currentInterface.setIpStatus(status == 3 ? new Integer(3) : new Integer(1)); if (InterfaceSnmpPrimaryType.P.equals(snmpPrimary)) { final InetAddress addr = InetAddressUtils.addr(ipAddr); if (addr == null) { LogUtils.errorf(this, "Unable to resolve address of snmpPrimary interface for node %s", m_node.getLabel()); } m_collector = new IfSnmpCollector(addr); } //FIXME: verify this doesn't conflict with constructor. The constructor already adds this //interface to the node. m_node.addIpInterface(m_currentInterface); }
/** * @param ipAddr * @param nodeLabel */ private void doAddNode(String ipAddr, String nodeLabel) { OnmsNode node = new OnmsNode(); node.setLabel(nodeLabel); OnmsIpInterface iface = new OnmsIpInterface(addr(ipAddr), node); iface.setIsManaged("M"); iface.setPrimaryString("N"); m_provisionService.insertNode(node); }
/** * @param ipAddr * @param nodeLabel */ private void doAddNode(String ipAddr, String nodeLabel) { OnmsNode node = new OnmsNode(); node.setLabel(nodeLabel); OnmsIpInterface iface = new OnmsIpInterface(addr(ipAddr), node); iface.setIsManaged("M"); iface.setPrimaryString("N"); m_provisionService.insertNode(node); }
/** * This method is necessary for CXF to be able to introspect * the type of {@link OnmsNode} parameters. */ public void setNode(OnmsNode node) { OnmsMonitoredService service = getMonitoredService(); if (service == null) { service = new OnmsMonitoredService(); setMonitoredService(service); } OnmsIpInterface intf = service.getIpInterface(); if (intf == null) { intf = new OnmsIpInterface(); service.setIpInterface(intf); } intf.setNode(node); }
public OnmsIpInterface createInterfaceFromRow() { final Integer ifIndex = getIfIndex(); final String ipAddr = getIpAddress(); final Integer type = getType(); final InetAddress netMask = getNetMask(); LOG.debug("createInterfaceFromRow: ifIndex = {}, ipAddress = {}, type = {}, netmask = {}", ifIndex, ipAddr, type, netMask); if (type != IP_ADDRESS_TYPE_UNICAST || ipAddr == null) { return null; } final InetAddress inetAddress = InetAddressUtils.addr(ipAddr); final OnmsIpInterface iface = new OnmsIpInterface(inetAddress, null); iface.setNetMask(netMask); if (ifIndex != null) { final OnmsSnmpInterface snmpIface = new OnmsSnmpInterface(null, ifIndex); snmpIface.setCollectionEnabled(true); iface.setSnmpInterface(snmpIface); iface.setIfIndex(ifIndex); } String hostName = null; if (inetAddress != null) hostName = inetAddress.getHostName(); if (hostName == null) hostName = normalize(ipAddr); LOG.debug("setIpHostName: {}", hostName); iface.setIpHostName(hostName == null? ipAddr : hostName); return iface; }
public OnmsIpInterface createInterfaceFromRow() { final Integer ifIndex = getIfIndex(); final String ipAddr = getIpAddress(); final Integer type = getType(); final InetAddress netMask = getNetMask(); LOG.debug("createInterfaceFromRow: ifIndex = {}, ipAddress = {}, type = {}, netmask = {}", ifIndex, ipAddr, type, netMask); if (type != IP_ADDRESS_TYPE_UNICAST || ipAddr == null) { return null; } final InetAddress inetAddress = InetAddressUtils.addr(ipAddr); final OnmsIpInterface iface = new OnmsIpInterface(inetAddress, null); iface.setNetMask(netMask); if (ifIndex != null) { final OnmsSnmpInterface snmpIface = new OnmsSnmpInterface(null, ifIndex); snmpIface.setCollectionEnabled(true); iface.setSnmpInterface(snmpIface); iface.setIfIndex(ifIndex); } String hostName = null; if (inetAddress != null) hostName = inetAddress.getHostName(); if (hostName == null) hostName = normalize(ipAddr); LOG.debug("setIpHostName: {}", hostName); iface.setIpHostName(hostName == null? ipAddr : hostName); return iface; }
public OnmsIpInterface createInterfaceFromRow() { final Integer ifIndex = getIfIndex(); final String ipAddr = getIpAddress(); final InetAddress netMask = getNetMask(); LOG.debug("createInterfaceFromRow: ifIndex = {}, ipAddress = {}, netmask = {}", ifIndex, ipAddr, netMask); if (ipAddr == null) { return null; } final InetAddress inetAddress = InetAddressUtils.addr(ipAddr); final OnmsIpInterface iface = new OnmsIpInterface(inetAddress, null); iface.setNetMask(netMask); if (ifIndex != null) { final OnmsSnmpInterface snmpIface = new OnmsSnmpInterface(null, ifIndex); snmpIface.setCollectionEnabled(true); iface.setSnmpInterface(snmpIface); iface.setIfIndex(ifIndex); } String hostName = null; if (inetAddress != null) hostName = inetAddress.getHostName(); if (hostName == null) hostName = InetAddressUtils.normalize(ipAddr); iface.setIpHostName(hostName == null? ipAddr : hostName); return iface; }
public OnmsIpInterface createInterfaceFromRow() { final Integer ifIndex = getIfIndex(); final String ipAddr = getIpAddress(); final InetAddress netMask = getNetMask(); LOG.debug("createInterfaceFromRow: ifIndex = {}, ipAddress = {}, netmask = {}", ifIndex, ipAddr, netMask); if (ipAddr == null) { return null; } final InetAddress inetAddress = InetAddressUtils.addr(ipAddr); final OnmsIpInterface iface = new OnmsIpInterface(inetAddress, null); iface.setNetMask(netMask); if (ifIndex != null) { final OnmsSnmpInterface snmpIface = new OnmsSnmpInterface(null, ifIndex); snmpIface.setCollectionEnabled(true); iface.setSnmpInterface(snmpIface); iface.setIfIndex(ifIndex); } String hostName = null; if (inetAddress != null) hostName = inetAddress.getHostName(); if (hostName == null) hostName = InetAddressUtils.normalize(ipAddr); iface.setIpHostName(hostName == null? ipAddr : hostName); return iface; }
private static OnmsIpInterface getInterface() { OnmsNode node = new OnmsNode(); node.setId(1); OnmsIpInterface iface = new OnmsIpInterface(InetAddressUtils.getInetAddress("192.168.1.1"), node); iface.setId(1); return iface; }
@Before public void setUp() throws Exception { MockLogAppender.setupLogging(); m_rrdStrategy = new JRobinRrdStrategy(); m_fileAnticipator = new FileAnticipator(); m_intf = new OnmsIpInterface(); m_node = new OnmsNode(); m_node.setId(1); m_intf.setNode(m_node); m_intf.setIpAddress(InetAddressUtils.addr("1.1.1.1")); m_intf.setId(27); m_ifDao = EasyMock.createMock(IpInterfaceDao.class); EasyMock.expect(m_ifDao.load(m_intf.getId())).andReturn(m_intf).anyTimes(); EasyMock.replay(m_ifDao); }
@Override protected OnmsNode doInsert() { final Date now = new Date(); OnmsMonitoringLocation location = createLocationIfNecessary(locationString); // Associate the location with the node final OnmsNode node = new OnmsNode(location); final String hostname = getHostnameResolver().getHostname(addr(ipAddress), locationString); if (hostname == null || ipAddress.equals(hostname)) { node.setLabel(ipAddress); node.setLabelSource(NodeLabelSource.ADDRESS); } else { node.setLabel(hostname); node.setLabelSource(NodeLabelSource.HOSTNAME); } node.setForeignSource(effectiveForeignSource); node.setType(NodeType.ACTIVE); node.setLastCapsdPoll(now); final OnmsIpInterface iface = new OnmsIpInterface(InetAddressUtils.addr(ipAddress), node); iface.setIsManaged("M"); iface.setIpHostName(hostname); iface.setIsSnmpPrimary(PrimaryType.NOT_ELIGIBLE); iface.setIpLastCapsdPoll(now); m_nodeDao.save(node); m_nodeDao.flush(); return node; } }.execute();
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()); }
@Before public void setUp() throws Exception { MockUtil.println("------------ Begin Test " + m_testName.getMethodName() + " --------------------------"); MockLogAppender.setupLogging(); m_fileAnticipator = new FileAnticipator(); m_rrdStrategy = new JRobinRrdStrategy(); m_resourceStorageDao = new FilesystemResourceStorageDao(); m_resourceStorageDao.setRrdDirectory(m_fileAnticipator.getTempDir()); m_intf = new OnmsIpInterface(); m_node = new OnmsNode(); m_node.setId(1); m_intf.setId(25); m_intf.setNode(m_node); m_intf.setIpAddress(InetAddressUtils.addr("1.1.1.1")); m_ifDao = m_easyMockUtils.createMock(IpInterfaceDao.class); m_serviceParams = new ServiceParameters(new HashMap<String,Object>()); }
@Test public void canHandleInterfaceDeletedEvents() { // Handle a interfaceDeleted event targeting svc1 OnmsNode node = new OnmsNode(); node.setId(svc1.getNodeId()); OnmsIpInterface iface = new OnmsIpInterface(); iface.setId(99); iface.setNode(node); iface.setIpAddress(svc1.getAddress()); Event e = new EventBuilder(EventConstants.INTERFACE_DELETED_EVENT_UEI, "test") .setIpInterface(iface) .getEvent(); collectd.onEvent(e); // The delete flag should be set (and only set) on svc1 assertTrue("deletion flag was not set on svc1!", svc1.getCollectorUpdates().isDeletionFlagSet()); assertFalse("deletion flag was set on svc2!", svc2.getCollectorUpdates().isDeletionFlagSet()); }
@Test public void canHandleServiceDeletedEvents() { // Handle a serviceDeleted event targeting svc2 OnmsNode node = new OnmsNode(); node.setId(svc2.getNodeId()); OnmsIpInterface iface = new OnmsIpInterface(); iface.setId(101); iface.setNode(node); iface.setIpAddress(svc2.getAddress()); Event e = new EventBuilder(EventConstants.SERVICE_DELETED_EVENT_UEI, "test") .setIpInterface(iface) .setService(svc2.getServiceName()) .getEvent(); collectd.onEvent(e); // The delete flag should be set (and only set) on svc2 assertFalse("deletion flag was set on svc1!", svc1.getCollectorUpdates().isDeletionFlagSet()); assertTrue("deletion flag was not set on svc2!", svc2.getCollectorUpdates().isDeletionFlagSet()); } }