TextFSM - sjherrick/code-base GitHub Wiki
TextFSM
https://github.com/google/textfsm/wiki
Python
import textfsm
template = open('template.textfsm')
re_table = textfsm.TextFSM(template)
fsm_results = re_table.ParseText(raw_text_data)
Templates
- Filldown- Carries the value over to subsequent entries if same field is blank
Value Filldown SWITCHNAME (\w+\.\w+)
Example
# Carry down the local end information so that it is present on each row item.
Value SWITCHNAME (\w+\.\w+)
Value PLATFORM (.*)
Value LOCALIF (\w+)
Value LOCALPORT (0/0?/?\d+)
Value REMOTEIF (\w+)
Value REMOTEPORT ([0|1]/[0|1]?/?\d+)
Value MGMTIP (\d+(\.\d+){3})
Start
^Device ID: ${SWITCHNAME}\.\w+
^\s+IP address: ${MGMTIP}
^Platform: cisco ${PLATFORM},
^Interface: ${LOCALIF}${LOCALPORT}, Port ID \(outgoing port\): ${REMOTEIF}${REMOTEPORT} -> Record
# Last record is already recorded then skip doing so here.
EOF
- Output
['CISCO-TEST', 'ME-3400E-24TS-M', 'GigabitEthernet', '0/0/12', 'GigabitEthernet', '0/1', '192.168.0.1'], ['CISCO-TEST', 'ME-3400E-24TS-M', 'GigabitEthernet', '0/0/13', 'GigabitEthernet', '0/1', '192.168.0.2'](/sjherrick/code-base/wiki/'CISCO-TEST',-'ME-3400E-24TS-M',-'GigabitEthernet',-'0/0/12',-'GigabitEthernet',-'0/1',-'192.168.0.1'],-['CISCO-TEST',-'ME-3400E-24TS-M',-'GigabitEthernet',-'0/0/13',-'GigabitEthernet',-'0/1',-'192.168.0.2')