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
Get Updates on the Splunk Community!

.conf25 Community Recap

Hello Splunkers, And just like that, .conf25 is in the books! What an incredible few days — full of learning, ...

Splunk App Developers | .conf25 Recap & What’s Next

If you stopped by the Builder Bar at .conf25 this year, thank you! The retro tech beer garden vibes were ...

Congratulations to the 2025-2026 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...