question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

use_textfsm parses different result from ntc-templates

See original GitHub issue

I am using use_textfsm=True parameter in send_command to get parsed output of show version command from Cisco devices. In most cases it works like a charm except for the case in the issue.

facts = conn.send_command(command_string="show version", use_textfsm=True)

printing the facts variable I get (incorrect output):

All serial numbers and MAC addresses are just placeholders.

[
    {
        "config_register": "",
        "hardware": ["C9500-32QC"],  # <-- 1 device
        "hostname": "Main-DataCenter-core-SW",
        "mac": ["c0:80:c0:80:c0:80", "be:00:be:00:be:00"],  # <-- 2 mac addrs
        "reload_reason": "PowerOn",
        "restarted": "",
        "rommon": "IOS-XE",
        "running_image": "packages.conf",
        "serial": ["ABC12345D0E"],  # <-- 1 serial number
        "uptime": "4 weeks, 3 days, 1 hour, 2 minutes",
        "uptime_days": "3",
        "uptime_hours": "1",
        "uptime_minutes": "2",
        "uptime_weeks": "4",
        "uptime_years": "",
        "version": "17.3.1",
    }
]

On the other hand, when I use ntc-templates v2.3.1 outside of netmiko, I get the correct parsed output:

from pprint import pprint

from ntc_templates.parse import parse_output

input_data = """
Cisco IOS XE Software, Version 17.03.01
Cisco IOS Software [Amsterdam], Catalyst L3 Switch Software (CAT9K_IOSXE), Version 17.3.1, RELEASE SOFTWARE (fc5)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2020 by Cisco Systems, Inc.
Compiled Fri 07-Aug-20 21:32 by mcpre


Cisco IOS-XE software, Copyright (c) 2005-2020 by cisco Systems, Inc.
All rights reserved.  Certain components of Cisco IOS-XE software are
licensed under the GNU General Public License ("GPL") Version 2.0.  The
software code licensed under GPL Version 2.0 is free software that comes
with ABSOLUTELY NO WARRANTY.  You can redistribute and/or modify such
GPL code under the terms of GPL Version 2.0.  For more details, see the
documentation or "License Notice" file accompanying the IOS-XE software,
or the applicable URL provided on the flyer accompanying the IOS-XE
software.


ROM: IOS-XE ROMMON
BOOTLDR: System Bootstrap, Version 17.3.1r[FC2], RELEASE SOFTWARE (P)

Main-DataCenter-core-SW uptime is 4 weeks, 3 days, 1 hour, 2 minutes
Uptime for this control processor is 4 weeks, 3 days, 1 hour, 5 minutes
System returned to ROM by PowerOn
System image file is "bootflash:packages.conf"
Last reload reason: PowerOn



This product contains cryptographic features and is subject to United
States and local country laws governing import, export, transfer and
use. Delivery of Cisco cryptographic products does not imply
third-party authority to import, export, distribute or use encryption.
Importers, exporters, distributors and users are responsible for
compliance with U.S. and local country laws. By using this product you
agree to comply with applicable laws and regulations. If you are unable
to comply with U.S. and local laws, return this product immediately.

A summary of U.S. laws governing Cisco cryptographic products may be found at:
http://www.cisco.com/wwl/export/crypto/tool/stqrg.html

If you require further assistance please contact us by sending email to
export@cisco.com.


Technology Package License Information:

------------------------------------------------------------------------------
Technology-package                                     Technology-package
Current                        Type                       Next reboot
------------------------------------------------------------------------------
network-advantage       Smart License                    network-advantage
dna-advantage           Subscription Smart License       dna-advantage
AIR License Level: AIR DNA Advantage
Next reload AIR license Level: AIR DNA Advantage


Smart Licensing Status: UNREGISTERED/EVAL MODE

cisco C9500-32QC (X86) processor with 2000000K/6000K bytes of memory.
Processor board ID ABC12345D0E
1 Virtual Ethernet interfaces
11 Forty Gigabit Ethernet interfaces
11 Hundred Gigabit Ethernet interfaces
11111K bytes of non-volatile configuration memory.
11111111K bytes of physical memory.
11111111K bytes of Bootflash at bootflash:.
11111111K bytes of Bootflash at bootflash-2:.
1111111K bytes of Crash Files at crashinfo:.
1111111K bytes of Crash Files at crashinfo-2:.

Base Ethernet MAC Address          : c0:80:c0:80:c0:80
Motherboard Assembly Number        : 40A0
Motherboard Serial Number          : ABC12345D0E
Model Revision Number              : V01
Motherboard Revision Number        : 1
Model Number                       : C9500-32QC
System Serial Number               : ABC12345D0E

Switch 02
---------
Base Ethernet MAC Address          : be:00:be:00:be:00
Motherboard Assembly Number        : 40A0
Motherboard Serial Number          : FGH67890I0J
Model Revision Number              : V01
Motherboard Revision Number        : 1
Model Number                       : C9500-32QC
System Serial Number               : FGH67890I0J
"""

facts = parse_output(platform="cisco_ios", command="show version", data=input_data)

pprint(facts)

Output:

[
    {
        "config_register": "",
        "hardware": ["C9500-32QC", "C9500-32QC"],  # <-- 2 devices
        "hostname": "Main-DataCenter-core-SW",
        "mac": ["c0:80:c0:80:c0:80", "be:00:be:00:be:00"],  # <-- 2 mac addrs
        "reload_reason": "PowerOn",
        "restarted": "",
        "rommon": "IOS-XE",
        "running_image": "packages.conf",
        "serial": ["ABC12345D0E", "FGH67890I0J"],  # <-- 2 serial numbers
        "uptime": "4 weeks, 3 days, 1 hour, 2 minutes",
        "uptime_days": "3",
        "uptime_hours": "1",
        "uptime_minutes": "2",
        "uptime_weeks": "4",
        "uptime_years": "",
        "version": "17.3.1",
    }
]

Would could be the issue? I have created an issue on ntc-templates #924 and it’s solved already.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ktbyerscommented, Sep 13, 2021

Another option is to point directly at the Template file using the following argument to send_command

textfsm_template="/path/to/textfsm/template/file",
use_textfsm=True,
0reactions
Tes3awycommented, Sep 30, 2021

Another option is to point directly at the Template file using the following argument to send_command

textfsm_template="/path/to/textfsm/template/file",
use_textfsm=True,

This one worked. Thanks a lot ❤️

BR, Osama

Read more comments on GitHub >

github_iconTop Results From Across the Web

Parsing Strategies - NTC Templates using TextFSM
This post will dive deeper into using NTC Templates to parse unstructured data into usable, structured data. NTC Templates uses TextFSM under ...
Read more >
python - Parse output with TextFSM from different sections
It is also possible to use different templates on the same data, in order to create different tables (or views). **.
Read more >
Netmiko and TextFSM - Python for Network Engineers
How to use Netmiko with TextFSM? Now that both Netmiko and ntc-templates have been installed, how do we tell Netmiko to use the...
Read more >
Examples of TextFSM usage - Python for network engineers
This section discusses examples of templates and TextFSM usage. Section uses parse_output.py script to process command output by template.
Read more >
network-automation-blog - Anirudh Kamath
Using TextFSM, we can describe the manner using which information can be ... the flexibility to define the different states the template can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found