Python (textfsm template) for grepping show ip bgp (IOS format) into CSV file

Started by wintermute000, July 05, 2016, 05:41:02 AM

Previous topic - Next topic

wintermute000

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


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/
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...)



deanwebb

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?:
Take a baseball bat and trash all the routers, shout out "IT'S A NETWORK PROBLEM NOW, SUCKERS!" and then peel out of the parking lot in your Ferrari.
"The world could perish if people only worked on things that were easy to handle." -- Vladimir Savchenko
Вопросы есть? Вопросов нет! | BCEB: Belkin Certified Expert Baffler | "Plan B is Plan A with an element of panic." -- John Clarke
Accounting is architecture, remember that!
Air gaps are high-latency Internet connections.