clay584 / parse_genie

Ansible filter plugin for network CLI parsing using Cisco's Genie and pyATS
GNU General Public License v3.0
52 stars 15 forks source link

Parser "show lldp neighbors detail" for ios not working to parse "System Description" #1

Closed cuiminghao8 closed 5 years ago

cuiminghao8 commented 5 years ago

I want to get LLDP neighbor details especially LLDP neighbor system description of a Cisco Catalyst switch. The playbook works without error, but it seemed the LLDP neighbor "system_description" is missing in the parsed output. This is the output from Cisco switch:

UCBJSO_ASW01#show lldp nei detail
------------------------------------------------
Local Intf: Gi1/0/48
Chassis id: ec1d.8b2e.3700
Port id: Gi2/0/48
Port Description: GigabitEthernet2/0/48
System Name: UCBJSO_CSW02

System Description: 
Cisco IOS Software, IOS-XE Software, Catalyst L3 Switch Software (CAT3K_CAA-UNIVERSALK9-M), Version 03.06.06E RELEASE SOFTWARE (fc1)
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2016 by Cisco Systems, Inc.
Compiled Sat 17-Dec-16 

Time remaining: 107 seconds
System Capabilities: B,R
Enabled Capabilities: B,R
Management Addresses:
    IP: 10.33.32.1
Auto Negotiation - supported, enabled
Physical media capabilities:
    1000baseT(FD)
    100base-TX(FD)
    100base-TX(HD)
    10base-T(FD)
    10base-T(HD)
Media Attachment Unit type: 30
Vlan ID: 1

Total entries displayed: 1

This is the parsed output:

TASK [parse LLDP neighbor] ****************************************************************************************************************************************************************************
ok: [10.33.33.21] => {
    "msg": {
        "interfaces": {
            "GigabitEthernet1/0/48": {
                "if_name": "GigabitEthernet1/0/48",
                "port_id": {
                    "GigabitEthernet2/0/48": {
                        "neighbors": {
                            "UCBJSO_CSW02": {
                                "auto_negotiation": "supported, enabled",
                                "capabilities": {
                                    "mac_bridge": {
                                        "enabled": true,
                                        "name": "mac_bridge",
                                        "system": true
                                    },
                                    "router": {
                                        "enabled": true,
                                        "name": "router",
                                        "system": true
                                    }
                                },
                                "chassis_id": "ec1d.8b2e.3700",
                                "management_address": "10.33.32.1",
                                "neighbor_id": "UCBJSO_CSW02",
                                "physical_media_capabilities": [
                                    "1000baseT(FD)",
                                    "100base-TX(FD)",
                                    "100base-TX(HD)",
                                    "10base-T(FD)",
                                    "10base-T(HD)"
                                ],
                                "port_description": "GigabitEthernet2/0/48",
                                "port_id": "GigabitEthernet2/0/48",
                                "system_name": "UCBJSO_CSW02",
                                "time_remaining": 108,
                                "unit_type": 30,
                                "vlan_id": 1
                            }
                        }
                    }
                }
            }
        },

My ansible version:

ansible 2.8.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/minghao.cui/ansible-env/lib/python3.7/site-packages/ansible
  executable location = /home/minghao.cui/ansible-env/bin/ansible
  python version = 3.7.3 (default, May 10 2019, 11:10:10) [GCC 4.8.5 20150623 (Red Hat 4.8.5-36)]

The playbook look like this:

---
- name: parse lldp,cdp,vlan information
  hosts: '{{ hosts }}'
  gather_facts: no
  connection: local

  tasks:
  - name: "show ip interface brief"
    ios_command:
      commands: "show ip interface brief"
    register: intf_brief
  - name: "show lldp neighbor detail"
    ios_command:
      commands: "show lldp neighbors detail"
    register: lldp_neighbor
  - name: "show VLAN"
    ios_command:
      commands: "show vlan"
    register: vlan_brief
  - name: "show CDP neighbor detail"
    ios_command:
      commands: "show cdp neighbors"
    register: cdp_neighbor
  - include_role:
      name: clay584.parse_genie
  - name: "parse interface brief"
    debug:
      msg: "{{ intf_brief.stdout[0] | parse_genie(command='show ip interface brief', os='ios')}}"
    register: parsed_intf_brief
  - name: "parse LLDP neighbor"
    debug:
      msg: "{{ lldp_neighbor.stdout[0] | parse_genie(command='show lldp neighbors detail', os='ios')}}"
    register: parsed_lldp_neighbor
  - name: "parse VLAN"
    debug:
      msg: "{{ vlan_brief.stdout[0] | parse_genie(command='show vlan', os='ios')}}"
    register: parsed_vlan_brief
  - name: "parse CDP neighbor"
    debug:
      msg: "{{ cdp_neighbor.stdout[0] | parse_genie(command='show cdp neighbors', os='iosxe')}}"
    register: parsed_vlan_brief
clay584 commented 5 years ago

You may have found a bug in the parser in Cisco's Genie library. I have opened an issue on your behalf there and linked it over to this issue.

This is the issue for your reference. https://github.com/CiscoTestAutomation/genieparser/issues/20

I have a feeling that the regex parser that they have built is not matching on the CLI output from your device, and therefore does not appear in the output.

jeaubin commented 5 years ago

@cuiminghao8 - Thanks to report it, we are looking into it

jeaubin commented 5 years ago

It has been fixed, and a beta package has been released

pip install genie.libs.parser --upgrade --pre

Give it a try and let us know.

Thanks

cuiminghao8 commented 5 years ago

Great job! It has been fixed, thanks!