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.

IOS: "show lldp neighbor detail" not parsing

See original GitHub issue

Using ansible and clay584.parse_genie module, parsing ‘show lldp neighbor detail’ and ‘show lldp entry *’.

Task returns “parse_genie: local variable ‘intf_dict’ referenced before assignment - Failed to parse command output.”

OS is IOS devices running versions 15.0 and 15.2

Relevant parts of ansible playbook

 - name: "show lldp neighbor detail"
    ios_command:
      commands: "show lldp neighbors detail"
    register: lldp_neighbors

- name: "parse LLDP neighbor"
    debug:
      msg: "{{ lldp_neighbors.stdout[0] | parse_genie(command='show lldp neighbors detail', os='ios')}}"
    register: parsed_lldp_neighbor

Output from ansible playbook

TASK [parse LLDP neighbor] *****************************************************
fatal: [switch]: FAILED! => {"msg": "parse_genie: local variable 'intf_dict' referenced before assignment - Failed to parse command output."}

Ansible, python and genie versions

ansible 2.9.4
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/awx/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /var/lib/awx/venv/genie/lib64/python3.6/site-packages/ansible
  executable location = /var/lib/awx/venv/genie/bin/ansible
  python version = 3.6.8 (default, Aug  7 2019, 17:28:10) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]

Name: genie
Version: 20.1
Summary: Genie: THE standard pyATS Library System
Home-page: https://developer.cisco.com/pyats/
Author: Cisco Systems Inc.
Author-email: pyats-support-ext@cisco.com
License: Apache 2.0
Location: /var/lib/awx/venv/genie/lib/python3.6/site-packages
Requires: genie.libs.parser, genie.libs.sdk, tqdm, PrettyTable, netaddr, genie.libs.conf, genie.libs.filetransferutils, genie.libs.ops, jsonpickle, dill

switch show lldp neighbor detail sample output

------------------------------------------------
Chassis id: 10.10.191.15
Port id: ccf9.5493.ba88
Port Description: Avaya IP Deskphone
System Name - not advertised

System Description:
Avaya 1220 IP Deskphone, Firmware:06Q

Time remaining: 155 seconds
System Capabilities: B,T
Enabled Capabilities: B,T
Management Addresses - not advertised
Auto Negotiation - supported, enabled
Physical media capabilities:
    100base-TX(FD)
    100base-TX(HD)
    10base-T(FD)
    10base-T(HD)
Media Attachment Unit type: 16
Vlan ID: - not advertised

MED Information:

    MED Codes:
          (NP) Network Policy, (LI) Location Identification
          (PS) Power Source Entity, (PD) Power Device
          (IN) Inventory

    F/W revision: 06Q
    Manufacturer: Avaya-05
    Model: 1220 IP Deskphone
    Capabilities: NP, LI, PD, IN
    Device type: Endpoint Class III
    Network Policy(Voice): VLAN 110, tagged, Layer-2 priority: 5, DSCP: 46
    Network Policy(Voice Signal): VLAN 110, tagged, Layer-2 priority: 0, DSCP: 0
    PD device, Power source: Unknown, Power Priority: High, Wattage: 6.0
    Location - not advertised

------------------------------------------------

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
nathantabaileycommented, Feb 26, 2020

Hey @xiaoxinz-cisco

Thank you for getting back to me so quickly. I have tested against the original output provided and the parser is working.

When testing against a different device, with a different neighbor type, the error is thrown. I will look through the code and hopefully make a pull request in the future.

Thank you again,

Nathan

0reactions
xiaoxinz-ciscocommented, Feb 26, 2020

Hi @nathantabailey ,

Based on the output you provided above, we updated the schema and parser class. This output and its parsed output can be found in this test.

Did you get this error from the above output?

Since we just release, we may not release another version with new fixes recently. To reduce your waiting time, I encourage you to jump into the code and fix it. I believe you can do this!

Here is an assumption about the error: `

        # ==== Med Information ====
 1.    # F/W revision: 06Q
 2.    # S/W revision: SCCP42.9-3-1ES27S
 3.    # H/W revision: 12
        m = med_p1.match(line)
        if m:
            group = m.groupdict()
   4.       med_dict = ret_dict.setdefault('med_information', {})
            med_dict[group['head'].lower()+'_revision'] = m.groupdict()['revision']
            continue

        # Manufacturer: Avaya-05
        # Model: 1220 IP Deskphone
        # Device type: Endpoint Class III
        m = med_p2.match(line) or med_p3.match(line) or med_p5.match(line)
        if m:
            match_key = [*m.groupdict().keys()][0]
    5.      med_dict[match_key] = m.groupdict()[match_key]
            continue

` The reason is med_dict is not defined before line-5, or the first if-condition has not been called. There are a few reasons:

  1. No F/W revision: …, S/W revision:… or H/W revision:… in your output. In this case, a possible solution: `

        m = med_p2.match(line) or med_p3.match(line) or med_p5.match(line)
        if m:
            match_key = [*m.groupdict().keys()][0]
      >>    if 'med_information' not in ret_dict:
      >>       med_dict = ret_dict.setdefault('med_information', {})
            med_dict[match_key] = m.groupdict()[match_key]
            continue
    

` 2. Those keys exist, but in lowercase, such as f/w revision. In this case, updating the regex med_pq will fix it.

Hope this example gives you some hints!

If there are any updates you want to share with us, you could create a pull request in this repo.

Thanks, Irene

Read more comments on GitHub >

github_iconTop Results From Across the Web

Parser "show lldp neighbors detail" for ios not working to ...
I want to get LLDP neighbor details especially LLDP neighbor system description of a Cisco Catalyst switch. The playbook works without error ...
Read more >
Missing information in "show LLDP neighbors detail&quot
I am working on mapping layer 2 devices by parsing the output from "show LLDP neighbors detail". The network contains only Cisco devices....
Read more >
Configuring LLDP
The neighbor database itself can be read by either LLDP or CDP methods or by using the show lldp commands. Take note of...
Read more >
IP Fabric v3.x.x - IP Fabric Documentation Portal
Cisco NX-OS - fixed parsing of different output for command "show vrrp detail"; Cisco NX-OS - XDP links for LLDP protocol might have...
Read more >
4.3.5+1 - IP Fabric Docs - Confluence
Arista Eos- Fix parsing of command "show lldp neighbors detail". ... Cisco - IOS/IOS-XE fixed parsing of "show ip mroute count" command.
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