Python - Parsing output of show commands

In the context of network monitoring and automation, it can be useful to use specialized tools to parse the output of show commands on a Cisco IOS device in conjunction with Python.

There are several tools that can be used for this purpose:

  1. TextFSM: TextFSM is a Python module developed by Google which is widely used for parsing semi-structured text data like the output from “show” commands in Cisco IOS. It allows you to define a template that maps the output into a structured format, making it easier to process and analyze. TextFSM is particularly powerful for parsing complex and varied text outputs.

  2. Netmiko: While primarily a library for handling SSH connections to network devices, Netmiko can be used in conjunction with TextFSM to send commands and parse the output. Netmiko simplifies the process of connecting to a device, executing commands, and retrieving the output.

  3. PyATS/Genie: Developed by Cisco, PyATS is a Python automation framework designed specifically for network testing. Genie is part of the PyATS ecosystem and provides libraries for modeling and parsing network devices’ configurations and operational state. Genie can parse the output of “show” commands into structured JSON data, making it easier to work with programmatically.

  4. Nornir: Nornir is a pluggable multi-threaded framework with inventory management to help operate collections of devices. It can use Netmiko and other plugins to connect to devices, send commands, and parse the output.

  5. Ansible with ios_command module: Although Ansible is not a Python library per se, it is a powerful automation tool that can be used for network automation tasks. The ios_command module in Ansible allows you to run commands on remote Cisco IOS devices and can be used in conjunction with parsing filters to structure the output.