当前位置: 首页>>代码示例>>Java>>正文


Java OnmsNode.getIpInterfaceByIpAddress方法代码示例

本文整理汇总了Java中org.opennms.netmgt.model.OnmsNode.getIpInterfaceByIpAddress方法的典型用法代码示例。如果您正苦于以下问题:Java OnmsNode.getIpInterfaceByIpAddress方法的具体用法?Java OnmsNode.getIpInterfaceByIpAddress怎么用?Java OnmsNode.getIpInterfaceByIpAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.opennms.netmgt.model.OnmsNode的用法示例。


在下文中一共展示了OnmsNode.getIpInterfaceByIpAddress方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: simulateScan

import org.opennms.netmgt.model.OnmsNode; //导入方法依赖的package包/类
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();
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:19,代码来源:NodeDaoTest.java

示例2: isRequisitioned

import org.opennms.netmgt.model.OnmsNode; //导入方法依赖的package包/类
public boolean isRequisitioned(OnmsIpInterface ip) {
	String foreignSource = ip.getNode().getForeignSource();
	String foreignId = ip.getNode().getForeignId();
	
	// is this a discovered node
	if (foreignSource == null) return false;
	
	OnmsNode reqNode = getRequisitionedNode(foreignSource, foreignId);
	if (reqNode == null) { 
		// this is no requisition node?
		LogUtils.errorf("No requistion exists for node with foreignSource %s and foreignId %s.  Treating node as unrequistioned", foreignSource, foreignId);
		return false;
	}
	
	OnmsIpInterface reqIp = reqNode.getIpInterfaceByIpAddress(ip.getIpAddress());
	// if we found the ip then its a requisitioned interface
	return reqIp != null;
	
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:20,代码来源:DefaultProvisionService.java

示例3: deleteService

import org.opennms.netmgt.model.OnmsNode; //导入方法依赖的package包/类
/**
 * <p>deleteService</p>
 *
 * @param nodeCriteria a {@link java.lang.String} object.
 * @param ipAddress a {@link java.lang.String} object.
 * @param serviceName a {@link java.lang.String} object.
 * @return a {@link javax.ws.rs.core.Response} object.
 */
@DELETE
@Path("{service}")
public Response deleteService(@PathParam("nodeCriteria") String nodeCriteria, @PathParam("ipAddress") String ipAddress, @PathParam("service") String serviceName) {
    writeLock();
    
    try {
        OnmsNode node = m_nodeDao.get(nodeCriteria);
        if (node == null) throw getException(Status.BAD_REQUEST, "deleteService: can't find node " + nodeCriteria);
        OnmsIpInterface intf = node.getIpInterfaceByIpAddress(ipAddress);
        if (intf == null) throw getException(Status.BAD_REQUEST, "deleteService: can't find interface with ip address " + ipAddress + " for node " + nodeCriteria);
        OnmsMonitoredService service = intf.getMonitoredServiceByServiceType(serviceName);
        if (service == null) throw getException(Status.CONFLICT, "deleteService: service " + serviceName + " not found on interface " + intf);
        log().debug("deleteService: deleting service " + serviceName + " from node " + nodeCriteria);
        intf.getMonitoredServices().remove(service);
        m_ipInterfaceDao.saveOrUpdate(intf);
        
        sendEvent(EventConstants.SERVICE_DELETED_EVENT_UEI, service);
        return Response.ok().build();
    } finally {
        writeUnlock();
    }
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:31,代码来源:OnmsMonitoredServiceResource.java

示例4: getIpInterface

import org.opennms.netmgt.model.OnmsNode; //导入方法依赖的package包/类
/**
 * <p>getIpInterface</p>
 *
 * @param nodeCriteria a {@link java.lang.String} object.
 * @param ipAddress a {@link java.lang.String} object.
 * @return a {@link org.opennms.netmgt.model.OnmsIpInterface} object.
 */
@GET
@Produces({MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON})
@Path("{ipAddress}")
public OnmsIpInterface getIpInterface(@PathParam("nodeCriteria") final String nodeCriteria, @PathParam("ipAddress") final String ipAddress) {
    readLock();
    
    try {
        final OnmsNode node = m_nodeDao.get(nodeCriteria);
        if (node == null) {
            throw getException(Status.BAD_REQUEST, "getIpInterface: can't find node " + nodeCriteria);
        }
        return node.getIpInterfaceByIpAddress(InetAddressUtils.getInetAddress(ipAddress));
    } finally {
        readUnlock();
    }
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:24,代码来源:OnmsIpInterfaceResource.java

示例5: testPersistEventWithService

import org.opennms.netmgt.model.OnmsNode; //导入方法依赖的package包/类
/**
 * Test that eventd's service ID lookup works properly.
 */
@Test
@JUnitTemporaryDatabase
public void testPersistEventWithService() throws Exception {

    assertEquals(0, m_database.countRows(String.format("select * from events where eventuei = '%s'", EventConstants.SERVICE_UNRESPONSIVE_EVENT_UEI)));
    assertEquals("service ID for ICMP", 1, m_jdbcTemplate.queryForInt("select serviceid from service where servicename = 'ICMP'"));

    OnmsNode node = m_databasePopulator.getNode1();
    assertNotNull(node);
    OnmsIpInterface intf = node.getIpInterfaceByIpAddress("192.168.1.1");
    assertNotNull(intf);
    OnmsMonitoredService svc = intf.getMonitoredServiceByServiceType("ICMP");
    assertNotNull(svc);
    assertEquals(1, svc.getNodeId().intValue());
    assertEquals("192.168.1.1", str(svc.getIpAddress()));
    assertEquals(1, svc.getServiceId().intValue());
    sendServiceDownEvent(null, svc);

    Thread.sleep(1000);
    assertEquals(1, m_database.countRows(String.format("select * from events where eventuei = '%s'", EventConstants.SERVICE_UNRESPONSIVE_EVENT_UEI)));
    assertEquals("service ID for event", 1, m_jdbcTemplate.queryForInt(String.format("select serviceID from events where eventuei = '%s'", EventConstants.SERVICE_UNRESPONSIVE_EVENT_UEI)));
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:26,代码来源:EventdTest.java

示例6: updateIpInterfaceData

import org.opennms.netmgt.model.OnmsNode; //导入方法依赖的package包/类
/**
 * <p>updateIpInterfaceData</p>
 *
 * @param node a {@link org.opennms.netmgt.model.OnmsNode} object.
 * @param ipAddr a {@link java.lang.String} object.
 */
public void updateIpInterfaceData(final OnmsNode node, final String ipAddr) {
	OnmsIpInterface ipIf = node.getIpInterfaceByIpAddress(ipAddr);
    if (ipIf == null) {
        ipIf = new OnmsIpInterface(ipAddr, node);
    }

    final InetAddress inetAddr = ipIf.getIpAddress();
    final Integer ifIndex = getIfIndex(inetAddr);

    // if we've found an ifIndex for this interface
    if (ifIndex != null) {

        // first look to see if an snmpIf was created already
        OnmsSnmpInterface snmpIf = node.getSnmpInterfaceWithIfIndex(ifIndex);

        if (snmpIf == null) {
            // if not then create one
            snmpIf = new OnmsSnmpInterface(node, ifIndex);
        }

        final InetAddress mask = getNetMask(inetAddr);
        if (mask != null) {
            snmpIf.setNetMask(mask);
        }

        snmpIf.setCollectionEnabled(true);
        
        ipIf.setSnmpInterface(snmpIf);

    }

    ipIf.setIpHostName(ipAddr);
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:40,代码来源:IpAddressTable.java

示例7: updateIpInterfaceData

import org.opennms.netmgt.model.OnmsNode; //导入方法依赖的package包/类
/**
 * <p>updateIpInterfaceData</p>
 *
 * @param node a {@link org.opennms.netmgt.model.OnmsNode} object.
 * @param ipAddr a {@link java.lang.String} object.
 */
public void updateIpInterfaceData(OnmsNode node, String ipAddr) {
    OnmsIpInterface ipIf = node.getIpInterfaceByIpAddress(ipAddr);
    if (ipIf == null) {
        ipIf = new OnmsIpInterface(ipAddr, node);
    }

    InetAddress inetAddr = ipIf.getIpAddress();
    Integer ifIndex = getIfIndex(inetAddr);

    // if we've found an ifIndex for this interface
    if (ifIndex != null) {

        // first look to see if an snmpIf was created already
        OnmsSnmpInterface snmpIf = node.getSnmpInterfaceWithIfIndex(ifIndex);

        if (snmpIf == null) {
            // if not then create one
            snmpIf = new OnmsSnmpInterface(node, ifIndex);
        }

        final InetAddress mask = getNetMask(inetAddr);
        if (mask != null) {
            snmpIf.setNetMask(mask);
        }

        snmpIf.setCollectionEnabled(true);
        
        ipIf.setSnmpInterface(snmpIf);

    }

    ipIf.setIpHostName(ipAddr);
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:40,代码来源:IpAddrTable.java

示例8: updateIpInterface

import org.opennms.netmgt.model.OnmsNode; //导入方法依赖的package包/类
/**
 * <p>updateIpInterface</p>
 *
 * @param nodeCriteria a {@link java.lang.String} object.
 * @param ipAddress a {@link java.lang.String} object.
 * @param params a {@link org.opennms.web.rest.MultivaluedMapImpl} object.
 * @return a {@link javax.ws.rs.core.Response} object.
 */
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("{ipAddress}")
public Response updateIpInterface(@PathParam("nodeCriteria") final String nodeCriteria, @PathParam("ipAddress") final String ipAddress, final MultivaluedMapImpl params) {
    writeLock();
    
    try {
        final OnmsNode node = m_nodeDao.get(nodeCriteria);
        if (node == null) {
            throw getException(Status.BAD_REQUEST, "deleteIpInterface: can't find node " + nodeCriteria);
        }
        final OnmsIpInterface ipInterface = node.getIpInterfaceByIpAddress(ipAddress);
        if (ipInterface == null) {
            throw getException(Status.CONFLICT, "deleteIpInterface: can't find interface with ip address " + ipAddress + " for node " + nodeCriteria);
        }
        LogUtils.debugf(this, "updateIpInterface: updating ip interface %s", ipInterface);

        final BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(ipInterface);

        for(final String key : params.keySet()) {
            if (wrapper.isWritableProperty(key)) {
                final String stringValue = params.getFirst(key);
                final Object value = wrapper.convertIfNecessary(stringValue, (Class<?>)wrapper.getPropertyType(key));
                wrapper.setPropertyValue(key, value);
            }
        }
        LogUtils.debugf(this, "updateIpInterface: ip interface %s updated", ipInterface);
        m_ipInterfaceDao.saveOrUpdate(ipInterface);
        return Response.seeOther(getRedirectUri(m_uriInfo)).build();
    } finally {
        writeUnlock();
    }
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:42,代码来源:OnmsIpInterfaceResource.java

示例9: deleteIpInterface

import org.opennms.netmgt.model.OnmsNode; //导入方法依赖的package包/类
/**
 * <p>deleteIpInterface</p>
 *
 * @param nodeCriteria a {@link java.lang.String} object.
 * @param ipAddress a {@link java.lang.String} object.
 * @return a {@link javax.ws.rs.core.Response} object.
 */
@DELETE
@Path("{ipAddress}")
public Response deleteIpInterface(@PathParam("nodeCriteria") final String nodeCriteria, @PathParam("ipAddress") final String ipAddress) {
    writeLock();
    
    try {
        final OnmsNode node = m_nodeDao.get(nodeCriteria);
        if (node == null) {
            throw getException(Status.BAD_REQUEST, "deleteIpInterface: can't find node " + nodeCriteria);
        }
        final OnmsIpInterface intf = node.getIpInterfaceByIpAddress(InetAddressUtils.getInetAddress(ipAddress));
        if (intf == null) {
            throw getException(Status.CONFLICT, "deleteIpInterface: can't find interface with ip address " + ipAddress + " for node " + nodeCriteria);
        }
        LogUtils.debugf(this, "deleteIpInterface: deleting interface %s from node %s", ipAddress, nodeCriteria);
        node.getIpInterfaces().remove(intf);
        m_nodeDao.save(node);
        
        final EventBuilder bldr = new EventBuilder(EventConstants.INTERFACE_DELETED_EVENT_UEI, getClass().getName());

        bldr.setNodeid(node.getId());
        bldr.setInterface(addr(ipAddress));

        try {
            m_eventProxy.send(bldr.getEvent());
        } catch (final EventProxyException ex) {
            throw getException(Status.BAD_REQUEST, ex.getMessage());
        }
        return Response.ok().build();
    } finally {
        writeUnlock();
    }
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:41,代码来源:OnmsIpInterfaceResource.java

示例10: walkTable

import org.opennms.netmgt.model.OnmsNode; //导入方法依赖的package包/类
private void walkTable(final BatchTask currentPhase, final Set<InetAddress> provisionedIps, final TableTracker tracker) {
          final OnmsNode node = getNode();
	infof(this, "detecting IP interfaces for node %d/%s/%s using table tracker %s", node.getId(), node.getForeignSource(), node.getForeignId(), tracker);

	if (isAborted()) {
		debugf(this, "'%s' is marked as aborted; skipping scan of table %s", currentPhase, tracker);
	} else {
           Assert.notNull(getAgentConfigFactory(), "agentConfigFactory was not injected");
	
       	final SnmpAgentConfig agentConfig = getAgentConfigFactory().getAgentConfig(getAgentAddress());
	
		final SnmpWalker walker = SnmpUtils.createWalker(agentConfig, "IP address tables", tracker);
		walker.start();
     
		try {
		    walker.waitFor();
     
		    if (walker.timedOut()) {
		        abort("Aborting node scan : Agent timed out while scanning the IP address tables");
		    }
		    else if (walker.failed()) {
		        abort("Aborting node scan : Agent failed while scanning the IP address tables : " + walker.getErrorMessage());
		    } else {
     
		        // After processing the SNMP provided interfaces then we need to scan any that 
		        // were provisioned but missing from the ip table
		        for(final InetAddress ipAddr : provisionedIps) {
		            final OnmsIpInterface iface = node.getIpInterfaceByIpAddress(ipAddr);
		            
		            if (iface != null) {
			            iface.setIpLastCapsdPoll(getScanStamp());
			            iface.setIsManaged("M");
      
			            currentPhase.add(ipUpdater(currentPhase, iface), "write");
		            }
		        }
     
		        debugf(this, "Finished phase %s", currentPhase);
     
		    }
		} catch (final InterruptedException e) {
		    abort("Aborting node scan : Scan thread failed while waiting for the IP address tables");
		}
	}
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:46,代码来源:NodeScan.java

示例11: addService

import org.opennms.netmgt.model.OnmsNode; //导入方法依赖的package包/类
/**
 * <p>addService</p>
 *
 * @param nodeCriteria a {@link java.lang.String} object.
 * @param ipAddress a {@link java.lang.String} object.
 * @param service a {@link org.opennms.netmgt.model.OnmsMonitoredService} object.
 * @return a {@link javax.ws.rs.core.Response} object.
 */
@POST
@Consumes(MediaType.APPLICATION_XML)
public Response addService(@PathParam("nodeCriteria") final String nodeCriteria, @PathParam("ipAddress") final String ipAddress, final OnmsMonitoredService service) {
    writeLock();
    
    try {
        OnmsNode node = m_nodeDao.get(nodeCriteria);
        if (node == null) throw getException(Status.BAD_REQUEST, "addService: can't find node " + nodeCriteria);
        final OnmsIpInterface intf = node.getIpInterfaceByIpAddress(ipAddress);
        if (intf == null) throw getException(Status.BAD_REQUEST, "addService: can't find interface with ip address " + ipAddress + " for node " + nodeCriteria);
        if (service == null) throw getException(Status.BAD_REQUEST, "addService: service object cannot be null");
        if (service.getServiceName() == null) throw getException(Status.BAD_REQUEST, "addService: service must have a name");

        final OnmsServiceType serviceType = new CreateIfNecessaryTemplate<OnmsServiceType, ServiceTypeDao>(m_transactionManager, m_serviceTypeDao) {
            @Override
            protected OnmsServiceType query() {
                return m_dao.findByName(service.getServiceName());
            }

            @Override
            protected OnmsServiceType doInsert() {
                final OnmsServiceType s = new OnmsServiceType(service.getServiceName());
                m_dao.saveOrUpdate(s);
                return s;
            }
        }.execute();

        service.setServiceType(serviceType);
        service.setIpInterface(intf);
        log().debug("addService: adding service " + service);
        m_serviceDao.save(service);
        
        Event e = EventUtils.createNodeGainedServiceEvent(getClass().getName(), node.getId(), intf.getIpAddress(), 
                service.getServiceName(), node.getLabel(), node.getLabelSource(), node.getSysName(), node.getSysDescription());
        
        try {
            m_eventProxy.send(e);
        } catch (EventProxyException ex) {
            throw getException(Status.BAD_REQUEST, ex.getMessage());
        }
        return Response.seeOther(getRedirectUri(m_uriInfo, service.getServiceName())).build();
    } finally {
        writeUnlock();
    }
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:54,代码来源:OnmsMonitoredServiceResource.java

示例12: updateService

import org.opennms.netmgt.model.OnmsNode; //导入方法依赖的package包/类
/**
 * <p>updateService</p>
 *
 * @param nodeCriteria a {@link java.lang.String} object.
 * @param ipAddress a {@link java.lang.String} object.
 * @param serviceName a {@link java.lang.String} object.
 * @param params a {@link org.opennms.web.rest.MultivaluedMapImpl} object.
 * @return a {@link javax.ws.rs.core.Response} object.
 */
@PUT
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@Path("{service}")
public Response updateService(@PathParam("nodeCriteria") String nodeCriteria, @PathParam("ipAddress") String ipAddress, @PathParam("service") String serviceName, MultivaluedMapImpl params) {
    writeLock();
    try {
        OnmsNode node = m_nodeDao.get(nodeCriteria);
        if (node == null) throw getException(Status.BAD_REQUEST, "addService: can't find node " + nodeCriteria);
        OnmsIpInterface intf = node.getIpInterfaceByIpAddress(ipAddress);
        if (intf == null) throw getException(Status.BAD_REQUEST, "addService: can't find ip interface on " + nodeCriteria + "@" + ipAddress);
        OnmsMonitoredService service = intf.getMonitoredServiceByServiceType(serviceName);
        if (service == null) throw getException(Status.BAD_REQUEST, "addService: can't find service " + serviceName + " on " + nodeCriteria + "@" + ipAddress);

        log().debug("updateService: updating service " + service);
        BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(service);
        for(String key : params.keySet()) {
            if (wrapper.isWritableProperty(key)) {
                String stringValue = params.getFirst(key);
                Object value = wrapper.convertIfNecessary(stringValue, (Class<?>)wrapper.getPropertyType(key));
                if (key.equals("status")) {
                    if ("S".equals(value) || (service.getStatus().equals("A") && value.equals("F"))) {
                        log().debug("updateService: suspending polling for service " + service.getServiceName() + " on node with IP " + service.getIpAddress().getHostAddress());
                        value = "F";
                        sendEvent(EventConstants.SUSPEND_POLLING_SERVICE_EVENT_UEI, service);
                    }
                    if ("R".equals(value) || (service.getStatus().equals("F") && value.equals("A"))) {
                        log().debug("updateService: resumg polling for service " + service.getServiceName() + " on node with IP " + service.getIpAddress().getHostAddress());
                        value = "A";
                        sendEvent(EventConstants.RESUME_POLLING_SERVICE_EVENT_UEI, service);
                    }
                }
                wrapper.setPropertyValue(key, value);
            }
        }
        log().debug("updateSservice: service " + service + " updated");
        m_serviceDao.saveOrUpdate(service);
        // If the status is changed, we should send the proper event to notify Pollerd
        return Response.seeOther(getRedirectUri(m_uriInfo)).build();
    } finally {
        writeUnlock();
    }
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:52,代码来源:OnmsMonitoredServiceResource.java

示例13: getIpInterface

import org.opennms.netmgt.model.OnmsNode; //导入方法依赖的package包/类
private OnmsIpInterface getIpInterface(int nodeId, String ipAddress) {
	OnmsNode node = m_nodeDao.load(nodeId);
       OnmsIpInterface iface = node.getIpInterfaceByIpAddress(ipAddress);
	return iface;
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:6,代码来源:Collectd.java


注:本文中的org.opennms.netmgt.model.OnmsNode.getIpInterfaceByIpAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。