Closed Abed1985 closed 5 years ago
Hi @Abed1985 Looks like your template probably failed to snag the data it needed. A quick look at this and I saw three maybe issues;
Value IPADDRESS (\d+.\d+.\d+.\d+)
Value MAC-ADDRESS (\w+-\w+-\w+)
Value EXPIRE (\d+)
Value TYPE (\S+)
Value INTERFACE (\S+)
Value VPN_INSTANCE (.*)
Start
^${IPADDRESS}\s+${MAC-ADDRESS}\s+${EXPIRE}\s+${TYPE}\s+${INTERFACE}\s+${VPN_INSTANCE} -> Record
^${IPADDRESS}\s+${MAC-ADDRESS}\s+${EXPIRE}\s+${TYPE}\s+${INTERFACE} -> Record
Also from a workflow perspective, I like to start with a single variable and a rule or rules that process that single variable. I then verify I have a working solution on that single variable case.
I then expand on that to add a second variable and updated rule(s) and make sure that works.
And keep working in an iterative manner to extract all of the fields.
Thanks @ktbyers @carlniger carlniger
is it this what you mean ? I am trying to have only IP and mac as an interesting parameters for me at this point with no luck. I will see if I can work out ip address alone then and build on that ? is the string under the start is right
abooda@bne-mns-dev-01:~/TextFSM/ntc-templates/templates$ cat huawei_display_arp.template Value IPADDRESS (\d+.\d+.\d+.\d+) Value MAC-ADDRESS (\w+-\w+-\w+)
Start ^${IPADDRESS}\s+${MAC-ADDRESS}\s -> Record abooda@bne-mns-dev-01:~/TextFSM/ntc-templates/templates$
In [1]: from netmiko import Netmiko
In [2]: my_device = { "host":"10.170.17.46","username":"abooda","password":"###Yamm3029Sherry","device_type": "huawei",}
In [3]: net_connect2 = Netmiko(**my_device)
In [4]: output = net_connect2.send_command("display arp",use_textfsm=True)
Total:7 Dynamic:5 Static:0 Interface:2
In [6]: exit()
This has not worked too.. Is there anything else I need to edit other than creating this template file. I feel that the template is not being used at all. is there any file I should add the use of this template to? please execuse my limited understanding as I am new to using this approach .
abooda@bne-mns-dev-01:~/TextFSM/ntc-templates/templates$ cat huawei_display_arp.template
Value IPADDRESS (\d+.\d+.\d+.\d+)
Start ^${IPADDRESS}\s -> Record abooda@bne-mns-dev-01:~/TextFSM/ntc-templates/templates$
Have you updated your index file to point to this template? The last comment looks like it should work assuming index file is updated appropriately.
Also a very quick search didn't find anything to document this, but I believe that dashes/hyphens "-" in Values will fail in TextFSM (sorry I pasted a version with dashes from testing some stuff yesterday) -- obviously this shouldn't affect that last template file you posted just wanted to mention that.
I find out that i have to update the enviroent variable export =.. on the linux machine every once in a while for the netmiko command to accept the tfm usage .. when i try with one of the existing templates for a cisco device for example it works. But also how do i update the index file to point perminantly to the templates location
Sounds like you need to add the appropriate line to the index file:
Template, Hostname, Platform, Command
alcatel_aos_show_vlan.template, .*, alcatel_aos, show vlan
So for you something like:
huawei_show_ip_arp.template, .*, huawei, show ip arp
See the index file/repo for details: https://github.com/networktocode/ntc-templates/blob/master/templates/index
Thanks , its now working fine with the variables I have :
In [6]: print(output) [{'ipaddress': '10.170.17.46', 'mac_address': '346a-c214-8503'}, {'ipaddress': '10.170.17.41', 'mac_address': '6400-f175-d080'}, {'ipaddress': '172.16.7.2', 'mac_address': '346a-c214-8501'}, {'ipaddress': '172.16.7.5', 'mac_address': '0c8d-dbb9-cbf4'}, {'ipaddress': '172.16.7.6', 'mac_address': '0c8d-dbb9-a740'}, {'ipaddress': '172.16.7.4', 'mac_address': '0018-0a4f-0001'}, {'ipaddress': '172.16.7.3', 'mac_address': '4c00-826a-c77e'}]
I have this :
abooda@bne-mns-dev-01:~/TextFSM/ntc-templates/templates$ cat huawei_display_arp.template Value IPADDRESS (\d+.\d+.\d+.\d+) Value MAC_ADDRESS (\w+-\w+-\w+)
Start ^${IPADDRESS}\s+${MAC_ADDRESS}\s -> Record abooda@bne-mns-dev-01:~/TextFSM/ntc-templates/templates$
one last query :) I have to keep inserting setting up the environment with this 👍 xport NET_TEXTFSM=/home/abooda/TextFSM/ntc-templates/templates
everytime the template calls fails , is it something i can solve permenantly and why its happening
netmiko looks in ~/ntc-template/ by default, so you can either update your bashrc/profile so that the env var for "NET_TEXTFSM" is persistent, or move the etc-templates folder up to your home dir.
Thank you vey much all sorted. I will play around with the templates to fetch what I want , as now I think i understand how this works! appreciate your swift response and support on this .
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
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'}]`
Hi , This is just a question . I am trying to replicate what I see on NTC templates on a huawei routers we use .
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 :
Actual /similar hp comware tfm template