Getting Data In

Problems with line breaks in a config file

jambajuice
Communicator

I am trying to configure line breaking for a config file that looks like the following (I'm using 4 spaces to indent some of the lines, but it isn't working in the preview). Only the first config and last end start at the beginning of a new line. All of the other lines have multiple spaces or tabs:

config firewall profile-protocol-options  
    edit "strict"  
        config http  
            set port 80   
            set port 8080   
            unset options  
            unset post-lang  
        end  
        config https  
            set port 443   
            set port 8000   
            set options allow-invalid-server-cert no-content-summary  
            unset post-lang  
            set deep-scan enable  
        end  
end

I want to break the event at the first "config" and the last "end". I do not want it to break before/after any config or end line that is preceded by one or more spaces.

I have tried the following at none of them break properly:

[fortinet_config]
SHOULD_LINEMERGE = true
MUST_BREAK_AFTER = [^\s]end
BREAK_ONLY_BEFORE = [^\s]config

[fortinet_config]
SHOULD_LINEMERGE = true
MUST_BREAK_AFTER = (?i)^end
BREAK_ONLY_BEFORE = (?i)^config

[fortinet_config]
SHOULD_LINEMERGE = true
MUST_NOT_BREAK_BEFORE= (?i)^end
MUST_NOT_BREAK_AFTER = (?i)^config

[fortinet_config]
SHOULD_LINEMERGE = true
MUST_NOT_BREAK_BEFORE= (?i)end
MUST_NOT_BREAK_AFTER = (?i)config

Thanks.

Tags (1)

gkanapathy
Splunk Employee
Splunk Employee

Here's the best way:

[fortinet_config]
SHOULD_LINEMERGE = false
LINE_BREAKER = ([\r\n]+)(?=config)

It should get you the same results as the possibly clearer but less performant:

[fortinet_config]
SHOULD_LINEMERGE = true
BREAK_ONLY_BEFORE = ^config
0 Karma

gkanapathy
Splunk Employee
Splunk Employee

You might add a (?i) to the beginning of the LINE_BREAKER regex if in fact it's supposed to be case-insensitive.

0 Karma

jrodman
Splunk Employee
Splunk Employee

I'm feeling stupid tonight, so don't I don't want to get deep into the interaction of MUST_BREAK_AFTER and BREAK_ONLY_BEFORE. If everything is in one of these, you shouldn't need both. We can dig in later if it's needed?

The first ruleset is looking for words like 'config' which have somethig besides backslash or s before them. I think you want BREAK_ONLY_BEFORE = ^config Does that work alone?

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

[Puzzles] Solve, Learn, Repeat: Character substitutions with Regular Expressions

This challenge was first posted on Slack #puzzles channelFor BORE at .conf23, we had a puzzle question which ...

Splunk Community Badges!

  Hey everyone! Ready to earn some serious bragging rights in the community? Along with our existing badges ...

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...