ntc-templates icon indicating copy to clipboard operation
ntc-templates copied to clipboard

cisco_ios_show_interface_link template breaks when there are subinterfaces

Open brianatlarge opened this issue 1 year ago • 3 comments

ISSUE TYPE
  • Template Issue with error and raw data
TEMPLATE USING
Value PORT ([a-zA-Z]{2,3}[0-9]{1,2}\/[0-9]{1,2}(\/[0-9]{1,2})?)
Value NAME (.+?)
Value DOWNTIME ((00:00:00)|(([0-9]{1,2} year[s]? , )?([0-9]{1,2} week[s]?, )?([0-9]{1,2} day[s]?, )?([0-9]{1,2} hour[s]?, )?([0-9]{1,2} minute[s]? )?([0-9]{1,2} secs))|((([0-9]{1,2}y)?([0-9]{1,2}w)?([0-9]{1,2}d)([0-9]{1,2}h)?|[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2})))
Value SINCE (.+?)
Value UPTIME ((([0-9]{1,2}m)?([0-9]{1,2}w)?([0-9]{1,2}d)|[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}))

Start
  ^\s*\^\s* -> EOF
  ^.*Invalid input detected.* -> EOF
  ^Load\s+for\s+
  # Capture time-stamp if vty line has command time-stamping turned on
  ^Time\s+source\s+is
  ^-+\s*$$
  ^\s*Port\s+Name\s+Down Time\s+Down Since\s*$$ -> DownSince
  ^\s*Port\s+Name\s+Down Time\s+Up Time\s*$$ -> UpTime
  ^\s*$$
  ^. -> Error

DownSince
  ^\s*${PORT}\s+${DOWNTIME}\s*$$ -> Record
  ^\s*${PORT}\s+${DOWNTIME}\s*${SINCE}\s*$$ -> Record
  ^\s*${PORT}\s+${NAME}\s*${DOWNTIME}\s*$$ -> Record
  ^\s*${PORT}\s+${NAME}\s*${DOWNTIME}\s+${SINCE}\s*$$ -> Record
  ^\s*$$
  ^. -> Error

UpTime
  ^\s*${PORT}\s+${NAME}\s+00:00:00\s+${UPTIME}?\s*$$ -> Record
  ^\s*${PORT}\s+${DOWNTIME}\s+${UPTIME}?\s*$$ -> Record
  ^\s*${PORT}\s+${NAME}\s+${DOWNTIME}\s*$$ -> Record
  ^\s*$$
  ^. -> Error
SAMPLE COMMAND OUTPUT
Te5/0/1                           43w5d
Te5/0/2                           43w5d
Te5/0/3                           43w5d
Te5/0/4                           43w5d
Te5/0/5                           43w5d
Te5/0/6                           43w5d
Te5/0/7                           43w5d
Te5/0/8                           43w5d
Fo5/0/9                           43w5d
Fo5/0/10                          43w5d
Twe5/0/1       L3 Link            00:00:00       9w4d
Twe5/0/1.602   L3 Link VR 00:00:00       9w4d
Twe5/0/1.603   L3 Link VRF    00:00:00       9w4d
Twe5/0/5                          43w5d
Ap5/0/1                           43w5d
Te6/0/1                           43w5d
Te6/0/2                           43w5d
Te6/0/3                           43w5d
Te6/0/4                           43w5d
Te6/0/5                           43w5d
Te6/0/6                           43w5d
Te6/0/7                           43w5d
Te6/0/8                           43w5d
Fo6/0/9                           43w5d
Fo6/0/10                          43w5d
Twe6/0/1       L3 Link            00:00:00       9w4d
Twe6/0/1.602   L3 Link VR 00:00:00       9w4d
Twe6/0/1.603   L3 Link VRF    00:00:00       9w4d
Twe6/0/5                          43w5d
SUMMARY

When subinterfaces are present, the subinterface is not included in the second group for the regex match for port information

STEPS TO REPRODUCE

EXPECTED RESULTS

results = {'downtime': '', 'name': 'L3 Link', 'port': 'Te6/0/1', 'since': '', 'uptime': '9w4d'}, {'downtime': '', 'name': 'L3 Link VR', 'port': 'Te6/0/1.602', 'since': '', 'uptime': '9w4d'}

ACTUAL RESULTS
textfsm.parser.TextFSMError: State Error raised. Rule Line: 32. Input Line: Twe6/0/1.602   L3 Link VR 00:00:00       9w4d

brianatlarge avatar Jan 22 '24 21:01 brianatlarge

would maybe using the below work better?

Value PORT (\S+)

kuraijay avatar Jan 25 '24 01:01 kuraijay

would maybe using the below work better?

Value PORT (\S+)

@kuraijay , @brianatlarge

\S+ would probably work out better in the long run

It is simpler than adding (\.[0-9]+)? to the end of that already long and complex regex. :grimacing: The below works, but I don't see a reason why \S+ couldn't be used instead. Value PORT ([a-zA-Z]{2,3}[0-9]{1,2}\/[0-9]{1,2}(\/[0-9]{1,2})?(\.[0-9]+)?)

mjbear avatar Feb 23 '24 03:02 mjbear

The line formatting looks a little odd. I'd expect the "columns" to generally line up. Example: Twe5/0/1.602 L3 Link VR 00:00:00 9w4d

The sample output from above with the header line

Port           Name               Down Time      Up Time
Te5/0/1                           43w5d
Te5/0/2                           43w5d
Te5/0/3                           43w5d
Te5/0/4                           43w5d
Te5/0/5                           43w5d
Te5/0/6                           43w5d
Te5/0/7                           43w5d
Te5/0/8                           43w5d
Fo5/0/9                           43w5d
Fo5/0/10                          43w5d
Twe5/0/1       L3 Link            00:00:00       9w4d
Twe5/0/1.602   L3 Link VR 00:00:00       9w4d
Twe5/0/1.603   L3 Link VRF    00:00:00       9w4d
Twe5/0/5                          43w5d
Ap5/0/1                           43w5d
Te6/0/1                           43w5d
Te6/0/2                           43w5d
Te6/0/3                           43w5d
Te6/0/4                           43w5d
Te6/0/5                           43w5d
Te6/0/6                           43w5d
Te6/0/7                           43w5d
Te6/0/8                           43w5d
Fo6/0/9                           43w5d
Fo6/0/10                          43w5d
Twe6/0/1       L3 Link            00:00:00       9w4d
Twe6/0/1.602   L3 Link VR 00:00:00       9w4d
Twe6/0/1.603   L3 Link VRF    00:00:00       9w4d
Twe6/0/5                          43w5d

mjbear avatar Feb 23 '24 03:02 mjbear

@brianatlarge Apologies for the lapse in time here. I'm a volunteer and if this thread was responded to it would have kept this process moving along.

  1. Would you please provide or confirm that the raw cli output is as it appears above is unaltered?

(If I'm to use your raw output for the test cases then it really needs to be indented/formatted as it comes back from the network device.)

Regarding the capture group regexes... While we could add to the existing long regex (see below), it can also be shortened with simply \S+. The latter is where I'm leaning to hopefully reduce maintenance on that capture group in the long term.

(Note: This works, but is long and complex. [a-zA-Z]{2,3}[0-9]{1,2}\/[0-9]{1,2}(\/[0-9]{1,2})?(\.\d+)?)

For the time being I'm going with the below slightly truncated (less duplicate line formats) and adjusted raw output alignment which should be closer to how it appears on the device.

Port           Name               Down Time      Up Time
Te5/0/1                           43w5d
Fo5/0/9                           43w5d
Fo5/0/10                          43w5d
Twe5/0/1       L3 Link            00:00:00       9w4d
Twe5/0/1.602   L3 Link VR         00:00:00       9w4d
Twe5/0/1.603   L3 Link VRF        00:00:00       9w4d
Twe5/0/5                          43w5d
Ap5/0/1                           43w5d
Te6/0/1                           43w5d
Fo6/0/9                           43w5d
Fo6/0/10                          43w5d
Twe6/0/1       L3 Link            00:00:00       9w4d
Twe6/0/1.602   L3 Link VR         00:00:00       9w4d
Twe6/0/1.603   L3 Link VRF        00:00:00       9w4d
Twe6/0/5                          43w5d

mjbear avatar Jul 15 '24 01:07 mjbear

PR #1740 has been created which should resolve this issue

mjbear avatar Jul 15 '24 01:07 mjbear

@brianatlarge PR #1740 has been merged and this issue should be resolved.

mjbear avatar Jul 15 '24 21:07 mjbear