cisco_ios_show_interface_link - NAME capture group matches a single space when there is no visible name
Closed this issue · 3 comments
ISSUE TYPE
- Template Issue with error and raw data
Note: This issue is to openly discuss the possible change and any drawbacks/concerns. As noted below, I have a fix for it and will gladly submit a PR.
TEMPLATE USING
Value PORT (\S+)
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
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
SUMMARY
While working on issue #1605, I noticed that the NAME
capture group matches a single space when there is no visible name/description present. Ideally if there is no visible name then no characters should be matched and thus a zero length empty string would be returned. This has programming benefits when it comes to conditional logic.
STEPS TO REPRODUCE
---
parsed_sample:
- downtime: "43w5d"
name: " "
port: "Te5/0/1"
since: ""
uptime: ""
- downtime: "43w5d"
name: " "
port: "Fo5/0/9"
since: ""
uptime: ""
- downtime: "43w5d"
name: " "
port: "Fo5/0/10"
since: ""
uptime: ""
- downtime: ""
name: "L3 Link"
port: "Twe5/0/1"
since: ""
uptime: "9w4d"
- downtime: ""
name: "L3 Link VR"
port: "Twe5/0/1.602"
since: ""
uptime: "9w4d"
EXPECTED RESULTS
Ideally if there is no visible name then no characters should be matched and thus a zero length empty string would be returned. This has programming benefits when it comes to conditional logic.
💡 This can easily be remedied by adjusting the NAME
regex as shown below.
🎉 I will gladly submit a PR once any drawbacks/concerns have been voiced.
Value NAME (.*?)
ACTUAL RESULTS
A single space was matched for the NAME
capture group.
see above raw and yaml outputs
@jvanderaa @itdependsnetworks
Thoughts?
Thank you!
it should capture an empty string