Splunk Search

Trimming the value of a savedsearch parameter within the savedsearch

jeffmartin
Engager

I have a saved "MySearch" that takes a parameter "INPUT_SessionId", something like this:

index=foo
| ... some stuff
| search $INPUT_SessionId$
| ... more stuff

And then "MySearch" invoked like this

| savedsearch "MySearch" INPUT_SessionId="abc123"

My challenge is that sometimes me & my users accidentally invoke with curly braces around the SessionId (it's a long story), like this:

| savedsearch "MySearch" INPUT_SessionId="{abc123}"

When invoked this way, the search produces no results, which is confusing for user until they realize they accidentally included curly braces.

I'd like to change things inside of "MySearch" so that it strips curly braces from $INPUT_SessionId$ before continuing to use the value.

For a typical field value I know how to use trim like

| eval someField=trim(someField, "{}")

How do I do something like trim() but on the value of the parameter $INPUT_SessionId$ ?

Labels (1)
Tags (2)
0 Karma
1 Solution

yuanliu
SplunkTrust
SplunkTrust

Let me clarify the requirement.  You want to modify the saved search so it can handle curly brackets that users may accidentally enter when invoking it.  If this correct, you can do something like

 

index=foo
| ... some stuff
| search
  [makeresults format=csv data="search
$INPUT_SessionId$"
  | eval search = replace(search, "{|}", "")
  | format]
| ... more stuff

 

(Note trim(someField, "{}") will not work in your use case because "{" does not appear in the beginning of $INPUT_SessionId$.)

View solution in original post

Tags (1)

yuanliu
SplunkTrust
SplunkTrust

Let me clarify the requirement.  You want to modify the saved search so it can handle curly brackets that users may accidentally enter when invoking it.  If this correct, you can do something like

 

index=foo
| ... some stuff
| search
  [makeresults format=csv data="search
$INPUT_SessionId$"
  | eval search = replace(search, "{|}", "")
  | format]
| ... more stuff

 

(Note trim(someField, "{}") will not work in your use case because "{" does not appear in the beginning of $INPUT_SessionId$.)

Tags (1)
Get Updates on the Splunk Community!

Get Inspired! We’ve Got Validation that Your Hard Work is Paying Off

We love our Splunk Community and want you to feel inspired by all your hard work! Eric Fusilero, our VP of ...

What's New in Splunk Enterprise 9.4: Features to Power Your Digital Resilience

Hey Splunky People! We are excited to share the latest updates in Splunk Enterprise 9.4. In this release we ...

Take Your Breath Away with Splunk Risk-Based Alerting (RBA)

WATCH NOW!The Splunk Guide to Risk-Based Alerting is here to empower your SOC like never before. Join Haylee ...