This lesson is part of the Network Configuration with Netmiko Course.
In this lesson, we will cover:
- What is TextFSM?
- How to use TextFSM parsers in Netmiko.
- How to build a custom TextFSM parsing template.
The scripts and code for this lesson can be found within the Netmiko repo under the directory: examples/003_parsing/textfsm
.
TextFSM Overview
TextFSM is a Python module developed by Google that allows you to take unstructured data and convert it to structured data via sets of regex-based templates. An example of a TextFSM template for parsing the output of show_version
on an EOS is shown below:
Value MODEL (\S+)
Value HW_VERSION (\S+)
Value SERIAL_NUMBER (\S+)
Value SYS_MAC (\S+)
Value IMAGE (\S+)
Value TOTAL_MEMORY (\d+)
Value FREE_MEMORY (\d+)
Start
^Arista\s+${MODEL}
^Hardware\s+version:\s+${HW_VERSION}
^Serial\s+number:\s+${SERIAL_NUMBER}
^System\s+MAC\s+address:\s+${SYS_MAC}
^Software\s+image\s+version:\s+${IMAGE}
^Total\s+memory:\s+${TOTAL_MEMORY}
^Free\s+memory:\s+${FREE_MEMORY} -> Record