use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class EnhancedLinkdTopologyProvider method loadCompleteTopology.
private void loadCompleteTopology() {
try {
resetContainer();
} catch (Exception e) {
LOG.error("Exception reset Container: " + e.getMessage(), e);
}
Map<Integer, OnmsNode> nodemap = new HashMap<Integer, OnmsNode>();
Map<Integer, List<OnmsIpInterface>> nodeipmap = new HashMap<Integer, List<OnmsIpInterface>>();
Map<Integer, OnmsIpInterface> nodeipprimarymap = new HashMap<Integer, OnmsIpInterface>();
Map<String, List<OnmsIpInterface>> macipmap = new HashMap<String, List<OnmsIpInterface>>();
Map<InetAddress, OnmsIpInterface> ipmap = new HashMap<InetAddress, OnmsIpInterface>();
Map<Integer, List<OnmsSnmpInterface>> nodesnmpmap = new HashMap<Integer, List<OnmsSnmpInterface>>();
Timer.Context context = m_loadNodesTimer.time();
try {
LOG.info("Loading nodes");
for (OnmsNode node : m_nodeDao.findAll()) {
nodemap.put(node.getId(), node);
}
LOG.info("Nodes loaded");
} catch (Exception e) {
LOG.error("Exception getting node list: " + e.getMessage(), e);
} finally {
context.stop();
}
context = m_loadIpInterfacesTimer.time();
try {
LOG.info("Loading Ip Interface");
Set<InetAddress> duplicatedips = new HashSet<InetAddress>();
for (OnmsIpInterface ip : m_ipInterfaceDao.findAll()) {
if (!nodeipmap.containsKey(ip.getNode().getId())) {
nodeipmap.put(ip.getNode().getId(), new ArrayList<OnmsIpInterface>());
nodeipprimarymap.put(ip.getNode().getId(), ip);
}
nodeipmap.get(ip.getNode().getId()).add(ip);
if (ip.getIsSnmpPrimary().equals(PrimaryType.PRIMARY)) {
nodeipprimarymap.put(ip.getNode().getId(), ip);
}
if (duplicatedips.contains(ip.getIpAddress())) {
LOG.info("Loading ip Interface, found duplicated ip {}, skipping ", InetAddressUtils.str(ip.getIpAddress()));
continue;
}
if (ipmap.containsKey(ip.getIpAddress())) {
LOG.info("Loading ip Interface, found duplicated ip {}, skipping ", InetAddressUtils.str(ip.getIpAddress()));
duplicatedips.add(ip.getIpAddress());
continue;
}
ipmap.put(ip.getIpAddress(), ip);
}
for (InetAddress duplicated : duplicatedips) ipmap.remove(duplicated);
LOG.info("Ip Interface loaded");
} catch (Exception e) {
LOG.error("Exception getting ip list: " + e.getMessage(), e);
} finally {
context.stop();
}
context = m_loadSnmpInterfacesTimer.time();
try {
LOG.info("Loading Snmp Interface");
for (OnmsSnmpInterface snmp : m_snmpInterfaceDao.findAll()) {
// Index the SNMP interfaces by node id
final int nodeId = snmp.getNode().getId();
List<OnmsSnmpInterface> snmpinterfaces = nodesnmpmap.get(nodeId);
if (snmpinterfaces == null) {
snmpinterfaces = new ArrayList<>();
nodesnmpmap.put(nodeId, snmpinterfaces);
}
snmpinterfaces.add(snmp);
}
LOG.info("Snmp Interface loaded");
} catch (Exception e) {
LOG.error("Exception getting snmp interface list: " + e.getMessage(), e);
} finally {
context.stop();
}
context = m_loadIpNetToMediaTimer.time();
try {
Set<String> duplicatednodemac = new HashSet<String>();
Map<String, Integer> mactonodemap = new HashMap<String, Integer>();
LOG.info("Loading ip net to media");
for (IpNetToMedia ipnettomedia : m_ipNetToMediaDao.findAll()) {
if (duplicatednodemac.contains(ipnettomedia.getPhysAddress())) {
LOG.info("load ip net media: different nodeid found for ip: {} mac: {}. Skipping...", InetAddressUtils.str(ipnettomedia.getNetAddress()), ipnettomedia.getPhysAddress());
continue;
}
OnmsIpInterface ip = ipmap.get(ipnettomedia.getNetAddress());
if (ip == null) {
LOG.info("load ip net media: no nodeid found for ip: {} mac: {}. Skipping...", InetAddressUtils.str(ipnettomedia.getNetAddress()), ipnettomedia.getPhysAddress());
continue;
}
if (mactonodemap.containsKey(ipnettomedia.getPhysAddress())) {
if (mactonodemap.get(ipnettomedia.getPhysAddress()).intValue() != ip.getNode().getId().intValue()) {
LOG.info("load ip net media: different nodeid found for ip: {} mac: {}. Skipping...", InetAddressUtils.str(ipnettomedia.getNetAddress()), ipnettomedia.getPhysAddress());
duplicatednodemac.add(ipnettomedia.getPhysAddress());
continue;
}
}
if (!macipmap.containsKey(ipnettomedia.getPhysAddress())) {
macipmap.put(ipnettomedia.getPhysAddress(), new ArrayList<OnmsIpInterface>());
mactonodemap.put(ipnettomedia.getPhysAddress(), ip.getNode().getId());
}
macipmap.get(ipnettomedia.getPhysAddress()).add(ip);
}
for (String dupmac : duplicatednodemac) macipmap.remove(dupmac);
LOG.info("Ip net to media loaded");
} catch (Exception e) {
LOG.error("Exception getting ip net to media list: " + e.getMessage(), e);
} finally {
context.stop();
}
context = m_loadLldpLinksTimer.time();
try {
LOG.info("Loading Lldp link");
getLldpLinks(nodemap, nodesnmpmap, nodeipprimarymap);
LOG.info("Lldp link loaded");
} catch (Exception e) {
LOG.error("Exception getting Lldp link: " + e.getMessage(), e);
} finally {
context.stop();
}
context = m_loadOspfLinksTimer.time();
try {
LOG.info("Loading Ospf link");
getOspfLinks(nodemap, nodesnmpmap, nodeipprimarymap);
LOG.info("Ospf link loaded");
} catch (Exception e) {
LOG.error("Exception getting Ospf link: " + e.getMessage(), e);
} finally {
context.stop();
}
context = m_loadIsisLinksTimer.time();
try {
LOG.info("Loading Cdp link");
getCdpLinks(nodemap, nodesnmpmap, nodeipprimarymap, ipmap);
LOG.info("Cdp link loaded");
} catch (Exception e) {
LOG.error("Exception getting Cdp link: " + e.getMessage(), e);
} finally {
context.stop();
}
context = m_loadCdpLinksTimer.time();
try {
LOG.info("Loading IsIs link");
getIsIsLinks(nodesnmpmap, nodeipprimarymap);
LOG.info("IsIs link loaded");
} catch (Exception e) {
LOG.error("Exception getting IsIs link: " + e.getMessage(), e);
} finally {
context.stop();
}
context = m_loadBridgeLinksTimer.time();
try {
LOG.info("Loading Bridge link");
getBridgeLinks(nodemap, nodesnmpmap, macipmap, nodeipmap, nodeipprimarymap);
LOG.info("Bridge link loaded");
} catch (Exception e) {
LOG.error("Exception getting Bridge link: " + e.getMessage(), e);
} finally {
context.stop();
}
context = m_loadNoLinksTimer.time();
try {
LOG.debug("loadtopology: adding nodes without links: " + isAddNodeWithoutLink());
if (isAddNodeWithoutLink()) {
addNodesWithoutLinks(nodemap, nodeipmap, nodeipprimarymap);
}
} finally {
context.stop();
}
LOG.debug("Found {} groups", getGroups().size());
LOG.debug("Found {} vertices", getVerticesWithoutGroups().size());
LOG.debug("Found {} edges", getEdges().size());
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class EnhancedLinkdTopologyProvider method getEdgeTooltipText.
private String getEdgeTooltipText(LinkDetail<?> linkDetail, Map<Integer, List<OnmsSnmpInterface>> snmpmap) {
final StringBuilder tooltipText = new StringBuilder();
Vertex source = linkDetail.getSource();
Vertex target = linkDetail.getTarget();
OnmsSnmpInterface sourceInterface = getByNodeIdAndIfIndex(linkDetail.getSourceIfIndex(), source, snmpmap);
OnmsSnmpInterface targetInterface = getByNodeIdAndIfIndex(linkDetail.getTargetIfIndex(), target, snmpmap);
tooltipText.append(HTML_TOOLTIP_TAG_OPEN);
tooltipText.append(linkDetail.getType());
String layerText = " Layer 2";
if (sourceInterface != null && targetInterface != null) {
final List<OnmsIpInterface> sourceNonLoopback = sourceInterface.getIpInterfaces().stream().filter(iface -> {
return !iface.getNetMask().isLoopbackAddress();
}).collect(Collectors.toList());
final List<OnmsIpInterface> targetNonLoopback = targetInterface.getIpInterfaces().stream().filter(iface -> {
return !iface.getNetMask().isLoopbackAddress();
}).collect(Collectors.toList());
if (!sourceNonLoopback.isEmpty() && !targetNonLoopback.isEmpty()) {
// if both the source and target have non-loopback IP interfaces, assume this is a layer3 edge
layerText = " Layer3/Layer2";
}
}
tooltipText.append(layerText);
tooltipText.append(HTML_TOOLTIP_TAG_END);
tooltipText.append(HTML_TOOLTIP_TAG_OPEN);
tooltipText.append(source.getLabel());
if (sourceInterface != null) {
tooltipText.append("(");
tooltipText.append(sourceInterface.getIfName());
tooltipText.append(")");
}
tooltipText.append(HTML_TOOLTIP_TAG_END);
tooltipText.append(HTML_TOOLTIP_TAG_OPEN);
tooltipText.append(target.getLabel());
if (targetInterface != null) {
tooltipText.append("(");
tooltipText.append(targetInterface.getIfName());
tooltipText.append(")");
}
tooltipText.append(HTML_TOOLTIP_TAG_END);
if (targetInterface != null) {
if (targetInterface.getIfSpeed() != null) {
tooltipText.append(HTML_TOOLTIP_TAG_OPEN);
tooltipText.append(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(getHumanReadableIfSpeed(sourceInterface.getIfSpeed()));
tooltipText.append(HTML_TOOLTIP_TAG_END);
}
}
return tooltipText.toString();
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class NxosGpbAdapter method handleMessage.
@Override
public Optional<CollectionSetWithAgent> handleMessage(TelemetryMessage message, TelemetryMessageLog messageLog) throws Exception {
final TelemetryBis.Telemetry msg = tryParsingTelemetryMessage(message.getByteArray());
CollectionAgent agent = null;
try {
LOG.debug(" Telemetry message content : {} ", msg);
final InetAddress inetAddress = InetAddress.getByName(msg.getNodeIdStr());
final Optional<Integer> nodeId = interfaceToNodeCache.getFirstNodeId(messageLog.getLocation(), inetAddress);
if (nodeId.isPresent()) {
// NOTE: This will throw a IllegalArgumentException if the nodeId/inetAddress pair does not exist in the database
agent = collectionAgentFactory.createCollectionAgent(Integer.toString(nodeId.get()), inetAddress);
}
} catch (UnknownHostException e) {
LOG.debug("Could not convert system id to address: {}", msg.getNodeIdStr());
}
if (agent == null) {
// We were unable to build the agent by resolving the systemId, try finding
// a node with a matching label
agent = transactionTemplate.execute(new TransactionCallback<CollectionAgent>() {
@Override
public CollectionAgent doInTransaction(TransactionStatus status) {
OnmsNode node = Iterables.getFirst(nodeDao.findByLabelForLocation(msg.getNodeIdStr(), messageLog.getLocation()), null);
if (node == null) {
// If there is no matching label , Try matching with foreignId
node = Iterables.getFirst(nodeDao.findByForeignIdForLocation(msg.getNodeIdStr(), messageLog.getLocation()), null);
}
if (node != null) {
final OnmsIpInterface primaryInterface = node.getPrimaryInterface();
return collectionAgentFactory.createCollectionAgent(primaryInterface);
}
return null;
}
});
}
if (agent == null) {
LOG.warn("Unable to find node and interface for system id: {}", msg.getNodeIdStr());
return Optional.empty();
}
final ScriptedCollectionSetBuilder builder = scriptedCollectionSetBuilders.get();
if (builder == null) {
throw new Exception(String.format("Error compiling script '%s'. See logs for details.", script));
}
final CollectionSet collectionSet = builder.build(agent, msg);
return Optional.of(new CollectionSetWithAgent(agent, collectionSet));
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class IpLikeHopCriteria method getVertices.
@Override
public Set<VertexRef> getVertices() {
CriteriaBuilder bldr = new CriteriaBuilder(OnmsIpInterface.class);
bldr.iplike("ipAddr", m_ipQuery);
List<OnmsIpInterface> ips = ipInterfaceProvider.findMatching(bldr.toCriteria());
Set<VertexRef> vertices = new TreeSet<VertexRef>(new RefComparator());
for (OnmsIpInterface ip : ips) {
OnmsNode node = ip.getNode();
vertices.add(new DefaultVertexRef("nodes", String.valueOf(node.getId()), node.getLabel()));
}
return vertices;
}
use of org.opennms.netmgt.model.OnmsIpInterface in project opennms by OpenNMS.
the class PingOperation method execute.
@Override
public void execute(final List<VertexRef> targets, final OperationContext operationContext) {
final VertexRef target = targets.get(0);
final Vertex vertex = getVertexItem(operationContext, target);
final Optional<OnmsNode> node = getNodeIfAvailable(vertex);
final List<String> locations = monitoringLocationDao.findAll().stream().map(OnmsMonitoringLocation::getLocationName).collect(Collectors.toList());
final String defaultLocation = node.isPresent() ? node.get().getLocation().getLocationName() : MonitoringLocationDao.DEFAULT_MONITORING_LOCATION_ID;
final List<InetAddress> ipAddresses = node.isPresent() ? Lists.newArrayList(node.get().getIpInterfaces()).stream().map(OnmsIpInterface::getIpAddress).collect(Collectors.toList()) : Lists.newArrayList(InetAddressUtils.addr(vertex.getIpAddress()));
final InetAddress defaultIp = getDefaultIp(vertex, node);
final String caption = String.format("Ping - %s (%s)", vertex.getLabel(), vertex.getIpAddress());
new PingWindow(pingClient, locations, ipAddresses, defaultLocation, defaultIp, caption).open();
}
Aggregations