Splunk Search

How to compare using eval expression and field value pair

k_harini
Communicator

I want the table to be generated based on 2 conditions - one condition is comparing eval expression and other field value pair.. how to do that
index="myindex" |eval Due_Date_Time = strftime(strptime('Due By',"%d.%m.%Y"),"%d.%m.%Y")|eval now_time=strftime(now(),"%d.%m.%Y")|table ID,Category | where (now_time>=Due_Date_Time) AND ('System Status'!="Completed")

This where clause is not working.. please help

Tags (1)
0 Karma
1 Solution

inventsekar
SplunkTrust
SplunkTrust

i dont have logs to test this, can you check this once -

index="myindex" |eval Due_Date_Time = strftime(strptime('Due By',"%d.%m.%Y"),"%d.%m.%Y")|eval now_time=strftime(now(),"%d.%m.%Y")|table ID,Category | where (now_time>=Due_Date_Time) | search 'System Status'!="Completed"

or even, you can try checking the System Status at first stage itself -

index="myindex" 'System Status'!="Completed" |eval Due_Date_Time = strftime(strptime('Due By',"%d.%m.%Y"),"%d.%m.%Y")|eval now_time=strftime(now(),"%d.%m.%Y")|table ID,Category | where (now_time>=Due_Date_Time) 

View solution in original post

0 Karma

javiergn
Super Champion

I can see two issues:

1) Your "|table ID,Category" is getting rid of some fields you are using later on such as now_time, System Status or Due_Date_Time.
2) I think this part is also going to cause you a headache as you are not comparing integers with integers, just strings with strings:

 where (now_time>=Due_Date_Time)

Can you try this instead?

index="myindex" 
|eval Due_Date_Epoch = strptime('Due By',"%d.%m.%Y")
|table ID, Category, Due_Date_Epoch, 'System Status'
| where (now() >= Due_Date_Epoch) AND ('System Status'!="Completed")

Thanks,
J

0 Karma

k_harini
Communicator

Thanks for your reply. This is also not working..

0 Karma

inventsekar
SplunkTrust
SplunkTrust

i dont have logs to test this, can you check this once -

index="myindex" |eval Due_Date_Time = strftime(strptime('Due By',"%d.%m.%Y"),"%d.%m.%Y")|eval now_time=strftime(now(),"%d.%m.%Y")|table ID,Category | where (now_time>=Due_Date_Time) | search 'System Status'!="Completed"

or even, you can try checking the System Status at first stage itself -

index="myindex" 'System Status'!="Completed" |eval Due_Date_Time = strftime(strptime('Due By',"%d.%m.%Y"),"%d.%m.%Y")|eval now_time=strftime(now(),"%d.%m.%Y")|table ID,Category | where (now_time>=Due_Date_Time) 

0 Karma

k_harini
Communicator

Thanks for your reply.. both are not working

second one works till here.. where clause time condition not working 😞
index="myindex" "System Status"!="Completed"|eval Due_Date_Time = strftime(strptime('Due By',"%d.%m.%Y"),"%d.%m.%Y")|eval now_time=strftime(now(),"%d.%m.%Y")|table ID,Category

0 Karma

inventsekar
SplunkTrust
SplunkTrust
 index="myindex" 'System Status'!="Completed"
  |eval Due_Date = strptime('Due By',"%d.%m.%Y") 
  | where (now() >= Due_Date)
  |table ID, Category
0 Karma

k_harini
Communicator

It worked the way i wanted.. Thank you so much..

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...