textfsm return repetitive same interface for stackwise link

45 views Asked by At

I am trying to parse value from stackwise link output from Cisco router using textfsm but it seems like the textfsm config file is incorrect because it return the repetitive interface details. Below are sample of textfsm config.

Stackwise Virtual Link(SVL) Information:
----------------------------------------
Flags:
------
Link Status
-----------
U-Up D-Down
Protocol Status
---------------
S-Suspended P-Pending E-Error T-Timeout R-Ready
-----------------------------------------------
Switch  SVL     Ports                           Link-Status     Protocol-Status
------  ---     -----                           -----------     ---------------
1       1       TwentyFiveGigE1/0/1            U               R              
                TwentyFiveGigE1/0/2            U               R              
                TwentyFiveGigE1/0/3            U               R              
2       1       TwentyFiveGigE2/0/4            U               R              
                TwentyFiveGigE2/0/1            U               R              
                TwentyFiveGigE2/0/2            U               R   
                TwentyFiveGigE2/0/3            U               R   



Created template:

Value Required,Filldown SWITCH (\d)
Value Required,Filldown SVL (\d)   
Value Required,Filldown PORTS (\S+)
Value Required,Filldown LINK_STATUS (\S+)
Value Required,Filldown PROTOCOL_STATUS (\S+)

Start
  ^Switch(\s+([A-Za-z]+\s+)+)[A-Za-z]+-([A-Za-z]+(\s+[A-Za-z]+)+)-[A-Za-z]+ -> Continue
  ^------  ---     -----                           -----------     ---------------
  ^${SWITCH}\s+${SVL}.*  -> Continue
  ^(\d+)\s+(\d+)\s+${PORTS}\s+${LINK_STATUS}\s+${PROTOCOL_STATUS}\s+? -> Continue
  ^.* -> Record

EOF

but the output looks like :

[['1', '1', 'TwentyFiveGigE1/0/1', 'U', 'R'], ['1', '1', 'TwentyFiveGigE1/0/1', 'U', 'R'], ['1', '1', 'TwentyFiveGigE1/0/1', 'U', 'R'], ['2', '1', 'TwentyFiveGigE2/0/1', 'U', 'R'], ['2', '1', 'TwentyFiveGigE2/0/1', 'U', 'R'], ['2', '1', 'TwentyFiveGigE2/0/1', 'U', 'R']]

unable to fix any lead?

1

There are 1 answers

0
sleepystar96 On BEST ANSWER

You were pretty close; you just need to match on (\d+ OR nothing) in your PORTS line: (\d+|)

Value Required,Filldown SWITCH (\d)
Value Required,Filldown SVL (\d)   
Value Required,Filldown PORTS (\S+)
Value Required,Filldown LINK_STATUS (\S+)
Value Required,Filldown PROTOCOL_STATUS (\S+)

Start
  ^Switch(\s+([A-Za-z]+\s+)+)[A-Za-z]+-([A-Za-z]+(\s+[A-Za-z]+)+)-[A-Za-z]+ -> Continue
  ^------  ---     -----                           -----------     ---------------
  ^${SWITCH}\s+${SVL}.*  -> Continue
  ^(\d+|)\s+(\d+|)\s+${PORTS}\s+${LINK_STATUS}\s+${PROTOCOL_STATUS}\s+? -> Continue
  ^.* -> Record

EOF

Output:

LINK_STATUS PORTS   PROTOCOL_STATUS SVL SWITCH
U   TwentyFiveGigE1/0/1 R   1   1
U   TwentyFiveGigE1/0/2 R   1   1
U   TwentyFiveGigE1/0/3 R   1   1
U   TwentyFiveGigE2/0/4 R   1   2
U   TwentyFiveGigE2/0/1 R   1   2
U   TwentyFiveGigE2/0/2 R   1   2
U   TwentyFiveGigE2/0/3 R   1   2