Would like to share with you guys a tool that I developed - Template Text Parser.
Background.
Have to work in diverse networking environment with lots of legacy devices and various vendors, as a result came to conclusion that it would be nice to have a tool that can:
1 - Parse configuration and show commands outputs, including nested/indented text data
2 - Produce python native structures - dictionaries/lists, with any level of hierarchy
2 - Use templates that are easy to create, read and share
3 - Capable of processing and transforming data during and after parsing
4 - Able to output results in common formats such as json, yaml, csv, excel tables or render it with Jinja2
The goal was, to implement this workflow - write template, parse data with it and get desired results straight away, without the need to write lengthy scripts to process it further if use case was simple.
Simple example.
Source data:
interface Vlan778 ip address 2002::fd37:0091/124 ! interface Loopback991 ip address 192.168.0.1/32 !
TTP template:
interface ip address /
To parse using CLI tool:
ttp --data "/path/to/data.txt" --template "/path/to/template.txt" -o json
And this will be the result:
[ [ { "interface": "Vlan778", "ip": "2002::fd37:0091", "mask": "124" }, { "interface": "Loopback991", "ip": "192.168.0.1", "mask": "32" } ] ]
No comments:
Post a Comment