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!

Extending Observability Content to Splunk Cloud

Watch Now!   In this Extending Observability Content to Splunk Cloud Tech Talk, you'll see how to leverage ...

More Control Over Your Monitoring Costs with Archived Metrics GA in US-AWS!

What if there was a way you could keep all the metrics data you need while saving on storage costs?This is now ...

New in Observability Cloud - Explicit Bucket Histograms

Splunk introduces native support for histograms as a metric data type within Observability Cloud with Explicit ...