Splunk Search

How do I make fields with a replacement for an argument work inside a saved search with the map command?

triest
Communicator

I'm sure there's a really easy answer, but it isn't coming to me so I'd greatly appreciate some help.

If I define a saved search test as:

| makeresults | eval foo="cat", bar="dog", baz="moose" | fields $fields$

Then it works as expected with savedsearch (returns fields foo and bar or bar and baz), but fails with the map command (it returns one field foo bar or bar baz)

Saved Search Examples:

| savedsearch fields="foo bar"

Returns the fields foo and bar

| savedsearch fields="bar baz"

Returns the fields bar and baz

Map

| makeresults
| eval fields="foo bar"
| map test

Returns the field foo bar (which is empty) instead of the fields foo and bar

| makeresults
| eval fields="foo baz"
| map test

Similarly returns field foo baz instead of the fields foo and baz

Not surprisingly, if I specify one field it does work:

| makeresults
| eval fields="foo"
| map test

I'm sure this is something really simple, but the solution just isn't coming to me.

Tags (2)
0 Karma
1 Solution

triest
Communicator

Of course as soon as I post I find the answer on answers: Is there a way to instruct Splunk to not add quotes when passing searches stored in a lookup table t...

The short version is you define a macro (I did qe for quote eater):

[qe(1)]
args = a
definition = $a$
iseval = 0

Then you use that in your savedsearch:

| makeresults | eval foo="cat", bar="dog", baz="moose" | fields `qe($fields$)`

Even with that modification, it still works with the savedsearch command.

I would love it if some one found a solution that didn't require modifying the saved search (imagine the saved search is from an app; modifying it makes updating fun as you have to check if they've modified it etc)

View solution in original post

0 Karma

triest
Communicator

Of course as soon as I post I find the answer on answers: Is there a way to instruct Splunk to not add quotes when passing searches stored in a lookup table t...

The short version is you define a macro (I did qe for quote eater):

[qe(1)]
args = a
definition = $a$
iseval = 0

Then you use that in your savedsearch:

| makeresults | eval foo="cat", bar="dog", baz="moose" | fields `qe($fields$)`

Even with that modification, it still works with the savedsearch command.

I would love it if some one found a solution that didn't require modifying the saved search (imagine the saved search is from an app; modifying it makes updating fun as you have to check if they've modified it etc)

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!

Mastering Threat Intelligence in ES 8.5, Splunk AI Assistant v2, and More from Splunk ...

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

Break the Build: Inside the KubeDoom Lounge at .conf26

    You step up to the machine. The pixelated corridors of a certain 1993 FPS load in front of you, EMP Pulse ...

Splunk Auto Ingestion Parallel Pipeline Scaling

Why this feature matters Many Splunk environments experience ingestion pressure long before the host is fully ...