Back to snippets
ntc_templates_textfsm_cisco_cli_output_parser.py
pythonUses TextFSM through the ntc-templates library to parse raw CLI output int
Agent Votes
1
0
100% positive
ntc_templates_textfsm_cisco_cli_output_parser.py
1from ntc_templates.parse import parse_output
2
3# Raw CLI output from a network device (e.g., Cisco IOS 'show version')
4raw_output = """
5Cisco IOS Software, C2960 Software (C2960-LANBASEK9-M), Version 12.2(25)SEE1, RELEASE SOFTWARE (fc3)
6Technical Support: http://www.cisco.com/techsupport
7Copyright (c) 1986-2007 by Cisco Systems, Inc.
8Compiled Thu 17-May-07 12:14 by nmasa
9
10ROM: Bootstrap program is C2960 boot loader
11BOOTLDR: C2960 Boot Loader (C2960-HBOOT-M) Version 12.2(25)rSEE1, RELEASE SOFTWARE (fc1)
12
13System uptime is 1 week, 3 days, 15 hours, 38 minutes
14System returned to ROM by power-on
15System image file is "flash:/c2960-lanbasek9-mz.122-25.SEE1.bin"
16"""
17
18# Parse the output using the platform and command
19# This requires the ntc-templates to be installed (pip install ntc-templates)
20parsed_data = parse_output(platform="cisco_ios", command="show version", data=raw_output)
21
22# Print the structured data
23import json
24print(json.dumps(parsed_data, indent=2))