perl_lover has asked for the wisdom of the Perl Monks concerning the following question:

Is there any parser available to parse juniper firewall config files? This is little complex to parse as each option inside the term is optional.
Sample firewall configuration file
firewall { family inet { replace: filter simple-test { term pdq-test { then { accept; } } } filter abx { term def { from { source-address { 1.1.1.1 }; } then { accept; } } } } }

Replies are listed 'Best First'.
Re: Juniper firewall parser
by Marshall (Canon) on May 24, 2010 at 14:30 UTC
    Better would be to attach some actual lines of example Juniper config file output and your attempt at parsing it in Perl. Update: I guess that it could be that "Sample firewall configuration file " is actually some real file, if so then what do you want to do with it?
      I want to parse and extract filter and term information. filter definition can have multiple term definition in it. Inside term <term-name> { .* }, you will have multiple configuration like source-address { }. I want to extract all those information. It is difficult to parse these through RegEx as all the fields inside the term are optional and can occur in any order
        please show at least an output from your input.
        I've never heard of juniper firewall, and I don't recognize the format. You should ask the makers of juniper for a format specification and/or a parser.
Re: Juniper firewall parser
by rowdog (Curate) on May 25, 2010 at 09:22 UTC

    It looks like one of the JUNOS modules might be useful.