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
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Community Content Calendar, September edition

Welcome to another insightful post from our Community Content Calendar! We're thrilled to continue bringing ...

Splunkbase Unveils New App Listing Management Public Preview

Splunkbase Unveils New App Listing Management Public PreviewWe're thrilled to announce the public preview of ...

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...