Networking-Forums.com

Professional Discussions => Programming Goodies and Software-Defined Networking => Topic started by: wintermute000 on July 05, 2016, 05:41:02 AM

Title: Python (textfsm template) for grepping show ip bgp (IOS format) into CSV file
Post by: wintermute000 on July 05, 2016, 05:41:02 AM
Sounds simple..... Try it and see ;)


I've done the regex spade-work via a neat python module called textfsm which is basically a regex looping engine AFAIK. I haven't captured all the possible flags but all the standard ones are there (namely, *,>,i,m,r) and it also correctly handles IOS retarded parsing e.g. sometimes not leaving a space between the flags and the prefix, lines with no prefix but only next hop, lines where there is only the prefix then all the other info is on the next line.

https://github.com/wintermute000/ntc-templates/blob/master/templates/cisco_ios_show_ip_bgp.template (https://github.com/wintermute000/ntc-templates/blob/master/templates/cisco_ios_show_ip_bgp.template)


Call the above template via textfsm


Textfsm primer here. You'll have to manually install, it doesn't seem to be accessible via pip.
http://jedelman.com/home/programmatic-access-to-cli-devices-with-textfsm/ (http://jedelman.com/home/programmatic-access-to-cli-devices-with-textfsm/)
https://code.google.com/archive/p/textfsm/wikis/TextFSMHowto.wiki (https://code.google.com/archive/p/textfsm/wikis/TextFSMHowto.wiki)


can't guarantee its 100% but I've been using it to audit a dozen BGP tables that are >10k entries large and so far everything lines up. Let me know if any bugs are found - will likely be caused by output changes in different IOS versions etc., them's the breaks with screen scraping.


FFS Cisco just give us an API for the love of God, and even then it won't help the existing install base of gazillions (esp large megacorp core devices that can never EVAR be turned off or bounced for upgrading...)


Title: Re: Python (textfsm template) for grepping show ip bgp (IOS format) into CSV file
Post by: deanwebb on July 05, 2016, 07:05:00 AM
Quote from: wintermute000 on July 05, 2016, 05:41:02 AM
FFS Cisco just give us an API for the love of God, and even then it won't help the existing install base of gazillions (esp large megacorp core devices that can never EVAR be turned off or bounced for upgrading...)

I'll take that back to the BU. I'll let you know what they say.

:problem?: