0

I'm new to TextFSM and I'm trying to parse a BigIP F5 config using TextFSM. The final results only capturing one profile out of multiple profiles associated with a virtual server. I'm trying to get all of them captured.

I already tried a lot of TextFSM combination of commands but maybe I just fail to understand how it properly works.

Input

ltm virtual /Common/Cust_A_Virtual_Server {
    destination /Common/10.10.10.10:443
    ip-protocol tcp
    mask 255.255.255.255
    pool /Common/Cust_A_pool
    profiles {
        /Common/Cust_A_SSL {
            context clientside
        }
        /Common/Cust_A_http { }
        /Common/tcp { }
    }
    rules {
        /Common/Cust_A_iRule
    }
    source 0.0.0.0/0
    translate-address enabled
    translate-port enabled
    vlans {
        /Common/Cust_A_v1100
    }
    vlans-enabled
}

Current Result

{
    "virtual": "Cust_A_Virtual_Server",
    "virtualpart": "Common",
    "vprof": "tcp",
    "vprofpart": "Common"
}

Desired Result

{
    "virtual": "Cust_A_Virtual_Server",
    "virtualpart": "Common",
    "vprof": ["Cust_A_SSL","Cust_A_http","tcp"]
    "vprofpart": ["Common","Common","Common"]
}

I used below TextFSM template to get above "Current Result"

Value Filldown virtual (\S+)
Value Filldown virtualpart (\S+)
Value Required vprof ([a-zA-Z\/\-0-9.]+(?!:))
Value vprofpart (\S+)

Start
  ^ltm\svirtual\s\/${virtualpart}\/${virtual} -> Continue
  ^\s+profiles\s[{]\n+ -> Continue.Record
  ^\s+\/${vprofpart}\/${vprof}\s[{] -> Continue.Record
IPD86
  • 1

2 Answers2

0

I'm not familiar with TextFSM but wondering if instead of pulling from bigip.conf, grabbing from the REST API and re-working that output instead?

GET https:///mgmt/tm/ltm/virtual/<name_of_virtual>

and

GET https:///mgmt/tm/ltm/virtual/<name_of_virtual>/profiles

buulam
  • 36
  • 1
  • Unfortunately we cannot use REST API since we have range of devices running on different versions which does not support REST/SOAP APIs. Only option for us will be to scan the config files. Any config parsers for bigip.conf (based on RegEx/TextFSM) will help – IPD86 Nov 02 '21 at 22:08
0

Two things can help here: List option and the state transition. Template:

Value virtual (\S+)
Value virtualpart (\S+)
Value List vprof (\S+)
Value List vprofpart (\S+)

Start
  ^ltm\svirtual\s/${virtualpart}/${virtual}
  ^\s+profiles -> Profiles

Profiles
  ^\s+/${vprofpart}/${vprof}\s{
  ^\s+rules -> Record Start

Result:

 {'virtual': 'Cust_A_Virtual_Server',
  'virtualpart': 'Common',
  'vprof': ['Cust_A_SSL', 'Cust_A_http', 'tcp'],
  'vprofpart': ['Common', 'Common', 'Common']}