Solved

Splunk REGEX working perfectly for single line, not detecting multiline

Posted on 2016-10-19
6
45 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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 

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

Surfing Is Meant To Be Done Outdoors

Featuring its rugged IP67 compliant exterior and delivering broad, fast, and reliable Wi-Fi coverage, the AP322 is the ideal solution for the outdoors. Manage this AP with either a Firebox as a gateway controller, or with the Wi-Fi Cloud for an expanded set of management features

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Messaging apps are amazing tools with the power to do a lot of good, but the truth is the process of collaborating with coworkers requires relationships established through meaningful communication - the kind of communication that only happens face-…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
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…

733 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