mpenning / ciscoconfparse

Parse, Audit, Query, Build, and Modify Arista / Cisco / Juniper / Palo Alto / F5 configurations.
http://www.pennington.net/py/ciscoconfparse/
GNU General Public License v3.0
796 stars 220 forks source link

[Bug]: Issue parsing F5 BigIP config file #287

Closed i-m-d closed 9 months ago

i-m-d commented 1 year ago

Contact Details

mundoimd@gmail.com

What happened?

I am using CiscoConfigParse to parse F5 BigIP configuration files, which work very well, but i have a bug, but i think the problem is how F5 config file write the config, i explain:

if a code block contains a "{" and after contains text WITHOUT a "}" in the same LINE, the parse do not work correctly.

if a code block contains text before a "}" and not a "{" in the same LINE, the parse do not work correctly.

Config sample1 that parse OK:

sys syslog {
    remote-servers {
        /Common/remotesyslog1 {
            host 10.0.0.45
        }
    }
}
sys diags ihealth {
    expiration 30
    no-ihealth false
    options none
    password none
    user none
}

Config sample2 that parse with ERROR:

sys syslog {
    remote-servers {
        /Common/remotesyslog1 {   host 10.0.0.45
        }
    }
}
sys diags ihealth {
    expiration 30
    no-ihealth false
    options none
    password none
    user none
}

Config sample3 that parse with ERROR:

sys syslog {
    remote-servers {
        /Common/remotesyslog1 {
           host 10.0.0.45   }
    }
}
sys diags ihealth {
    expiration 30
    no-ihealth false
    options none
    password none
    user none
}

CiscoConfParse Version

Version 1.7.24

What Operating System are you using?

Linux - Debian, Ubuntu, CentOS, RHEL or others

What Python version(s) have this problem?

Python 3.9

Show us how to reproduce the problem. Please tell us if the problem is specific to certain inputs or situations.

# config sample1 OK

In [1]: from ciscoconfparse import CiscoConfParse

In [2]: config_file = "sample1"

In [3]: configparse = CiscoConfParse(config_file, syntax='junos', comment='#')

In [4]: configparse.find_objects('^sys ')[0].children
Out[4]: [<IOSCfgLine # 1 '    remote-servers' (parent is # 0)>]

In [5]: configparse.find_objects('^sys ')[1].children
Out[5]:
[<IOSCfgLine # 5 '    expiration 30' (parent is # 4)>,
 <IOSCfgLine # 6 '    no-ihealth false' (parent is # 4)>,
 <IOSCfgLine # 7 '    options none' (parent is # 4)>,
 <IOSCfgLine # 8 '    password none' (parent is # 4)>,
 <IOSCfgLine # 9 '    user none' (parent is # 4)>]

# config sample2 ERROR

In [1]: from ciscoconfparse import CiscoConfParse

In [2]: config_file = "sample2"

In [3]: configparse = CiscoConfParse(config_file, syntax='junos', comment='#')

In [4]: configparse.find_objects('^sys ')[0].children
Out[4]: [<IOSCfgLine # 1 '    remote-servers' (parent is # 0)>]

In [5]: configparse.find_objects('^sys ')[1].children
Out[5]: []

# config sample3 ERROR

In [1]: from ciscoconfparse import CiscoConfParse

In [2]: config_file = "sample3"

In [3]: configparse = CiscoConfParse(config_file, syntax='junos', comment='#')

In [4]: configparse.find_objects('^sys ')[0].children
Out[4]:
[<IOSCfgLine # 1 '    remote-servers' (parent is # 0)>,
 <IOSCfgLine # 4 '    sys diags ihealth' (parent is # 0)>]

In [5]: configparse.find_objects('^sys ')[1].children
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Input In [5], in <cell line: 1>()
----> 1 configparse.find_objects('^sys ')[1].children

IndexError: list index out of range

Python tracebacks

NO TRACEBACK

Relevant log output

No response

Code of Conduct

mpenning commented 1 year ago

Please add the entire F5 configuration, including all the info mentioned above; I won't try to tackle part of this problem without seeing what else may be broken in the config.

i-m-d commented 11 months ago

Sorry for delay.

The entire f5 configuration is over 25000 lines and has private info.

I can upload a portion with a few lines.

Cheers

i-m-d commented 11 months ago

The main problem is the irule config that is not formated, it is free format config. The f5 config (other than irule = ltm rule) is formated correctly by the system. The irule config are written in a text box with free format, so, curly brackets may be incorrectly set, so CiscoConfParse produces erroneous parsing.

mpenning commented 11 months ago

The entire f5 configuration is over 25000 lines and has private info.

Sanitize the private information and please email the file to me... penningtonthing@gmail.com. I will be forced to close this if I can't get a complete config file.

i-m-d commented 11 months ago

Hello @mpenning,

Here is the config:

config-f5.txt

The problem is after parsing ltm rule.

Cheers

mpenning commented 9 months ago

parse with ERROR:

sys syslog {
    remote-servers {
        /Common/remotesyslog1 {
           host 10.0.0.45   }
    }
}
sys diags ihealth {
    expiration 30
    no-ihealth false
    options none
    password none
    user none
}

This is fixed in ciscoconfparse2 version 0.5.0

FYI... several other things in the config-f5.txt do not parse correctly, but I will handle that as a different effort (which may require a dedicated parser).