use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class EnhancedLinkdTopologyProvider method addNodesWithoutLinks.
private void addNodesWithoutLinks(Map<Integer, OnmsNode> nodemap, Map<Integer, List<OnmsIpInterface>> nodeipmap, Map<Integer, OnmsIpInterface> nodeipprimarymap) {
for (Entry<Integer, OnmsNode> entry : nodemap.entrySet()) {
Integer nodeId = entry.getKey();
OnmsNode node = entry.getValue();
if (getVertex(getNamespace(), nodeId.toString()) == null) {
LOG.debug("Adding link-less node: {}", node.getLabel());
// Use the primary interface, if set
OnmsIpInterface ipInterface = nodeipprimarymap.get(nodeId);
if (ipInterface == null) {
// Otherwise fall back to the first interface defined
List<OnmsIpInterface> ipInterfaces = nodeipmap.getOrDefault(nodeId, Collections.emptyList());
if (ipInterfaces.size() > 0) {
ipInterfaces.get(0);
}
}
addVertices(createVertexFor(node, ipInterface));
}
}
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class ResponseTimeResourceType method getChildByName.
@Override
public OnmsResource getChildByName(OnmsResource parent, String ipAddress) {
// Grab the node entity
final OnmsNode node = ResourceTypeUtils.getNodeFromResource(parent);
// Determine the location name
final String locationName = MonitoringLocationUtils.getLocationNameOrNullIfDefault(node);
// Grab the interface
final OnmsIpInterface matchingIf = m_ipInterfaceDao.get(node, ipAddress);
if (matchingIf == null) {
throw new ObjectRetrievalFailureException(OnmsIpInterface.class, "No interface with ipAddr " + ipAddress + " could be found on node with id " + node.getId());
}
// Verify the path
final ResourcePath path = getInterfacePath(locationName, ipAddress);
if (!m_resourceStorageDao.exists(path, 0)) {
throw new ObjectRetrievalFailureException(OnmsResource.class, "No metrics found in parent path '" + parent.getPath() + "'");
}
// Create the resource
final OnmsResource resource = createResource(locationName, matchingIf, ipAddress, path);
resource.setParent(parent);
return resource;
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class RancidProvisioningAdapter method getSuitableIpForRancid.
private String getSuitableIpForRancid(OnmsNode node) {
LOG.debug("getSuitableIpForRancid: node: {} Foreign Source: {}", node.getForeignSource(), node.getNodeId());
OnmsIpInterface primaryInterface = node.getPrimaryInterface();
String ipaddr = "127.0.0.1";
if (primaryInterface == null) {
LOG.debug("getSuitableIpForRancid: found null SNMP Primary Interface, getting interfaces");
Set<OnmsIpInterface> ipInterfaces = node.getIpInterfaces();
for (OnmsIpInterface onmsIpInterface : ipInterfaces) {
LOG.debug("getSuitableIpForRancid: trying Interface with id: {}", onmsIpInterface.getId());
if (onmsIpInterface.getIpAddress() != null) {
ipaddr = str(onmsIpInterface.getIpAddress());
} else {
LOG.debug("getSuitableIpForRancid: found null ip address on Interface with id: {}", onmsIpInterface.getId());
}
}
} else {
LOG.debug("getSuitableIpForRancid: found SNMP Primary Interface");
if (primaryInterface.getIpAddress() != null) {
ipaddr = str(primaryInterface.getIpAddress());
} else {
LOG.debug("getSuitableIpForRancid: found null ip address on Primary Interface");
}
}
return ipaddr;
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class NetworkElementFactory method getHostname.
/* (non-Javadoc)
* @see org.opennms.web.element.NetworkElementFactoryInterface#getHostname(java.lang.String)
*/
@Override
public String getHostname(String ipAddress) {
OnmsCriteria criteria = new OnmsCriteria(OnmsIpInterface.class);
criteria.add(Restrictions.eq("ipAddress", InetAddressUtils.addr(ipAddress)));
criteria.add(Restrictions.isNotNull("ipHostName"));
criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
List<OnmsIpInterface> ipIfaces = m_ipInterfaceDao.findMatching(criteria);
if (ipIfaces.size() > 0) {
OnmsIpInterface iface = ipIfaces.get(0);
return iface.getIpHostName();
}
return null;
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class EnLinkdElementFactory method convertFromModel.
@Transactional
@SuppressWarnings("deprecation")
private NodeLinkBridge convertFromModel(String mac, SharedSegment segment, String port) {
final NodeLinkBridge linknode = new NodeLinkBridge();
linknode.setNodeLocalPort(port);
for (BridgePort link : segment.getBridgePortsOnSegment()) {
final BridgeLinkRemoteNode remlinknode = new BridgeLinkRemoteNode();
final Integer rempnodeId = link.getNode().getId();
final Integer rembridgePortIfIndex = link.getBridgePortIfIndex();
remlinknode.setBridgeRemoteNode(link.getNode().getLabel());
remlinknode.setBridgeRemoteUrl(getNodeUrl(rempnodeId));
final OnmsSnmpInterface remiface = rembridgePortIfIndex == null ? null : m_snmpInterfaceDao.findByNodeIdAndIfIndex(rempnodeId, rembridgePortIfIndex);
if (remiface != null) {
remlinknode.setBridgeRemotePort(getPortString(rembridgePortIfIndex, remiface.getIfName(), remiface.getIfAlias()));
} else {
remlinknode.setBridgeRemotePort(getPortString(rembridgePortIfIndex, null, null));
}
remlinknode.setBridgeRemotePortUrl(getSnmpInterfaceUrl(rempnodeId, rembridgePortIfIndex));
remlinknode.setBridgeRemoteVlan(link.getVlan());
linknode.getBridgeLinkRemoteNodes().add(remlinknode);
}
for (BridgeMacLink link : segment.getBridgeMacLinks()) {
if (link.getMacAddress().equals(mac)) {
linknode.setBridgeLinkCreateTime(Util.formatDateToUIString(link.getBridgeMacLinkCreateTime()));
linknode.setBridgeLinkLastPollTime(Util.formatDateToUIString(link.getBridgeMacLinkLastPollTime()));
break;
}
}
Map<String, List<IpNetToMedia>> sharedmacs = new HashMap<String, List<IpNetToMedia>>();
for (String shredmac : segment.getMacsOnSegment()) {
if (shredmac.equals(mac))
continue;
sharedmacs.put(shredmac, new ArrayList<IpNetToMedia>());
sharedmacs.get(shredmac).addAll(m_ipNetToMediaDao.findByPhysAddress(shredmac));
}
Map<String, List<OnmsIpInterface>> sharedhosts = new HashMap<String, List<OnmsIpInterface>>();
for (String shredmac : sharedmacs.keySet()) {
if (sharedmacs.get(shredmac).isEmpty()) {
BridgeLinkSharedHost remlinknode = new BridgeLinkSharedHost();
OnmsSnmpInterface snmp = getFromPhysAddress(shredmac);
if (snmp == null) {
remlinknode.setSharedHost(shredmac + " No ip address found");
} else {
remlinknode.setSharedHost(snmp.getNode().getLabel());
remlinknode.setSharedHostUrl(getNodeUrl(snmp.getNode().getId()));
remlinknode.setSharedHostPort(getPortString(snmp.getIfIndex(), snmp.getIfName(), snmp.getIfAlias()));
remlinknode.setSharedHostPortUrl(getSnmpInterfaceUrl(snmp.getNode().getId(), snmp.getIfIndex()));
}
linknode.getBridgeLinkSharedHost().add(remlinknode);
continue;
}
sharedhosts.put(shredmac, new ArrayList<OnmsIpInterface>());
for (IpNetToMedia ipnettomedia : sharedmacs.get(shredmac)) sharedhosts.get(shredmac).addAll(m_ipInterfaceDao.findByIpAddress(ipnettomedia.getNetAddress().getHostAddress()));
}
for (String shredmac : sharedhosts.keySet()) {
BridgeLinkSharedHost remlinknode = new BridgeLinkSharedHost();
Set<InetAddress> ips = new HashSet<InetAddress>();
if (sharedhosts.get(shredmac).isEmpty()) {
for (IpNetToMedia ipnettomedia : sharedmacs.get(shredmac)) {
ips.add(ipnettomedia.getNetAddress());
}
remlinknode.setSharedHost(getNodePortString(ips, shredmac) + " No node found");
linknode.getBridgeLinkSharedHost().add(remlinknode);
continue;
}
OnmsIpInterface first = null;
boolean multiplenodeids = false;
for (OnmsIpInterface ip : sharedhosts.get(shredmac)) {
if (first == null)
first = ip;
if (first.getNode().getId().intValue() != ip.getNode().getId().intValue())
multiplenodeids = true;
ips.add(ip.getIpAddress());
}
if (multiplenodeids) {
remlinknode.setSharedHost(getNodePortString(ips, shredmac) + " duplicated ip multiple node associated in db");
} else {
remlinknode.setSharedHost(first.getNode().getLabel());
remlinknode.setSharedHostUrl(getNodeUrl(first.getNode().getId()));
}
remlinknode.setSharedHostPort(getNodePortString(ips, shredmac));
if (ips.size() == 1) {
remlinknode.setSharedHostPortUrl(getIpInterfaceUrl(first));
}
linknode.getBridgeLinkSharedHost().add(remlinknode);
}
return linknode;
}
Aggregations