Splunk Search

conditional if based on multiple condition

k_harini
Communicator

I have to get the count of records with multiple status and due date less than current date..

Below query - This query works for single status means only Prod.. I get error on clubbing multiple status
index = "my index" Transaction_Type =* Priority=* Category=* |eventstats count as Total_Events |eval due_time= strptime('Due By',"%d.%m.%Y") |eval now_time= now() |stats count as Total_events count(eval((due_time <= now_time) AND ('Status'!="Prod" OR 'Status'!="Go Live" OR 'Status'!="Completed"))) as Missed_count

Please help

Tags (1)
0 Karma
1 Solution

niketn
Legend

Few points about searches

1) They are more efficient if you use positive scenarios rather than negative (or NOT) scenarios i.e. if you know which status you need include only those.

2) You should filter results upfront rather than later. This will give most performance improvement.
IN the above case I assume Status is part of your extracted fields then

index = "my index" Transaction_Type=* Priority=* Category=* AND NOT (Status="Prod" OR Status="Go Live" OR Status="Completed") |eventstats count as Total_Events |eval due_time= strptime('Due By',"%d.%m.%Y") |eval now_time= now() |stats count as Total_events count(eval((due_time <= now_time))) as Missed_count

3) You should also be converting now_time to dd.mm.YYYY format.

PS: If you want to continue to use your existing query you can try the following since you are applying not for each conditions, OR should be replaced with AND:

index = "my index" Transaction_Type = Priority= Category=* |eventstats count as Total_Events |eval due_time= strptime('Due By',"%d.%m.%Y") |eval now_time= now() |stats count as Total_events count(eval((due_time <= now_time) AND ('Status'!="Prod" AND 'Status'!="Go Live" AND 'Status'!="Completed"))) as Missed_count
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"

View solution in original post

0 Karma

niketn
Legend

Few points about searches

1) They are more efficient if you use positive scenarios rather than negative (or NOT) scenarios i.e. if you know which status you need include only those.

2) You should filter results upfront rather than later. This will give most performance improvement.
IN the above case I assume Status is part of your extracted fields then

index = "my index" Transaction_Type=* Priority=* Category=* AND NOT (Status="Prod" OR Status="Go Live" OR Status="Completed") |eventstats count as Total_Events |eval due_time= strptime('Due By',"%d.%m.%Y") |eval now_time= now() |stats count as Total_events count(eval((due_time <= now_time))) as Missed_count

3) You should also be converting now_time to dd.mm.YYYY format.

PS: If you want to continue to use your existing query you can try the following since you are applying not for each conditions, OR should be replaced with AND:

index = "my index" Transaction_Type = Priority= Category=* |eventstats count as Total_Events |eval due_time= strptime('Due By',"%d.%m.%Y") |eval now_time= now() |stats count as Total_events count(eval((due_time <= now_time) AND ('Status'!="Prod" AND 'Status'!="Go Live" AND 'Status'!="Completed"))) as Missed_count
____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

k_harini
Communicator

Thank you so much.. It worked.. Problem is I have to calculate the %. Hence If i give in base search I will not be able to get total count to calculate % . In the first query my Total_Events is same as Missed_count..

If there is any other better approach please let me know.. Thanks a lot..

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!

Unlocking Unified Insights: New Gigamon Federated Search App for Splunk

In today’s data-heavy environment, organizations are caught in a data distribution dilemma. As data volumes ...

GA: New Data Management App in Splunk Platform

Streamlining Data Management: Introducing a unified experience in Splunk Managing data at scale shouldn’t feel ...

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 ...