protected String getEdgeTooltipText(DataLinkInterface link, Vertex source, Vertex target) { StringBuffer tooltipText = new StringBuffer(); OnmsSnmpInterface sourceInterface = getSnmpInterfaceDao() .findByNodeIdAndIfIndex(Integer.parseInt(source.getId()), link.getIfIndex()); OnmsSnmpInterface targetInterface = getSnmpInterfaceDao() .findByNodeIdAndIfIndex(Integer.parseInt(target.getId()), link.getParentIfIndex()); tooltipText.append(HTML_TOOLTIP_TAG_OPEN); if (sourceInterface != null && targetInterface != null && sourceInterface.getNetMask() != null && !sourceInterface.getNetMask().isLoopbackAddress() && targetInterface.getNetMask() != null && !targetInterface.getNetMask().isLoopbackAddress()) { tooltipText.append("Type of Link: Layer3/Layer2"); } else { tooltipText.append("Type of Link: Layer2"); } tooltipText.append(HTML_TOOLTIP_TAG_END); tooltipText.append(HTML_TOOLTIP_TAG_OPEN); tooltipText.append("Name: <endpoint1 " + source.getLabel()); if (sourceInterface != null) tooltipText.append(":" + sourceInterface.getIfName()); tooltipText.append(" ---- endpoint2 " + target.getLabel()); if (targetInterface != null) tooltipText.append(":" + targetInterface.getIfName()); tooltipText.append(">"); tooltipText.append(HTML_TOOLTIP_TAG_END); LinkStateMachine stateMachine = new LinkStateMachine(); stateMachine.setParentInterfaces(sourceInterface, targetInterface); tooltipText.append(HTML_TOOLTIP_TAG_OPEN); tooltipText.append("Link status: " + stateMachine.getLinkStatus()); tooltipText.append(HTML_TOOLTIP_TAG_END); if (targetInterface != null) { if (targetInterface.getIfSpeed() != null) { tooltipText.append(HTML_TOOLTIP_TAG_OPEN); tooltipText.append("Bandwidth: " + getHumanReadableIfSpeed(targetInterface.getIfSpeed())); tooltipText.append(HTML_TOOLTIP_TAG_END); } } else if (sourceInterface != null) { if (sourceInterface.getIfSpeed() != null) { tooltipText.append(HTML_TOOLTIP_TAG_OPEN); tooltipText.append("Bandwidth: " + getHumanReadableIfSpeed(sourceInterface.getIfSpeed())); tooltipText.append(HTML_TOOLTIP_TAG_END); } } tooltipText.append(HTML_TOOLTIP_TAG_OPEN); tooltipText.append("End Point 1: " + source.getLabel() + ", " + source.getIpAddress()); tooltipText.append(HTML_TOOLTIP_TAG_END); tooltipText.append(HTML_TOOLTIP_TAG_OPEN); tooltipText.append("End Point 2: " + target.getLabel() + ", " + target.getIpAddress()); tooltipText.append(HTML_TOOLTIP_TAG_END); return tooltipText.toString(); }
private ArrayList<OnmsResource> populateResourceList( File parent, File relPath, OnmsNode node, Boolean isForeign) { ArrayList<OnmsResource> resources = new ArrayList<OnmsResource>(); File[] intfDirs = parent.listFiles(RrdFileConstants.INTERFACE_DIRECTORY_FILTER); Set<OnmsSnmpInterface> snmpInterfaces = node.getSnmpInterfaces(); Map<String, OnmsSnmpInterface> intfMap = new HashMap<String, OnmsSnmpInterface>(); for (OnmsSnmpInterface snmpInterface : snmpInterfaces) { /* * When Cisco Express Forwarding (CEF) or some ATM encapsulations * (AAL5) are used on Cisco routers, an additional entry might be * in the ifTable for these sub-interfaces, but there is no * performance data available for collection. This check excludes * ifTable entries where ifDescr contains "-cef". See bug #803. */ if (snmpInterface.getIfDescr() != null) { if (Pattern.matches(".*-cef.*", snmpInterface.getIfDescr())) { continue; } } String replacedIfName = AlphaNumeric.parseAndReplace(snmpInterface.getIfName(), '_'); String replacedIfDescr = AlphaNumeric.parseAndReplace(snmpInterface.getIfDescr(), '_'); String[] keys = new String[] { replacedIfName + "-", replacedIfDescr + "-", replacedIfName + "-" + snmpInterface.getPhysAddr(), replacedIfDescr + "-" + snmpInterface.getPhysAddr() }; for (String key : keys) { if (!intfMap.containsKey(key)) { intfMap.put(key, snmpInterface); } } } for (File intfDir : intfDirs) { String name = intfDir.getName(); String desc = name; String mac = ""; // Strip off the MAC address from the end, if there is one int dashIndex = name.lastIndexOf('-'); if (dashIndex >= 0) { desc = name.substring(0, dashIndex); mac = name.substring(dashIndex + 1, name.length()); } String key = desc + "-" + mac; OnmsSnmpInterface snmpInterface = intfMap.get(key); String label; Long ifSpeed = null; String ifSpeedFriendly = null; if (snmpInterface == null) { label = name + " (*)"; } else { StringBuffer descr = new StringBuffer(); StringBuffer parenString = new StringBuffer(); if (snmpInterface.getIfAlias() != null) { parenString.append(snmpInterface.getIfAlias()); } // Append all of the IP addresses on this ifindex for (OnmsIpInterface ipif : snmpInterface.getIpInterfaces()) { String ipaddr = InetAddressUtils.str(ipif.getIpAddress()); if (!"0.0.0.0".equals(ipaddr)) { if (parenString.length() > 0) { parenString.append(", "); } parenString.append(ipaddr); } } if ((snmpInterface.getIfSpeed() != null) && (snmpInterface.getIfSpeed() != 0)) { ifSpeed = snmpInterface.getIfSpeed(); ifSpeedFriendly = SIUtils.getHumanReadableIfSpeed(ifSpeed); if (parenString.length() > 0) { parenString.append(", "); } parenString.append(ifSpeedFriendly); } if (snmpInterface.getIfName() != null) { descr.append(snmpInterface.getIfName()); } else if (snmpInterface.getIfDescr() != null) { descr.append(snmpInterface.getIfDescr()); } else { /* * Should never reach this point, since ifLabel is based on * the values of ifName and ifDescr but better safe than sorry. */ descr.append(name); } /* Add the extended information in parenthesis after the ifLabel, * if such information was found. */ if (parenString.length() > 0) { descr.append(" ("); descr.append(parenString); descr.append(")"); } label = descr.toString(); } OnmsResource resource = null; if (isForeign) { resource = getResourceByNodeSourceAndInterface( relPath.toString(), intfDir.getName(), label, ifSpeed, ifSpeedFriendly); } else { resource = getResourceByNodeAndInterface( node.getId(), intfDir.getName(), label, ifSpeed, ifSpeedFriendly); } if (snmpInterface != null) { Set<OnmsIpInterface> ipInterfaces = snmpInterface.getIpInterfaces(); if (ipInterfaces.size() > 0) { int id = ipInterfaces.iterator().next().getId(); resource.setLink("element/interface.jsp?ipinterfaceid=" + id); } else { int ifIndex = snmpInterface.getIfIndex(); if (ifIndex > -1) { resource.setLink( "element/snmpinterface.jsp?node=" + node.getNodeId() + "&ifindex=" + ifIndex); } } resource.setEntity(snmpInterface); } else { LOG.debug("populateResourceList: snmpInterface is null"); } LOG.debug("populateResourceList: adding resource toString {}", resource.toString()); resources.add(resource); } return resources; }