Splunk Search

Use Subsearch to insert commands

duesser
Path Finder

Hello,

I would like to use a subsearch to literally paste a command into the SPL e.g.:

 

 

| makeresults
[| makeresults
| eval test="|eval t1 = \"hello\""
| return $test]

 

 

and for it to be equivalent to

 

 

| makeresults
| eval t1 = "hello"

 

 

 

Is this possible?

Labels (1)
0 Karma
1 Solution

PickleRick
SplunkTrust
SplunkTrust

I should expect not.

PickleRick_0-1698313276886.png

 

View solution in original post

PickleRick
SplunkTrust
SplunkTrust

Do a quick test:

[ | makeresults | eval search="| makeresults" ]

If you look into the job log you'll see that while the internal search will get expanded to

Expanded index search = ([ | makeresults | eval search="| makeresults" ])

After the subsearch is evaluated and the result is returned to the outer search it will be treated as a string, with the pipe control character escaped

Expanded index search = (\| makeresults)

Which means that you will be searching for literal pipe character and "makeresults" word.

duesser
Path Finder

Yes I have seen this exactly. But is it possible to work around this in any way?

0 Karma

PickleRick
SplunkTrust
SplunkTrust

I should expect not.

PickleRick_0-1698313276886.png

 

duesser
Path Finder

I know that I can do

index=abc
         [
            | makeresults
            | addinfo
            | eval filter_t="earliest=".(info_min_time-60)." latest=".info_max_time
            | return filter_t
         ]

which literally becomes 

index=abc earliest=1698301592.0 latest=1698301792.0

 and I would like to use this behavior to dynamically define a command

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @duesser,

pleae try this:

index=abc
         [
            | makeresults
            | addinfo
            | eval earliest=relative_time(info_min_time,"-60s"), latest=info_max_time
            | fields earliest latest
         ]

Ciao.

Giuseppe

0 Karma

duesser
Path Finder

I am sorry for the confusion, I updated the original question.

 

The idea is to dynamically create strings of eval commands in a sub search (depending on a lookup e.g.) and then applying these to the base search by literally putting the into the search command. I hope I could clarify this now.

0 Karma

gcusello
SplunkTrust
SplunkTrust

Hi @duesser ,

good for you, see next time!

Ciao and happy splunking

Giuseppe

P.S.: Karma Points are appreciated by all the contributors 😉

0 Karma

gcusello
SplunkTrust
SplunkTrust

HI @duesser,

when you use a subsearch, you run a search on the main search using the output (exactly the fields you have in return or in fields).

What's your requirement?

Ciao.

Giuseppe

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!

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

[Puzzles] Solve, Learn, Repeat: Matching cron expressions

This puzzle (first published here) is based on matching timestamps to cron expressions.All the timestamps ...