@Override public NodeDiscoveryResult discover(ConnectionDetails connectionDetails) { String ipAddressString = connectionDetails.getParams().get("ipAddress"); String dnsCanonicalDomainName = doReverseDnsLookup(ipAddressString); String dnsShortName = StringUtils.substringBefore(dnsCanonicalDomainName, "."); NodeDiscoveryResult result = new NodeDiscoveryResult(); if (dnsCanonicalDomainName != null && !dnsCanonicalDomainName.isEmpty() && !dnsCanonicalDomainName.equals(ipAddressString)) { result.setDiscoveredData("FQDN", dnsCanonicalDomainName); result.setDiscoveredData("PQDN", dnsShortName); result.setNodeId(dnsShortName); return result; } else { return null; } }
@Override public void nodeDiscovered(NodeDiscoveryResult discoveryResult) { String nodeId = discoveryResult.getNodeId(); if (nodeId!=null && discoveryResult.getDiscoveredData()!=null) try { updatelist(nodeId, discoveryResult.getDiscoveryConnectionDetails(),discoveryResult.getOwnConnectionDetails(), discoveryResult.getNeighboursConnectionDetails()); } catch (IOException e) { e.printStackTrace(); } }
@Override public void nodeDiscovered(NodeDiscoveryResult discoveryResult) { File baseDir = new File(projectPath, labelDirName); if (!baseDir.exists()) baseDir.mkdir(); File rawDataDir = new File(baseDir, rawDataDirName); if (!rawDataDir.exists()) rawDataDir.mkdir(); String deviceName = discoveryResult.getNodeId(); File file = new File(rawDataDir, deviceName+".xml"); if (discoveryResult.getDiscoveredData()!=null) { if (discoveryResult.getDiscoveredData("rawData") != null) { String rawDataXml = new String((byte[]) discoveryResult.getDiscoveredData("rawData")); try { FileUtils.writeStringToFile(file, rawDataXml); } catch (IOException e) { logger.error(e); } } else { logger.info("no raw data found!!! in for "+discoveryResult.getNodeId()); } } else { logger.info("no Discovered data found!!! for "+discoveryResult.getNodeId()); } }
@Override public NodeDiscoveryResult discover(ConnectionDetails connectionDetails) { Set<String> nodeAliases = new HashSet<>(); NodeDiscoveryResult nodeDiscoveryResult = new NodeDiscoveryResult(); Set<ConnectionDetails> neighbourConnectionDetails = new HashSet<>(); Set<ConnectionDetails> ownConnectionDetails = new HashSet<>(); nodeDiscoveryResult.setNodeId(connDetailsDeviceName); nodeDiscoveryResult.setNodeAliases(nodeAliases); return nodeDiscoveryResult; }else { String icmpNodeId = null; if (icmpDiscoveryResult!=null) { icmpNodeId = icmpDiscoveryResult.getNodeId(); Map<String, Object> icmpDiscoveryData = icmpDiscoveryResult.getDiscoveredData(); dnsNodeId = dnsDiscoveryResult.getNodeId(); if (dnsNodeId!=null && !dnsNodeId.isEmpty()) nodeAliases.add(dnsNodeId); Map<String, Object> dnsDiscoveryData = dnsDiscoveryResult.getDiscoveredData(); snmpNodeId = snmpDiscoveryResult.getNodeId(); if (snmpNodeId!=null && !snmpNodeId.isEmpty()) nodeAliases.add(snmpNodeId); Map<String, Object> snmpDiscoveryData = snmpDiscoveryResult.getDiscoveredData(); DiscoveredDevice discoveredDevice = (DiscoveredDevice) snmpDiscoveryData.get("DiscoveredDevice");
futureCounter--; NodeDiscoveryResult result = future.get(); this.fireNodeDiscoveredEvent((NodeDiscoveryResult) result.clone()); String nodeId = result.getNodeId(); String parentId = result.getParentId(); boolean neighbourIsDiscovered = checkIfNeighbourIsDiscovered(future, nodeId, parentId); logger.debug("Unable to discover node with parent: " + parentId + ", for connection details=" + result.getDiscoveryConnectionDetails()); continue; logger.debug("Node already discovered: nodeId=" + nodeId + ", for connection details=" + result.getDiscoveryConnectionDetails()); continue; Set<String> nodeAliases = result.getNodeAliases(); this.updateNodesStructure(parentId, nodeId, nodeAliases); nodeDiscoveryResultMap.put(nodeId, result); ArrayList<Future<NodeDiscoveryResult>> neighbourFutures = createNewDiscoveryWorkers(nodeId, result.getNeighboursConnectionDetails(), result.getOwnConnectionDetails()); logger.info("Adding node neighbours for discovery... nodeId=" + nodeId + ", neighbour future size=" + neighbourFutures.size()); if (neighbourFutures.size() > 0) {
NodeDiscoveryResult result = new NodeDiscoveryResult(); result.setOwnConnectionDetails(ownConnectionDetails); result.setNeighboursConnectionDetails(neighboursConnDetails); result.setDiscoveredData("deviceData", discoveredDeviceData); result.setDiscoveredData("DiscoveredDevice", discoveredDevice); result.setDiscoveredData("rawData", rawData.getData()); result.setNodeId(deviceId); return result;
@Override public NodeDiscoveryResult call() { logger.debug("Discovery worker: " + Thread.currentThread().getName() + " started. connectionDetails = " + connectionDetails); String connectionType = connectionDetails.getConnectionType(); NodeDiscoverer nodeDiscoverer = discoverers.get(connectionType); NodeDiscoveryResult nodeDiscoveryResult = null; try { if (nodeDiscoverer == null) { logger.debug("No node discoverer can be found for connectionType: " + connectionDetails); logger.debug("Trying with the discoverer with connectionType any"); nodeDiscoverer = discoverers.get("any"); nodeDiscoveryResult = nodeDiscoverer.discover((ConnectionDetails) connectionDetails.clone()); } else { nodeDiscoveryResult = nodeDiscoverer.discover((ConnectionDetails) connectionDetails.clone()); } }catch (Exception e){ logger.error(e.getMessage(),e); } if (nodeDiscoveryResult == null) { nodeDiscoveryResult = new NodeDiscoveryResult(null, null,null); } nodeDiscoveryResult.setParentId(parentId); nodeDiscoveryResult.setDiscoveryConnectionDetails(connectionDetails); return nodeDiscoveryResult; }
@Override public NodeDiscoveryResult discover(ConnectionDetails connectionDetails) { String protocolType = connectionDetails.getParam("protocolType"); String subnetIpAddress = connectionDetails.getParam("ipAddress"); String subnetPrefixMask = connectionDetails.getParam("subnetPrefixMask"); String subnetPrefix=subnetIpAddress+"/"+subnetPrefixMask; NodeDiscoveryResult nodeDiscoveryResult = new NodeDiscoveryResult(subnetPrefix,null,null); nodeDiscoveryResult.setDiscoveredData("subnetDetails", connectionDetails.getParams()); int discoverySubnetPrefixSize = Integer.parseInt(subnetPrefixMask); if (generateIPconnectionsForSubnetMembers && discoverySubnetPrefixSize<=subnetMaxMaskSize); nodeDiscoveryResult.setNeighboursConnectionDetails(getSubnetIpNeighborConnections(subnetPrefix)); try { InetAddress inetAddress = InetAddress.getByName(subnetIpAddress); if (inetAddress instanceof Inet4Address) { IPv4BogonIdentitifier iPv4BogonIdentitifier = new IPv4BogonIdentitifier(subnetIpAddress); if (iPv4BogonIdentitifier.identifyBogon()) { nodeDiscoveryResult.setDiscoveredData("bogon", "YES"); } } if (privateSubnetIdentifier(subnetIpAddress)) { nodeDiscoveryResult.setDiscoveredData("private", "YES"); } } catch (UnknownHostException e) { logger.error(e); } return nodeDiscoveryResult; }
if (nodeId ==null) nodeId = discoveryResult.getNodeId(); Node currentNode = new Node(nodeId); nodes.put(nodeId, currentNode); initialNode.addNeighbour(currentNode); Set<ConnectionDetails> neighboursConnectionDetails = discoveryResult.getNeighboursConnectionDetails(); logger.debug("Found Neighbours, connection details: " + neighboursConnectionDetails); if (neighboursConnectionDetails != null) {
String deviceName = connectionDetails.getParam("deviceName"); NodeDiscoveryResult result = new NodeDiscoveryResult(); result = new NodeDiscoveryResult(deviceName, null,null); }else if (dnsCanonicalName!=null){ result = new NodeDiscoveryResult(dnsShortName, null,null); }else { result = new NodeDiscoveryResult(ipAddressStr, null,null); result = new NodeDiscoveryResult(deviceName, neighboursConnDetails,null); result.setDiscoveredData("deviceData", discoveredDeviceData); result.setDiscoveredData("rawData", rawData.getData()); return result;
@Override public void nodeDiscovered(NodeDiscoveryResult discoveryResult) { synchronized (this) { if (discoveryResult.getNodeId() != null) { logger.info("Node is discovered: " + discoveryResult); } else { logger.info("Node is not discovered: " + discoveryResult); } } } }
@Override public void networkDiscovered(NetworkDiscoveryResult result) { File baseDir = new File(projectPath); if (!baseDir.exists()) baseDir.mkdir(); File labelDirPath = new File(baseDir, labelDirName); if (!labelDirPath.exists()) labelDirPath.mkdir(); File graphmlDir = new File(labelDirPath, graphmlDirName); if (!graphmlDir.exists()) graphmlDir.mkdir(); Map<String, NodeDiscoveryResult> discoveryResultMap = result.getDiscoveredData(); for (String node : discoveryResultMap.keySet()) { byte[] discoveredDeviceData = (byte []) discoveryResultMap.get(node).getDiscoveredData("graphml"); try { final String fileName = ProjectConstants.networkGraphmlFileName; final File nodeFile = new File(graphmlDir,fileName); String graphml = new String(discoveredDeviceData); FileUtils.writeStringToFile(nodeFile, graphml); FileWriter writer = new FileWriter(new File(labelDirPath,"undirected"+".graphmls"),true); writer.append(String.valueOf(fileName)).append("\n"); writer.close(); } catch (IOException e) { e.printStackTrace(); } } }
@Override public void nodeDiscovered(NodeDiscoveryResult discoveryResult) { File connectionDetailsFile = new File(projectPath, connectionDetailsPath); PrintWriter out = null; try { out = new PrintWriter(new BufferedWriter(new FileWriter(connectionDetailsFile, true))); Set<ConnectionDetails> neighboursConnDetails = discoveryResult.getNeighboursConnectionDetails(); for (ConnectionDetails neighboursConnDetail : neighboursConnDetails) { StringBuffer connDetails = new StringBuffer(); String connectionDetailsType = neighboursConnDetail.getConnectionType(); Map<String, String> connectionDetailsParams = neighboursConnDetail.getParams(); String connectionDetailsName = connectionDetailsParams.get("deviceName"); connDetails.append("name=" + connectionDetailsName + ",type=" + connectionDetailsType+":"); int size =0; for ( String s : connectionDetailsParams.keySet()) { if (connectionDetailsParams.size()!=size) connDetails.append(s+"="+connectionDetailsParams.get(s)+","); else connDetails.append(s+"="+connectionDetailsParams.get(s)); size++; } out.println(connDetails.toString()); } } catch (IOException e) { e.printStackTrace(); } finally { out.close(); } }
@Override public void nodeDiscovered(NodeDiscoveryResult discoveryResult) { File baseDir = new File(projectPath, labelDirName); if (!baseDir.exists()) baseDir.mkdir(); File deviceDataDir = new File(baseDir, deviceDataDirName); if (!deviceDataDir.exists()) deviceDataDir.mkdir(); String deviceName = discoveryResult.getNodeId(); if (deviceName==null) return; File file = new File(deviceDataDir, "device-data-"+deviceName+".xml"); if (discoveryResult.getDiscoveredData("deviceData")!=null) { DiscoveredDeviceData discoveredDeviceData = (DiscoveredDeviceData) discoveryResult.getDiscoveredData("deviceData"); // ByteArrayOutputStream graphMLOutputStream = new ByteArrayOutputStream(); OutputStream os = null; try { os = new FileOutputStream(file); JaxbMarshalar.marshal(discoveredDeviceData, os, "DiscoveredDevice"); } catch (FileNotFoundException e) { logger.error(e.getMessage(), e); } catch (JAXBException e) { logger.error(e.getMessage(), e); } finally { if (os != null) try { os.close(); } catch (IOException e) { } } } }
protected void fireNeighboursDiscoveredEvent(final NodeDiscoveryResult nodeDiscoveryResult) { if (nodeNeighbourDiscoveryListeners != null) { String nodeId = nodeDiscoveryResult.getNodeId(); final Node node = nodes.get(nodeId); for (final NodeNeighboursDiscoveryListener nodeNeighboursDiscoveryListener : nodeNeighbourDiscoveryListeners) { nodeNeighboursDiscoveryListener.handleNodeNeighboursDiscovered(node, nodeDiscoveryResult); } } }
String discoveredIPv4Address = (String) nodeDiscoveryResult.getDiscoveredData().get("discoveredIPv4Address"); DiscoveredDevice discoveredDevice = (DiscoveredDevice) nodeDiscoveryResult.getDiscoveredData().get("DiscoveredDevice"); Map<String, String> subnetDetails = (Map<String, String>) nodeDiscoveryResult.getDiscoveredData().get("subnetDetails"); String icmpStatus = (String) nodeDiscoveryResult.getDiscoveredData().get("icmpStatus"); String dnsFQDN = (String) nodeDiscoveryResult.getDiscoveredData().get("FQDN"); String dnsPQDN = (String) nodeDiscoveryResult.getDiscoveredData().get("PQDN"); String bogonSubnetMarker = (String) nodeDiscoveryResult.getDiscoveredData().get("bogon"); String privateSubnetMarker = (String) nodeDiscoveryResult.getDiscoveredData().get("private");
@Override public void nodeDiscovered(NodeDiscoveryResult discoveryResult) { String nodeId = discoveryResult.getNodeId(); if (nodeId!=null) try { updatelist(nodeId, discoveryResult.getDiscoveryConnectionDetails(),discoveryResult.getOwnConnectionDetails(), discoveryResult.getNeighboursConnectionDetails()); } catch (IOException e) { e.printStackTrace(); } }
String deviceName = discoveryResult.getNodeId(); String rawDataXml = new String((byte[]) discoveryResult.getDiscoveredData("rawData"));
NodeDiscoveryResult result = new NodeDiscoveryResult(); result.setNodeId(ipAddressStr); result.setDiscoveredData("icmpStatus", "REACHABLE"); return result ;
protected void fireNeighboursDiscoveredEvent(final NodeDiscoveryResult nodeDiscoveryResult) { if (nodeNeighbourDiscoveryListeners != null) { String nodeId = nodeDiscoveryResult.getNodeId(); final Node node = nodes.get(nodeId); for (final NodeNeighboursDiscoveryListener nodeNeighboursDiscoveryListener : nodeNeighbourDiscoveryListeners) { eventFutureCount++; eventExecutorCompletionService.submit(new Runnable() { @Override public void run() { try { nodeNeighboursDiscoveryListener.handleNodeNeighboursDiscovered(node, nodeDiscoveryResult); }catch (RuntimeException rte){ logger.error(rte.getMessage(),rte); } } }, null); } } }