Skip to content

Commit

Permalink
Merge pull request #3 from ClayJay3/support/nexus-os
Browse files Browse the repository at this point in the history
Support/nexus os
  • Loading branch information
ClayJay3 authored Jun 30, 2023
2 parents e8387c5 + a74fb28 commit 0935261
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ gevent = "*"
pyvis = "*"
auto-py-to-exe = "*"
selenium = "*"
cryptography = "*"

[dev-packages]

Expand Down
6 changes: 0 additions & 6 deletions test.py

This file was deleted.

31 changes: 22 additions & 9 deletions utils/net_crawl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from functools import partial
from os import device_encoding
import re
import time
import logging
from multiprocessing.pool import ThreadPool
from netmiko.exceptions import NetmikoAuthenticationException, NetmikoTimeoutException, ReadTimeout
Expand Down Expand Up @@ -214,6 +215,14 @@ def get_cdp_neighbors_info(usernames, passwords, enable_secrets, enable_telnet,
# Get parent hostname.
prompt = connection.find_prompt()[:-1]

# Sometimes switches or login prompt will confuse netmiko. Retry until we found the actual prompt.
retries = 0
while "http" in prompt and retries < 10:
# Find prompt.
prompt = connection.find_prompt()[:-1]
# Sleep for output.
time.sleep(1)

# Create base dictionaries
license_dict = {"ip_addr": ip_addr, "license_state": "NULL", "expire_period": "NULL", "raw_output": "NULL"}
serial_dict = {"ip_addr": ip_addr, "system_serial": "NULL", "motherboard_serial": "NULL", "powersupply_serial": "NULL"}
Expand Down Expand Up @@ -518,9 +527,10 @@ def get_cdp_neighbors_info(usernames, passwords, enable_secrets, enable_telnet,
# Loop through each line and find the device info.
for line in info:
# Find device IP address.
if "IP address:" in line:
if ("IP address:" in line or "IPv4 Address" in line) and addr == "NULL":
# Replace keyword.
addr = line.replace("IP address: ", "").strip()
addr = addr.replace("IPv4 Address:", "").strip()
# Attempt to determine if the device is a switch.
if "Platform" in line and "Switch" in line:
is_switch = True
Expand All @@ -533,14 +543,16 @@ def get_cdp_neighbors_info(usernames, passwords, enable_secrets, enable_telnet,
# Check if export info is toggled on.
if export_info and len(addr) > 0:
# Find device hostname.
if "ID:" in line:
if "ID:" in line and hostname == "NULL":
# Replace keyword.
line = line.replace("ID:", "")
# Remove any parenthesis and text inside parenthesis.
line = re.sub("[\(\[].*?[\)\]]", "", line)
# Remove whitespace and store data.
hostname = line.strip()

# Find device software version info.
if "Version :" not in line and "Version" in line:
if "Version :" not in line and "Version:" not in line and "Version" in line:
# Split line up by commas.
line = re.split(",", line)
# Loop through and find software name and version.
Expand Down Expand Up @@ -609,13 +621,14 @@ def get_cdp_neighbors_info(usernames, passwords, enable_secrets, enable_telnet,
device_info["parent_host"] = parent_host
device_info["parent_trunk_interface"] = parent_trunk_interface

# Remove leading whitespace and append final ip to the cdp info list.
if addr != "NULL" and is_switch:
cdp_neighbors_result_ips.append(addr)
if "mgmt" not in local_trunk_interface and "mgmt" not in parent_trunk_interface:
# Remove leading whitespace and append final ip to the cdp info list.
if addr != "NULL" and is_switch:
cdp_neighbors_result_ips.append(addr)

# Append device to the device infos list.
if export_info and device_info["hostname"] != "NULL" and device_info not in device_infos:
device_infos.append(device_info)
# Append device to the device infos list.
if export_info and device_info["hostname"] != "NULL" and device_info not in device_infos:
device_infos.append(device_info)

# Close ssh connection.
connection.disconnect()
Expand Down

0 comments on commit 0935261

Please sign in to comment.