Splunk Search

Can I use the result of an eval command as a token further down the line in my search?

efferth
Path Finder

Hey y'all,

I have a chart that takes transaction data from processes that run at different intervals. Most processes run once per day, but one runs once per week. The end goal is to show the duration taken for the process by taking the difference in the time stamps from the start event and end event. I want to be able to show all of the data in the same dashboard panel, and to do that I am trying to run a search that goes something like this:

index=google_search_appliance (("checkForOrphans") AND ("Checking for orphaned documents" OR "orphaned assets added to the transaction table")) 
|eval pause_duration= if(process="connectweb","6d","23h") 
|transaction process maxpause=$pause_duration$ 
|table process orphan_count duration pause_duration

Can I correlate an eval to a token like this or is it not possible?

Thanks!

0 Karma
1 Solution

javiergn
Super Champion

See if the following helps as an alternative (not the most efficient approach and not tested):

index=google_search_appliance (("checkForOrphans") AND ("Checking for orphaned documents" OR "orphaned assets added to the transaction table")) process="connectweb"
|transaction process maxpause=6d
|table process orphan_count duration pause_duration
| append [
    | search index=google_search_appliance (("checkForOrphans") AND ("Checking for orphaned documents" OR "orphaned assets added to the transaction table")) NOT process="connectweb"
    |transaction process maxpause=23h
    |table process orphan_count duration pause_duration
]

Or you can always try to replace transaction with stats, streamstats, etc:

https://answers.splunk.com/answers/53748/alternative-to-transaction-command.html
https://answers.splunk.com/answers/103/transaction-vs-stats-commands.html

There are more answers if you do a quick search.

View solution in original post

woodcock
Esteemed Legend

You can indeed execute an eval statement and put the results into a token. The XML syntax is like this:

<eval token="myToken">tostring(round('field'))</eval>
0 Karma

javiergn
Super Champion

See if the following helps as an alternative (not the most efficient approach and not tested):

index=google_search_appliance (("checkForOrphans") AND ("Checking for orphaned documents" OR "orphaned assets added to the transaction table")) process="connectweb"
|transaction process maxpause=6d
|table process orphan_count duration pause_duration
| append [
    | search index=google_search_appliance (("checkForOrphans") AND ("Checking for orphaned documents" OR "orphaned assets added to the transaction table")) NOT process="connectweb"
    |transaction process maxpause=23h
    |table process orphan_count duration pause_duration
]

Or you can always try to replace transaction with stats, streamstats, etc:

https://answers.splunk.com/answers/53748/alternative-to-transaction-command.html
https://answers.splunk.com/answers/103/transaction-vs-stats-commands.html

There are more answers if you do a quick search.

efferth
Path Finder

The above search worked in my case! Thank you.

0 Karma

javiergn
Super Champion

No worries.
Please don't forget to mark it as answered in order to close this thread.

Thanks,
J

0 Karma
Get Updates on the Splunk Community!

Upcoming Webinar: Unmasking Insider Threats with Slunk Enterprise Security’s UEBA

Join us on Wed, Dec 10. at 10AM PST / 1PM EST for a live webinar and demo with Splunk experts! Discover how ...

.conf25 technical session recap of Observability for Gen AI: Monitoring LLM ...

If you’re unfamiliar, .conf is Splunk’s premier event where the Splunk community, customers, partners, and ...

A Season of Skills: New Splunk Courses to Light Up Your Learning Journey

There’s something special about this time of year—maybe it’s the glow of the holidays, maybe it’s the ...