redcode
redcode

Reputation: 91

Parse hierarchical text output with textfsm

I'm having some trouble to parse hierarchical data from an equipment with textfsm.

The data is something similar to that:

pcc-filter-base-name : P2P-BASE
filter = 1337x
filter-state = enabled
flow-inactivity-time = 0
flow-initiation = uplink
l7-uri = 1337x:
precedence = 1
protocol-id = 0

filter = abc
filter-state = enabled
flow-inactivity-time = 0
flow-initiation = uplink
l7-uri = abc:
precedence = 2
protocol-id = 0

filter = adc
filter-state = enabled
flow-inactivity-time = 0
flow-initiation = uplink
l7-uri = adc:
precedence = 3
protocol-id = 0

pcc-filter-base-name : FACEBOOK_FLEX-BASE
filter = IP_NET_1
destination-address = 157.240.24.32/29
destination-port-list = 80,443
filter-state = enabled
flow-inactivity-time = 0
flow-initiation = uplink
precedence = 1
protocol-id = 0

filter = IP_NET_2
destination-address = 157.240.25.32/29
destination-port-list = 80,443
filter-state = enabled
flow-inactivity-time = 0
flow-initiation = uplink
precedence = 2
protocol-id = 0

filter = IP_NET_3
destination-address = 157.240.26.32/29
destination-port-list = 80,443
filter-state = enabled
flow-inactivity-time = 0
flow-initiation = uplink
precedence = 3
protocol-id = 0

I was trying to parse it with this template:

Value Filldown filter_base_name (\S+)
Value Required filter (\S+)
Value filter_state (\S+)
Value flow_inactivity_time (\S+)
Value flow_initiation (\S+)
Value l7_uri (\S+)
Value Required precedence (\S+)
Value protocol_id (\S+)
Value destination_address (\S+)
Value destination_port_list (\S+)


Start
 ^pcc-filter-base-name : ${filter_base_name} -> Filter

Filter
 ^filter = ${filter}
 ^filter-state = ${filter_state}
 ^flow-inactivity-time = ${flow_inactivity_time}
 ^flow-initiation = ${flow_initiation}
 ^l7-uri = ${l7_uri}
 ^precedence = ${precedence}
 ^protocol-id = ${protocol_id}
 ^destination-address = ${destination_address}
 ^destination-port-list = ${destination_port_list}
 ^pcc-filter-base-name : ${filter_base_name} -> Record Start

However this is far away from the result I was expecting, which isto gather all filters from each filter-base.

I've tried several approaches so far, but I have no idea of what I'm doing, maybe textfsm is not the right tool for that job?

Thanks in advance for the help.

Upvotes: 0

Views: 319

Answers (1)

redcode
redcode

Reputation: 91

Seems like I've only needed to post the question to get an answer by myself...

Value Filldown filter_base_name (\S+)
Value Required filter (\S+)
Value filter_state (\S+)
Value flow_inactivity_time (\S+)
Value flow_initiation (\S+)
Value l7_uri (\S+)
Value Required precedence (\S+)
Value protocol_id (\S+)
Value destination_address (\S+)
Value destination_port_list (\S+)


Start
 ^pcc-filter-base-name : ${filter_base_name} -> Next.Record
 ^filter = ${filter}
 ^filter-state = ${filter_state}
 ^flow-inactivity-time = ${flow_inactivity_time}
 ^flow-initiation = ${flow_initiation}
 ^l7-uri = ${l7_uri}
 ^precedence = ${precedence}
 ^protocol-id = ${protocol_id} -> Next.Record
 ^destination-address = ${destination_address}
 ^destination-port-list = ${destination_port_list}

Upvotes: 1

Related Questions