Splunk Search

How to use dropdown value in different ways?

thenormalone
Path Finder

I have a dropdown whose value once input needs to be used in two different ways in the same search query. One of the indexes require that value to be as is but the other index requires the value to be altered. 

 

I'm doing something like what ive mentioned below but that doesn't seem to be working. Any help is appreciated.

 

 

dropdown token value is selected_client with the initial value being "*"

(index = indexA OR index = indexB) AND (clientForIndexA = domain1 OR clientForIndexB = domain2)
| eval domain1 = if("$selected_client$" == "*", "*", "$selected_client$") 
| eval domain2 = if(domain1 == "*", "*", replace (sync_ml_domain, "\." , "-")) 
| eval domain2 = if(domain1 == "*", "*", replace (sync_ml_domain, "_" , "-"))

 

 

Labels (2)
0 Karma
1 Solution

bowesmana
SplunkTrust
SplunkTrust

If I understand correctly, you are trying to match the clientForIndex?? against the selected dropdown where the field has a different format in each index and want to do something like this?

(index = indexA clientForIndexA = $selected_client$) OR (index = indexB clientForIndexB = $modified_client$)

where selected_client is the chosen value to match against clientForIndexA field from the dropdown and clientForIndexB needs to match against a modified domain format.

In that case, just create a second token in a change block of the input, like this

<input type="dropdown" token="selected_client">
...
  <change>
    <eval token="modified_client">replace($value$, "[\.|_]", "-")</eval>
  <change>
</input>

 however, I am not sure if I understood your question correctly as you have the sync_ml_domain field

Anyway,  you can't do eval statements after the search which can then change the effect of the search like you are doing.

View solution in original post

jdunlea
Contributor

I presume you are trying to replace both the "." and the "_" with a "-" for domain2?

 

If so, the issue was with the two eval statements for domain2. I was able to make it work (at least for what I think you are trying to achieve) as follows:

 

 

 

| eval domain1 = "$selected_client$"
| eval domain2 = if(domain1 == "*", "*", replace (sync_ml_domain, "[\.|_]" , "-"))

 

 

 

Also, you will notice that I do not have an IF statement for domain 1, as it appears to be redundant the way it was written. Let me know if this solves your problem!

thenormalone
Path Finder

I am trying to replace both the "." and the "_" with a "-" for domain2, thanks for the suggestion. 

 

So the default value for $selected_client$ is * which it is being assigned to domain 1 however search doesn't return anything because clientForIndexA still just maps to domain1 in my dashboard panel

 

 

 

(clientForIndexA = domain1 OR clientForIndexB = host*domain2*prod)
| eval domain1 = "*" 
| eval domain2 = if(domain1 == "*", "*", replace (domain1, "[\.|_]" , "-"))

 

 

 

 

so how do I get the values of domain1 and domain2 to be used in the search query?

0 Karma

bowesmana
SplunkTrust
SplunkTrust

If I understand correctly, you are trying to match the clientForIndex?? against the selected dropdown where the field has a different format in each index and want to do something like this?

(index = indexA clientForIndexA = $selected_client$) OR (index = indexB clientForIndexB = $modified_client$)

where selected_client is the chosen value to match against clientForIndexA field from the dropdown and clientForIndexB needs to match against a modified domain format.

In that case, just create a second token in a change block of the input, like this

<input type="dropdown" token="selected_client">
...
  <change>
    <eval token="modified_client">replace($value$, "[\.|_]", "-")</eval>
  <change>
</input>

 however, I am not sure if I understood your question correctly as you have the sync_ml_domain field

Anyway,  you can't do eval statements after the search which can then change the effect of the search like you are doing.

thenormalone
Path Finder

Thanks for the suggestion! I was able to get it to run successfully using 

 

<change>
    <eval token="modified_client">replace($value$, "[.|_]", "-")</eval>
  <change>

 

Tags (1)
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!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...