Splunk Enterprise Security

Splunk Enterprise Security: Can you provide a function which returns a string in an if statement?

panovattack
Communicator

Can you provide a function which returns a string in an if statement? For example:

if(src=="-" OR src=="127.0.0.1", Computer, trim(Source_Workstation,"some string")), reads as:

if src = - or 127.0.0.1, return the value of the Computer field. Else, return as string value of trim, where some string has been removed.

When I run this eval, the first result performs as expected. However, the trim statement returns 1 or 0. In testing, this reports whether the trim actually trimmed anything (1 for yes, 0 for no). If I pipe as separate command, then I get the expected results (e.g. eval src=trim(Source_Workstation,"some string")). However, I want this to be in a calculated field extraction and I can't seem to have multiple calculations running over the same field (makes sense). This is an attempt to remove the leading "::ffff:" from some Windows event logs.

0 Karma
1 Solution

panovattack
Communicator

I was able to solve by appending a dollar sign to the field name $somefield from the sub search e.g. [search * | table foo | return $foo]

View solution in original post

0 Karma

panovattack
Communicator

I was able to solve by appending a dollar sign to the field name $somefield from the sub search e.g. [search * | table foo | return $foo]

0 Karma

Richfez
SplunkTrust
SplunkTrust

You could try rex instead using mode=sed. Assuming the field you are working on is the Source_Workstation, that would be

... | rex mode=sed field=Source_Workstation "s/^::ffff://"

The rex string says to s substitute whenever you see what's between the first two slashes ^::ffff: (the carrot means at the start of that field) the values between the second two (which is empty).

I don't have test data that matches yours right now, so I'm guessing. You can try dropping off the ^ at the front if it doesn't work with it. Otherwise, if you can paste in a couple of the actual strings I can tweak it a bit if necessary.

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!

Persistent Queue at TcpOut — One of Splunk's Most Practical Features

Splunk introduced persistent queueing at the tcpout layer as one of the most practical resilience features in ...

Skip the Awkward Silence: Have a .conf-ersation at .conf26

Picture this. You arrive at .conf26 already having your socializing and networking plans mapped out. No ...

Rethinking Zero Trust: From Product Purchases to Logical Control Evidence

Implementing Zero Trust (ZT) across complex environments often falters at the very beginning due to a ...