Splunk Search

Adding column based on values from other columns

Soogbad
Engager

I have this code that shows me the start and end times of runs of a program:

index=index1 source=source1 | transaction startswith="Execution started" endswith="Execution ended" | eval start_time=_time | eval end_time=_time + duration | table start_time end_time

I also have this search which searches for errors (in a different log file):

search index=index1 source=source2 severity=ERROR

What I need is to add another column in the table that shows the runs of the program that would show how many errors occurred during the run of the program.

For example, appendcols like this:

<times_search> | appendcols [ search <error_search> | stats count as errors by _time ]

But this has two problems:

1) it's by _time when I need it to be by run. I need the amount of all the errors that occurred between start_time and end_time..

2) it's not sorted like I need it to be. As it says in the documentation, it puts the first result at the first row and the second in the second and so on

How do I achieve this? 

Labels (4)
0 Karma
1 Solution

ITWhisperer
SplunkTrust
SplunkTrust
index=index1 source=source1 OR (source=source2 severity=ERROR)
| sort - _time
| streamstats last(eval(if(match(_raw,"Execution ended"),_time,null)) as end
| stats count(eval(if(severity="ERROR",1,null))) as errors by end

View solution in original post

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust

Do both sources have timestamps?

What about errors which occur after one end but before the next start?

0 Karma

Soogbad
Engager

Yes both sources have timestamps. Something like _time > start_time and _time < end_time would work. And  no there are no errors in between runs the errors are the program's errors they can't occur when it's not running.

0 Karma

ITWhisperer
SplunkTrust
SplunkTrust
index=index1 source=source1 OR (source=source2 severity=ERROR)
| sort - _time
| streamstats last(eval(if(match(_raw,"Execution ended"),_time,null)) as end
| stats count(eval(if(severity="ERROR",1,null))) as errors by end
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!

May 2026 Splunk Expert Sessions: Security & Observability

Level Up Your Operations: May 2026 Splunk Expert Sessions Whether you are refining your security posture or ...

Network to App: Observability Unlocked [May & June Series]

In today’s digital landscape, your environment is no longer confined to the data center. It spans complex ...

SPL2 Deep Dives, AppDynamics Integrations, SAML Made Simple and Much More on Splunk ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...