ntc-templates
ntc-templates copied to clipboard
cisco_nxos_show_lldp_neighbor Regex errors in 3.0.0
ISSUE TYPE
- Bug Report
TEMPLATE USING
Value NEIGHBOR (\S+)
Value LOCAL_INTERFACE (\S+)
Value NEIGHBOR_INTERFACE (\S+)
Start
^Device.*ID -> LLDP
LLDP
^${NEIGHBOR}\s??$$
^${NEIGHBOR}\s+${LOCAL_INTERFACE}\s+\d+\s+(\w??\s)+\s+${NEIGHBOR_INTERFACE} -> Record
^\s+${LOCAL_INTERFACE}\s+\d+\s+(\w??\s)+\s+${NEIGHBOR_INTERFACE} -> Record
SAMPLE COMMAND OUTPUT
r1-services# show lldp neighbor
Capability codes:
(R) Router, (B) Bridge, (T) Telephone, (C) DOCSIS Cable Device
(W) WLAN Access Point, (P) Repeater, (S) Station, (O) Other
Device ID Local Intf Hold-time Capability Port ID
dcx3.org.local
mgmt0 120 B Gi1/0/37
r2-services Eth1/1 120 BR Eth1/1
dx1.org.local
Eth1/3 120 B Te1/1/1
fw1-clinical-partner
Eth1/5 120 ethernet1/9
fw1-clinical-partner
Eth1/6 120 ethernet1/10
fw2-clinical-partner
Eth1/7 120 ethernet1/9
fw2-clinical-partner
Eth1/8 120 ethernet1/10
cr-ebc.org.local Eth3/1 120 BR Fo1/0/8
r2-services Eth3/13 120 BR Eth3/13
fw1-services Eth3/23 120 ethernet1/21
fw2-services Eth3/24 120 ethernet1/23
cr-park.org.local
Eth4/1 120 BR Fo1/0/8
r2-services Eth4/13 120 BR Eth4/13
fw1-services Eth4/23 120 ethernet1/22
fw2-services Eth4/24 120 ethernet1/24
Total entries displayed: 15
SUMMARY
When parsing the output of 'show lldp neighbor' certain records are skipped
1. If Neighbor is on it's own line and has a space character before EoL (\n) (fw* and cr-park are examples from raw output above)
2. If Neighbor is not advertising any capabilities (fw* above are examples from raw output above)
from ntc_templates.parse import parse_output
show = (
"Capability codes:\n (R) Router, (B) Bridge, (T) Telephone, (C) DOCSIS Cable Device\n (W) WLAN Access Point, (P) Repeater, (S) Station, (O) Other\nDevice ID Local Intf Hold-time Capability Port ID \ndcx3-179ebc-cbnmgmt.org.local\n mgmt0 120 B Gi1/0/37 \nr2-services Eth1/1 120 BR Eth1/1 \ndx1.org.local\n Eth1/3 120 B Te1/1/1 \nfw1-clinical-partner \n Eth1/5 120 ethernet1/9 \nfw1-clinical-partner \n Eth1/6 120 ethernet1/10 \nfw2-clinical-partner \n Eth1/7 120 ethernet1/9 \nfw2-clinical-partner \n Eth1/8 120 ethernet1/10 \ncr-ebc.org.local Eth3/1 120 BR Fo1/0/8 \nr2-services Eth3/13 120 BR Eth3/13 \nfw1-services Eth3/23 120 ethernet1/21 \nfw2-services Eth3/24 120 ethernet1/23 \ncr-park.org.local \n Eth4/1 120 BR Fo1/0/8 \nr2-services Eth4/13 120 BR Eth4/13 \nfw1-services Eth4/23 120 ethernet1/22 \nfw2-services Eth4/24 120 ethernet1/24 \nTotal entries displayed: 15\n"
)
parse = parse_output(platform="cisco_nxos",command="show lldp neighbors",data=show)
print(parse)
EXPECTED RESULTS
[{"neighbor": "dcx3.org.local", "local_interface": "mgmt0", "neighbor_interface": "Gi1/0/37"}, {"neighbor": "r2-services", "local_interface": "Eth1/1", "neighbor_interface": "BR"}, {"neighbor": "dx1.org.local", "local_interface": "Eth1/3", "neighbor_interface": "Te1/1/1"}, {"neighbor": "fw1-clinical-partner", "local_interface": "Eth1/5", "neighbor_interface": "ethernet1/9"}, {"neighbor": "fw1-clinical-partner", "local_interface": "Eth1/6", "neighbor_interface": "ethernet1/10"}, {"neighbor": "fw2-clinical-partner", "local_interface": "Eth1/7", "neighbor_interface": "ethernet1/9"}, {"neighbor": "fw2-clinical-partner", "local_interface": "Eth1/8", "neighbor_interface": "ethernet1/10"}, {"neighbor": "cr-ebc.org.local", "local_interface": "Eth3/1", "neighbor_interface": "BR"}, {"neighbor": "r2-services", "local_interface": "Eth3/13", "neighbor_interface": "BR"}, {"neighbor": "fw1-services", "local_interface": "Eth3/23", "neighbor_interface": "ethernet1/21"}, {"neighbor": "fw2-services", "local_interface": "Eth3/24", "neighbor_interface": "ethernet1/23"}, {"neighbor": "cr-park.org.local", "local_interface": "Eth4/1", "neighbor_interface": "BR"}, {"neighbor": "r2-services", "local_interface": "Eth4/13", "neighbor_interface": "BR"}, {"neighbor": "fw1-services", "local_interface": "Eth4/23", "neighbor_interface": "ethernet1/22"}, {"neighbor": "fw2-services", "local_interface": "Eth4/24", "neighbor_interface": "ethernet1/24"}]
ACTUAL RESULTS
The list of lldp neighbors only includes those without spaces after neighbor name (if on its own line) and those advertising capabilities.
[{'neighbor': 'dcx3.org.local', 'local_interface': 'mgmt0', 'neighbor_interface': 'Gi1/0/37'}, {'neighbor': 'r2-services', 'local_interface': 'Eth1/1', 'neighbor_interface': 'Eth1/1'}, {'neighbor': 'dx1.org.local', 'local_interface': 'Eth1/3', 'neighbor_interface': 'Te1/1/1'}, {'neighbor': 'cr-ebc.org.local', 'local_interface': 'Eth3/1', 'neighbor_interface': 'Fo1/0/8'}, {'neighbor': 'r2-services', 'local_interface': 'Eth3/13', 'neighbor_interface': 'Eth3/13'}, {'neighbor': '', 'local_interface': 'Eth4/1', 'neighbor_interface': 'Fo1/0/8'}, {'neighbor': 'r2-services', 'local_interface': 'Eth4/13', 'neighbor_interface': 'Eth4/13'}]
This issue could be resolved by changing the regex used in the LLDP section as follows.
LLDP
^${NEIGHBOR}\s??$$
^${NEIGHBOR}\s+${LOCAL_INTERFACE}\s+\d+\s+(\w??\s)+\s+${NEIGHBOR_INTERFACE} -> Record
^\s+${LOCAL_INTERFACE}\s+\d+\s+(\w??\s)+\s+${NEIGHBOR_INTERFACE} -> Record
I'm novice so there are probably better ways to do this, but the change above worked when I changed it on my local version of the template.
The device capabilities data could be made optional as a whole and extra white space regex removed.
original (\w+?\s)+\s+
> (yours) (\w??\s)+\s+
> (\w+?\s+)?
I'm working on a fix and soon enough a PR based off current NTC master branch. I'll work on the merge conflicts for #1469 that has not been merged yet against the feature branch for this issue.
Edit: You're certainly right that for some reason fw1-clinical-partner (and a few others) have a trailing space in the Raw Output, but dcx3.org.local does not.
Edit: You're certainly right that for some reason fw1-clinical-partner (and a few others) have a trailing space in the Raw Output, but dcx3.org.local does not.
I believe dcx3.org.local is failing because the "output" for that device is moved down to a second line and not all on the same line. But again I don't know enough about the regex parser to be sure that's the 'why'
Edit: You're certainly right that for some reason fw1-clinical-partner (and a few others) have a trailing space in the Raw Output, but dcx3.org.local does not.
I believe dcx3.org.local is failing because the "output" for that device is moved down to a second line and not all on the same line. But again I don't know enough about the regex parser to be sure that's the 'why'
@IamBuldog Correct, the multi-line entry was the issue.
The PR #1586 I put together was merged into ntc-templates master branch about three days ago.
So if you're using a copy of ntc-templates that you git cloned then you should be able to run a git pull to update your copy. And if you're using a copy that you pip installed, that will require a new version to be released which may happen in few weeks per the NTC team but those dates are understandably fluid.
Can this be closed?
Yes