Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

textfsm return repetitive same interface for stackwise link

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 :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

[['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?

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading