Reporting

To create a dynamic report using eval splunk.

tvon1990
Explorer

|eval Actual_Start_Time=[search index=index ESP_JOB=$Start_Job$ JOB_STATUS=EXEC|return $_time]
how to write if condition to return _time if the serach returns result or hardcode 00:00

Tags (1)
0 Karma
1 Solution

DalJeanis
Legend

Basically, you just adjust your internal search until you are happy with the results, then put it back into your subsearch.

For example, your current subsearch, as a search, would be ...

  index=index ESP_JOB=$Start_Job$ JOB_STATUS=EXEC
 |table _time

You need to make sure you are getting exactly one record, and then if it has nothing in it, you want to override the value. There are lots of ways to do this, but here's one

  index=index ESP_JOB=$Start_Job$ JOB_STATUS=EXEC
 | head 1
 | stats count as mycount first(_time) as _time 
 | eval _time=if(count=0,0,_time)
 | table _time

Since splunk defaults to return records most recent first, that will return the _time of the most recent matching record, or it will return 0 if there are no matching records.

Now, we wrap that in your square braces and it should work.

|eval Actual_Start_Time=[index=index ESP_JOB=$Start_Job$ JOB_STATUS=EXEC
     | head 1
     | stats count as mycount first(_time) as _time 
     | eval _time=if(count=0,0,_time)
     | return $_time]

View solution in original post

DalJeanis
Legend

Basically, you just adjust your internal search until you are happy with the results, then put it back into your subsearch.

For example, your current subsearch, as a search, would be ...

  index=index ESP_JOB=$Start_Job$ JOB_STATUS=EXEC
 |table _time

You need to make sure you are getting exactly one record, and then if it has nothing in it, you want to override the value. There are lots of ways to do this, but here's one

  index=index ESP_JOB=$Start_Job$ JOB_STATUS=EXEC
 | head 1
 | stats count as mycount first(_time) as _time 
 | eval _time=if(count=0,0,_time)
 | table _time

Since splunk defaults to return records most recent first, that will return the _time of the most recent matching record, or it will return 0 if there are no matching records.

Now, we wrap that in your square braces and it should work.

|eval Actual_Start_Time=[index=index ESP_JOB=$Start_Job$ JOB_STATUS=EXEC
     | head 1
     | stats count as mycount first(_time) as _time 
     | eval _time=if(count=0,0,_time)
     | return $_time]
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!

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

SplunkTrust Application Period is Officially OPEN!

It's that time, folks! The application/nomination period for the 2026-2027 SplunkTrust is officially open. If ...