textfsm json template examples

Logan Rawlins maveric at gotskill.net
Tue May 11 20:07:15 CEST 2021


Here is a sample output from routedetail.textfsm

[
  {
    "Route": "12.0.0.0/24",
    "Neighbor": "go1",
    "Age": "2021-05-11 18:03:39",
    "NeiIP": "192.168.65.1",
    "OriginAS": "300",
    "Table": "go1_v4",
    "BGP_origin": "Incomplete",
    "BGP_aspath": "57 1 20 300",
    "BGP_nexthop": "192.168.65.1",
    "BGP_localpref": "100",
    "BGP_community": "",
    "BGP_med": ""
  },
  {
    "Route": "20.0.0.0/24",
    "Neighbor": "go2",
    "Age": "2021-05-11 18:03:39",
    "NeiIP": "192.168.65.2",
    "OriginAS": "300",
    "Table": "go2_v4",
    "BGP_origin": "Incomplete",
    "BGP_aspath": "18 1 20 300",
    "BGP_nexthop": "192.168.65.2",
    "BGP_localpref": "100",
    "BGP_community": "",
    "BGP_med": ""
  },
  {
    "Route": "20.0.0.0/24",
    "Neighbor": "go2",
    "Age": "2021-05-11 18:03:39",
    "NeiIP": "192.168.65.2",
    "OriginAS": "300",
    "Table": "gorr1_v4",
    "BGP_origin": "Incomplete",
    "BGP_aspath": "18 1 20 300",
    "BGP_nexthop": "192.168.65.2",
    "BGP_localpref": "100",
    "BGP_community": "(64666,666)",
    "BGP_med": ""
  },
  {
    "Route": "20.0.0.0/24",
    "Neighbor": "gorr2",
    "Age": "2021-05-11 18:03:38",
    "NeiIP": "192.168.64.101",
    "OriginAS": "300",
    "Table": "gorr2_v4",
    "BGP_origin": "Incomplete",
    "BGP_aspath": "18 1 20 300",
    "BGP_nexthop": "192.168.65.2",
    "BGP_localpref": "100",
    "BGP_community": "",
    "BGP_med": ""
  },
  {
    "Route": "20.0.0.0/24",
    "Neighbor": "go2",
    "Age": "2021-05-11 18:03:39",
    "NeiIP": "192.168.65.2",
    "OriginAS": "300",
    "Table": "test1.lab1_v4",
    "BGP_origin": "Incomplete",
    "BGP_aspath": "18 1 20 300",
    "BGP_nexthop": "192.168.65.2",
    "BGP_localpref": "100",
    "BGP_community": "(64666,666)",
    "BGP_med": ""
  }
]

On Tue, May 11, 2021 at 10:55 AM Logan Rawlins <maveric at gotskill.net> wrote:

> Like many of you on this list i've seen many running into issues needing
> json output from bird.  For now i'm getting through this using textfsm and
> then adding the headers to the output creating dict lists of routes or
> other info from bird.  This is probably the easiest method for parsing bird
> output into json hopefully this is of use to some on this list.
>
> <snip>
>     def _parse_bird_output(cls, template, text):
>         template='textfsm/' + template
>         with open(template) as f:
>             fsmtemplate = textfsm.TextFSM(f)
>             header = fsmtemplate.header
>             parsedtext = fsmtemplate.ParseText(text)
>             output = []
>
>             for item in parsedtext:
>                 output.append(dict(zip(header,item)))
>         return json.dumps(output)
> </snip>
>
> <routedetail.textfsm>
>
> Value Required Route
> (\d+\.\d+\.\d+\.\d+\/\d+|([0-9a-f]{0,4}:){2,7}[0-9a-f]{0,4}/\d{1,3})
> Value Neighbor ((\w|\.)+)
> Value Age (\d+-\d+-\d+ \d+:\d+:\d+)
> Value NeiIP (\d+\.\d+\.\d+\.\d+)
> Value OriginAS (\d+)
> Value Filldown Table (.+)
> Value BGP_origin (\w+)
> Value BGP_aspath (.+)
> Value BGP_nexthop (\d+\.\d+\.\d+\.\d+)
> Value BGP_localpref (\d+)
> Value BGP_community (.+)
> Value BGP_med (\d+)
>
> Start
>   ^Table ${Table}:
>   ^${Route}.*\[${Neighbor} ${Age} from ${NeiIP}\].*\[AS${OriginAS}.\]
>   ^\s+BGP.origin: ${BGP_origin}
>   ^\s+BGP.as_path: ${BGP_aspath}
>   ^\s+BGP.next_hop: ${BGP_nexthop}
>   ^\s+BGP.med: ${BGP_med}
>   ^\s+BGP.local_pref: ${BGP_localpref} -> CommCheck
>
> CommCheck
>   ^\s+BGP.community: ${BGP_community} -> Record Start
> # input buffer line doesn't have BGP.community in it, go on to the next
> rule(s) but save
>   ^\s*((?!BGP.community).)* -> Continue.Record
> # check for the start of new table or route and move back to initial state
>   ^Table ${Table}: -> Start
>   ^${Route}.*\[${Neighbor} ${Age} from ${NeiIP}\].*\[AS${OriginAS}.\] ->
> Start
> </routedetail.textfsm>
>
> <routes.textfsm>
>
> Value Filldown Table (.+)
> Value Required Route
> (\d+\.\d+\.\d+\.\d+\/\d+|([0-9a-f]{0,4}:){2,7}[0-9a-f]{0,4}/\d{1,3})
> Value Neighbor ((\w|\.)+)
> Value NeiIP (\d+\.\d+\.\d+\.\d+)
> Value Age (\d+-\d+-\d+ \d+:\d+:\d+)
> Value OriginAS (\d+)
>
>
> Start
>   ^BIRD \d+\.\d+\.\d+ ready. -> RTable
>
> RTable
>   ^Table ${Table}: -> Record
>   ^${Route}.*\[${Neighbor} ${Age} from ${NeiIP}\].*\[AS${OriginAS}.\] ->
> Record
>   ^Table -> Start
>
> </routes.textfsm>
>
> <routecount.textfsm>
>
> Value Table (\S+)
> Value Routes (\d+)
> Value Total (\d+)
> Value Networks (\d+)
> Value Tables (\d+)
>
> Start
>   ^${Routes} of ${Total} routes for ${Networks} networks in table ${Table}
> -> Record
>   ^Total: ${Routes} of ${Total} routes for ${Networks} networks in
> ${Tables} tables -> Record
>
> </routecount.textfsm>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://trubka.network.cz/pipermail/bird-users/attachments/20210511/def758f4/attachment.htm>


More information about the Bird-users mailing list