Many NetworkToCode NTC templates have a line such as ^. -> Error (Example). This line means that any line of output which does not match a previous expression results in a TextFSM error action. It's understandable why someone writing and testing template would want this behavior, so they could identify improvements needed.
However, I just want to collect the data that does match the template even if the network device output also includes other lines that don't match. (Typically this happens because the device vendor puts out an update which changes the text header/footer slightly: unstructured data that's not worth capturing anyway).
My current workaround is to modify the templates directly by deleting or commenting out the wildcard error lines. (One could also add lines to match the non-matching output). But this is inconvenient because many templates need to be modified this way, the code is less portable, updating the ntc templates package will result in the templates being overwritten, etc.
Is there a way to handle TextFSM errors in such a way that will still result in capturing the matching data?
Example Code: (command output data copied from here)
from ntc_templates.parse import parse_output
data = """IP-EIGRP neighbors for process 65535 VRF default
H Address Interface Hold Uptime SRTT RTO Q Seq
(sec) (ms) Cnt Num
7 10.20.150.2 Po2001 12 03:44:02 20 200 0 10331
6 10.20.200.2 Po2000 14 03:44:14 13 200 0 158157
5 10.40.1.1 Eth1/26 13 03:44:14 16 200 0 158164
4 10.50.2.1 Eth2/5 12 03:44:14 16 200 0 158166
3 10.50.1.1 Eth2/6 13 03:44:15 16 200 0 158165
2 10.50.3.1 Eth2/7 11 03:44:15 13 200 0 158167
1 10.20.5.2 Eth3/11 14 03:44:16 18 200 0 158158
0 10.20.6.2 Eth3/12 11 28w4d 14 200 0 158163"""
parse_output(platform='cisco_nxos',command='show ip eigrp neighbors', data = data)
Output:
raise TextFSMError('State Error raised. Rule Line: %s. Input Line: %s'
textfsm.parser.TextFSMError: State Error raised. Rule Line: 20. Input Line: 0 10.20.6.2 Eth3/12 11 28w4d 14 200 0 158163
I'm not trying to debug this specific example! If you're curious, it's because the current template is written to expect an all-number time format in the uptime field: (\d+:\d+:\d+), and this doesn't match the format used for longer time periods. The uptime field should be (\S+) or something more flexible.
What I'm trying to do is record the captured data that does match the template, even when there is a line that triggers the wildcard error action. Is there a way to do this without modifying the template directly?