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
Ready to Master Network Automation? Start Your Journey Today!
Our membership provides:
  • Full deep-dive course library (inc. Batfish, pyATS, Netmiko)
  • Code repositories inc. full course code, scripts and examples
  • 24x7 multi-vendor labs (Arista, Cisco, Juniper)
  • Private online community
  • Live monthly tech sessions
  • Access to tech session library

Join Now ➜
Close You've successfully subscribed to Packet Coders.
Close Success! Your account is fully activated, you now have access to all content.
Close Welcome back! You've successfully signed in.
Close Nearly there! To activate your account, please click the link in the email we just sent you.