Repository navigation
Expand file tree
/
Copy pathhost_troubleshooting.py
More file actions
executable file
·103 lines (89 loc) · 3.39 KB
/
Copy pathhost_troubleshooting.py
File metadata and controls
executable file
·103 lines (89 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#! /usr/bin/env python
"""
Discover details about Cisco DNA Center connected hosts.
"""
# Import and functions
from dnac import DNAC
# Entry point for program
if __name__ == "__main__":
# Setup Arg Parse for Command Line parameters
import argparse
parser = argparse.ArgumentParser()
# Command Line Parameters for Source and Destination IP
parser.add_argument("source_ip", help="Source IP Address")
parser.add_argument("destination_ip", help="Destination IP Address")
parser.add_argument(
"--dnac", help="Address for Cisco DNA Center", required=True
)
parser.add_argument(
"--port",
help="Override default port of 443 for Cisco DNA Center",
required=False,
default=443,
)
parser.add_argument(
"--username", help="Username for Cisco DNA Center", required=True
)
parser.add_argument(
"--password", help="Password for Cisco DNA Center", required=True
)
args = parser.parse_args()
# Get Source and Destination IPs from Command Line
source_ip = args.source_ip
destination_ip = args.destination_ip
# Print Starting message
print("Running Troubleshooting Script for ")
print(" Source IP: {} ".format(source_ip))
print(" Destination IP: {}".format(destination_ip))
print("")
# Initialize Cisco DNA Center Object
dnac = DNAC(
address=args.dnac,
port=args.port,
username=args.username,
password=args.password,
)
# Step 1: Identify involved hosts
# Retrieve Host Details from dnac
source_host = dnac.host_list(ip=source_ip)
destination_host = dnac.host_list(ip=destination_ip)
# Verify single host found for each IP
dnac.verify_single_host(source_host, source_ip)
dnac.verify_single_host(destination_host, destination_ip)
# Print Out Host details
print("Source Host Details:")
print("-" * 25)
dnac.print_host_details(source_host[0])
print("Destination Host Details:")
print("-" * 25)
dnac.print_host_details(destination_host[0])
# Step 2: Where are they in the network?
# Retrieve and Print Source Device Details from dnac
source_host_net_device = dnac.network_device_list(
id=source_host[0]["connectedNetworkDeviceId"]
) # noqa: E501
print("Source Host Network Connection Details:")
print("-" * 45)
dnac.print_network_device_details(source_host_net_device[0])
# If Host is wired, collect interface details
if source_host[0]["hostType"] == "wired":
source_host_interface = dnac.interface_details(
id=source_host[0]["connectedInterfaceId"]
) # noqa: E501
print("Attached Interface:")
print("-" * 20)
dnac.print_interface_details(source_host_interface)
destination_host_net_device = dnac.network_device_list(
id=destination_host[0]["connectedNetworkDeviceId"]
) # noqa: E501
print("Destination Host Network Connection Details:")
print("-" * 45)
dnac.print_network_device_details(destination_host_net_device[0])
# If Host is wired, collect interface details
if destination_host[0]["hostType"] == "wired":
destination_host_interface = dnac.interface_details(
id=destination_host[0]["connectedInterfaceId"]
) # noqa: E501
print("Attached Interface:")
print("-" * 20)
dnac.print_interface_details(destination_host_interface)