Skip to content

[WIP] Draft / prototype for device discovery #354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

mzbroch
Copy link
Contributor

@mzbroch mzbroch commented Apr 8, 2025

Prototype for device discovery built on-top of existing SSOT Job.

Current support is for SSH only (same as existing SSOT job), however more methods like SNMP can be added in the future if needed.

Assumptions:

  • There is an implemented opinion about network discovery workflow:

    • User to specify scanned prefixes
    • For targets discovered within prefixes, kickoff regular onboarding job
    • Skip existing Nautobot Device Primary IP4s from being scanned
  • Prefixes have to be created and are available for input selection

  • Integrates with existing device onboarding

  • Focuses on SSH running on 22, but can be extended for other ports and protocols

  • Crawling (CDP/LLDP) not being a priority

  • Re-uses hackaton project for threading

  • Does not integrate nmap/ scapy / scanners as these can might not allowed by Enterprise Security teams

  • Does not store models / information about discovered endpoints

  • Current support is for providing Prefix based on tags - this might need some thought process

TODO

  • Tests
  • Code to be finalised
  • Blacklist / skip flags for unwanted IPs

@chadell
Copy link
Contributor

chadell commented Apr 9, 2025

@mzbroch , I like your approach. I think that is fair to start using SSH discovery as an initial option and later add other methods if needed


# Dispatch SSH
if target_port_details["protocol"] == AutodiscoveryProtocolTypeChoices.SSH:
guessed_platform, exception, credentials = self._get_target_details_ssh(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we don't get proper details via SSH, should we remove the target from the self.targets? and log an issue? (because it seems to have the port SSH port open, but not able to connect with the credentials)

self.logger.error(f"Error with future for IP {host}: {e}")

if self.debug:
self.logger.info(f"Results: {results}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.logger.info(f"Results: {results}")
self.logger.debug(f"Results: {results}")

host = future_to_ip[future]
try:
results[host] = future.result()
except Exception as e:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which exception are you expecting?

"""Scan the selected IP Addresses for open protocol-ports - dispatcher method."""
scan_result = {}

with concurrent.futures.ThreadPoolExecutor(max_workers=self.scanning_threads_count) as executor:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems odd to me that we're not making these tasks nornir-tasks to keep the pattern the same.


return scan_result

def _parse_credentials(self, credentials):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would be the third time we define this same function in this app. Can you just import from

from nautobot_device_onboarding.nornir_plays.command_getter import _parse_credentials

)
raise OnboardException("fail-credentials - Unable to parse selected credentials.") from err

def _get_target_details_ssh(self, hostname, port):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

another one where we already have this

 from nautobot_device_onboarding.nornir_plays.inventory_creator import guess_netmiko_device_type

@scetron scetron mentioned this pull request Apr 11, 2025
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants