Overview
I wrote Python scripts that log in to a Cisco IOS router (R1) with Netmiko, run show version and show ip interface brief, turn the interface table into structured data with TextFSM and save it as a JSON report. My later version reads the device details from a JSON inventory file. The repository lists more stages I plan to add, such as Ansible and NETCONF. So far only the Python stage is published.
What I set out to do
- Collect device information automatically instead of typing commands by hand.
- Read the devices from an inventory file instead of hard-coding them.
What I did
- device_info.py connects to R1, runs the show commands and picks out the hostname, IOS version, uptime and interfaces.
- inventory_reader.py and inventory_connection.py read inventory/devices.json and open a Netmiko session.
- collect_device_info.py puts both together and writes api/<hostname>-device-info.json.
Screenshots
They are in the same order as in my repository. Click one to see it full size.
1. Python Device Information AutomationShows Python connecting to Cisco R1 using Netmiko and collecting device information. 2. Structured Device InformationShows the structured device information generated from the Cisco device. 3. Inventory-Driven Netmiko ConnectionShows Python reading the device inventory and successfully establishing a Netmiko connection to Cisco R1. 4. Inventory-Driven Device InformationShows the inventory-driven automation collecting and structuring Cisco R1 device information and generating the JSON report.
How I tested it
- My screenshots show the Netmiko connection to R1 and the structured output.
- The report api/r1-device-info.json shows IOS 17.15.1 and four interfaces with their status.
Repository
My full notes and the original screenshots are on GitHub: network-infrastructure-and-automation