Splunk Search

How to get an "eval if else" condition to continue a search depending on the resulting field?

gamification
Explorer

Hello,

I would like to know if it's possible to do certain part of search with if statement on a field.

For example:

index="test" | head 1 | eval field = lastUpdate ((lastUpdate is an extracted field)) | eval date = strptime( field ,"%Y.%m.%d %H:%M.%S")

The problem here is field is sometimes null, sometimes not, so strptime may not work correctly. So what I would like to do is:

index="test | head 1 | eval field = lastUpdate | if field ="2014.01.12" ----> parse it | else .....

Don't focus on my example, the thing that I don't understand is how to do the if else.

Thanks for help.

1 Solution

somesoni2
SplunkTrust
SplunkTrust

Try this

index="test" | head 1 | eval field = lastUpdate ((lastUpdate is an extracted field)) | eval date = if(isnotnull(field),strptime( field ,"%Y.%m.%d %H:%M.%S"),now())

OR

index="test" lastUpdate=* | eval field = lastUpdate ((lastUpdate is an extracted field)) | eval date = strptime( field ,"%Y.%m.%d %H:%M.%S")

View solution in original post

somesoni2
SplunkTrust
SplunkTrust

Try this

index="test" | head 1 | eval field = lastUpdate ((lastUpdate is an extracted field)) | eval date = if(isnotnull(field),strptime( field ,"%Y.%m.%d %H:%M.%S"),now())

OR

index="test" lastUpdate=* | eval field = lastUpdate ((lastUpdate is an extracted field)) | eval date = strptime( field ,"%Y.%m.%d %H:%M.%S")

gamification
Explorer

Thanks 🙂 helped me.

0 Karma
Get Updates on the Splunk Community!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...