Solved

Splunk REGEX working perfectly for single line, not detecting multiline

Posted on 2016-10-19
6
26 Views
Last Modified: 2016-10-25
Hello Experts,

I'm running Splunk to grab some live data off a switch and my regular expression is working great when it comes in a single line. However sometimes when the events happen too close together (which is common) the data comes in with multiple lines and the regex then only catches the first line. I googled it and everything I found said to just add (?m) to the beginning but that doesn't seem to be working. Here's a screenshot of the missing data from any more than one received at a time.
splunk-regex.png
0
Comment
Question by:EndTheFed
  • 3
  • 3
6 Comments
 
LVL 35

Expert Comment

by:Terry Woods
ID: 41851465
You could try (?gm) instead of (?m) to try to capture the extra result. Let me know if it works
0
 
LVL 35

Assisted Solution

by:Terry Woods
Terry Woods earned 500 total points
ID: 41851513
If that doesn't work, could you please copy and paste your pattern; I have another idea
0
 
LVL 35

Expert Comment

by:Terry Woods
ID: 41851578
I'm not familiar with Splunk (my focus is on regex in general, and in other languages), but it appears using the max_match argument could work (with 0 for unlimited):
rex max_match=0 "(?m)^yourpattern"

Open in new window


Details here:
http://docs.splunk.com/Documentation/Splunk/6.4.3/SearchReference/Rex

You'll still need the (?m) because you want the ^ in your pattern to match the start of each line.
0
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 

Author Comment

by:EndTheFed
ID: 41852454
Thank you for the quick reply! Unfortunately it doesn't look like either of those are working.
When I try (?gm) it fails completely with "Regex: unrecognized character after (? or (?-"
When I tried rex max_match=0 "(?m)^mypattern" I don't get an error on the syntax but it then doesn't match anything, not even the first line. I also tried max_match=1 and max_match=10 just to see what would happen, still nothing.
0
 

Accepted Solution

by:
EndTheFed earned 0 total points
ID: 41852469
Your asking to see my pattern made me go back and check the Event breaks at the Source type and I then realized... it's not set by pattern. Oops. Splunk has three options for event breaks, Auto (which is what it was set to), Every Line, and Regex (where you can specify a pattern for event breaks). I didn't think the Every Line option was functioning but it turns out for that type of change the service had to be restarted. Now set to Every Line (no pattern) and working.

If anyone comes across a similar issue to this (which I imagine is fairly common) change your Event Break to Every Line and restart the splunkd service.
1
 

Author Closing Comment

by:EndTheFed
ID: 41858259
Error on my part. Should have restarted service to be certain.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Outsource Your Fax Infrastructure to the Cloud (And come out looking like an IT Hero!) Relative to the many demands on today’s IT teams, spending capital, time and resources to maintain physical fax servers and infrastructure is not a high priority.
Use of TCL script on Cisco devices:  - create file and merge it with running configuration to apply configuration changes
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now