Splunk Search

How do I formulate a regex to discard events when applying sourcetype?

andrewtrobec
Motivator

Hello,
I'm currently creating a new sourcetype that has a TRANSFORMS-null setting with value discardit. Within my transforms.conf file I have created the appropriate stanza:

[discardit]
REGEX=(^|[\r\n])(.+,.+,.+,.+,"",.+)
DEST_KEY = queue
FORMAT = nullQueue

The regex that I've written is currently not working and I would like some help in formulating it.

The events are coming from csv files with the following header:

"Server","Job","Status","Start","End","Run Machine","Command"

My objective is to not index the events that have no value for End, so events that look like this:

"Server1","Job1","Running","2018-02-01 00:00:00","","Machine 1","Command 1"

The regex that I've written basically counts 4 commas and then checks to see whether the two characters after the fourth comma are "" (meaning that the value for Run is blank).

What am I missing?

Best regards,

Andrew

Tags (1)
0 Karma

micahkemp
Champion

Where is this props/transforms in place? On the indexer, heavy forwarder, universal forwarder, or search head?

0 Karma

andrewtrobec
Motivator

@micahkemp They are both in the $SPLUNK_HOME/etc/apps//local folder. It's a single server instance.

0 Karma

FrankVl
Ultra Champion

Do you really need that complex bit with the \r\n?

Shouldn't this regex suffice (https://regex101.com/r/rbEHqz/1):

REGEX=^.+,.+,.+,.+,"",.+

Apart from that: what does your Splunk environment look like? Single instance, or distributed? If distributed, where did you deploy this config (should be on the first heavy instance, either HF or Indexer)?

andrewtrobec
Motivator

@FrankVl Thanks for the suggestion. This doesn't solve the problem, and I've no idea why. I will continue to make changes and test until something starts working.

My Splunk environment is a single instance. The config is in the $SPLUNK_HOME/etc/apps//local folder.

If you have any additional suggestions then please let me know!

0 Karma

493669
Super Champion

Hi @andrewtrobec,
you need to escape quotes by using back slashes
try this:

[discardit]
 REGEX=(^|[\r\n])(.+,.+,.+,.+,\"\",.+)
 DEST_KEY = queue
 FORMAT = nullQueue

andrewtrobec
Motivator

Thanks for the suggestion. unfortunately adding the back slashes did not work. Do you have any other suggestions?

0 Karma

493669
Super Champion

Is your props.conf and transforms.conf files are in indexer/HWF?
I tried regex in splunk, it works as expected..

|makeresults|eval _raw="\"Server\",\"Job\",\"Status\",\"Start\",\"End\",\"\",\"Command\""|rex "(?<nulldata>(^|[\r\n])(.+,.+,.+,.+,\"\",.+))"
0 Karma

andrewtrobec
Motivator

Yes, I am currently working on a single server instance. To test I am using the Add data wizard to see whether the lines disappear in the preview, and they do not. Am I correct to expect them to get removed there, or do I need to go ahead and index?

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!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...