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.

Hi , This is just a question . I am trying to replicate what I see on NTC templates on a huawei routers we use .

In [22]: my_device = { "host":"10.170.17.46","username":"abooda","password":"password","device_type": "huawei",}

In [23]: net_connect2 = Netmiko(**my_device)  

In [24]: output = net_connect2.send_command("display arp",use_textfsm=True) 

In [25]: print(output)
IP ADDRESS      MAC ADDRESS     EXPIRE(M) TYPE        INTERFACE   VPN-INSTANCE 
                                          VLAN/CEVLAN PVC                      
------------------------------------------------------------------------------
10.170.17.46    346a-c214-8503            I -         GE0/0/9
10.170.17.41    6400-f175-d080  3         D-0         GE0/0/9
172.16.7.2      346a-c214-8501            I -         Vlanif7
172.16.7.5      0c8d-dbb9-cbf4  20        D-0         GE0/0/0
                                             7/-
172.16.7.6      0c8d-dbb9-a740  20        D-0         GE0/0/0
                                             7/-
172.16.7.4      0018-0a4f-0001  5         D-0         GE0/0/0
                                             7/-
172.16.7.3      4c00-826a-c77e  5         D-0         GE0/0/0
                                             7/-
------------------------------------------------------------------------------
Total:7         Dynamic:5       Static:0     Interface:2    

In [26]: 

I tried to create a template similar to the hp procurve switch (display arp) , but i am not getting structured data back. Any ideas if what if I am trying to replicate is right or this is not the way TFM works ?

my template :

$ cat huawei_display_arp.template 
Value IPADDRESS (\d+.\d+.\d+.\d+)
Value MAC ADDRESS (\w+-\w+-\w+)
Value EXPIRE(M) (\d+)
Value TYPE (\S+)
Value INTERFACE (\S+)
Value VPN-INSTANCE (\S+)

Start
^${IPADDRESS}\s+${MAC ADDRESS}\s+${EXPIRE(M)}\s+${TYPE}\s+${INTERFACE}\s+${VPN-INSTANCE} -> Record

Actual /similar hp comware tfm template

$ cat hp_comware_display_arp.template 
Value IPADDRESS (\d+.\d+.\d+.\d+)
Value MACADDRESS (\w+-\w+-\w+)
Value VLAN (\S+|\d+)
Value INTERFACE (\S+)
Value AGING (\d+)
Value TYPE (\S+)

Start
  ^${IPADDRESS}\s+${MACADDRESS}\s+${VLAN}\s+${INTERFACE}\s+${AGING}\s+${TYPE} -> Record

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
Abed1985commented, Apr 16, 2019

just leaving this comment here incase anybody need to know what i eventually did to get a structured format from display lldp neighbor on huawei routers

`I have parsed what I need using the below :

cat huawei_display_lldp_neighbor.template

`Value SYSTEM_NAME (\S+) Value MANAGEMENT_ADDRESS (\d+.\d+.\d+.\d+) Value MANUFACTURER_NAME (.) Value MODEL_NAME (.)

Start ^System name.+:${SYSTEM_NAME} ^Management address.+:\s${MANAGEMENT_ADDRESS} ^Manufacturer name.+:${MANUFACTURER_NAME} ^Model name.+:${MODEL_NAME} -> Record`

Sample output:

python3 test-huawei-lldp.py [{‘system_name’: ‘tsa-2960-sw01’, ‘management_address’: ‘192.168.0.240’, ‘manufacturer_name’: ‘Cisco Systems, Inc.’, ‘model_name’: ‘WS-C2960S-48LPS-L’}]`

0reactions
Abed1985commented, Mar 27, 2019

Just one last question 😃 do you think such output could be parsed with regex on the same approach , I am interested in the device( system description) under each neighbor. probably I need alot of time to get around this output … thanks I guess i will use the approach advised by Kirk above. Any hint is welcome though

display lldp neighbor GigabitEthernet0/0/0 has 0 neighbors

GigabitEthernet0/0/1 has 1 neighbors:

Neighbor index : 1 Chassis type :macAddress Chassis ID :ecb1-d7e6-e5c0 Port ID type :local Port ID :26 Port description :26 System name :ARCH-ADL-02 System description :HP J9772A 2530-48G-PoEP Switch, revision YA.15.12.0015, ROM YA.15.12 (/ws/swbuildm/YA_rel_knoxville_qaoff/code/build/lakes(swbuildm_YA_rel_knoxville_qaoff_rel_knoxville)) System capabilities supported :bridge System capabilities enabled :bridge Management address type :ipV4 Management address : 10.0.100.4
Expired time :94s

Port VLAN ID(PVID) :1 Protocol identity :

Auto-negotiation supported :Yes Auto-negotiation enabled :Yes
OperMau :speed(1000)/duplex(Full)

Power port class :PD PSE power supported :No PSE power enabled :No PSE pairs control ability:No Power pairs :Unknown Port power classification:Unknown

Link aggregation supported:No Link aggregation enabled :No Aggregation port ID :0 Maximum frame Size :0

MED Device information
Device class :Network Connectivity

HardwareRev :NA FirmwareRev :NA SoftwareRev :NA SerialNum :NA Manufacturer name :NA Model name :NA Asset tracking identifier :NA

Power Type :PSE PoE PSE power source :Unknown Port PSE Priority :Low Port Available power value:130 GigabitEthernet0/0/2 has 0 neighbors

GigabitEthernet0/0/3 has 0 neighbors

<architec-adelaide-ea-vpn>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Newest 'python-textfsm' Questions - Stack Overflow
I am trying to create a textfsm template for command of a Cisco switch. the command is show platform. This command doesn't have...
Read more >
Parsing Strategies - NTC Templates using TextFSM
This post will dive deeper into using NTC Templates to parse unstructured data into usable, structured data. NTC Templates uses TextFSM under ...
Read more >
TextFSM Value Key - Time To Learn - Наташа Самойленко
Today, thanks to a question from a listener, I decided to figure out what Value Key means in TextFSM templates. Previously, for some...
Read more >
TextFSM template syntax - Python for network engineers
TextFSM template describes how data should be processed. Each template consists of two parts: value definitions (or variable definitions) - ...
Read more >
ntc-templates - PyPI
TextFSM Templates for Network Devices, and Python wrapper for TextFSM's CliTable. ... For any questions or comments, please feel free to swing by...
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