Splunk Search

How can I use pre evaluated param in my rex?

ortalis
New Member

I'm getting from my dashboard parameter with '_' value in it, I would like to start my search by evaluating a new parameter without the '_' and then use it in my search.
In Addition, I would like to inject this parameter into my regex and do another manipulation on my result.

This is my query:

Spoiler
index=* |eval temp = ("my_value","_","")| "ERROR" "Exception in script execution" "at scripts.$temp$."
[search index=* script_name=my_value tid=*
| head 1 | return tid]
| rex "at\sscripts.$temp$.(?<stack_trace>[^\t\n\s]+)"
| head 1 | table stack_trace



I would like it to be searched like that:

Spoiler
index=* |eval temp = ("my_value","_","")| "ERROR" "Exception in script execution" "at scripts.myvalue."
[search index=* script_name=my_value tid=*
| head 1 | return tid]
| rex "at\sscripts.myvalue.(?<stack_trace>[^\t\n\s]+)"
| head 1 | table stack_trace



 
I can't seem to figure it out, could somebody help me?

Thanks:)

Labels (3)
0 Karma

bowesmana
SplunkTrust
SplunkTrust

@ortalis 

Are you talking about a token in your dashboard that you are passing to a search. If so, why not remove the _ in the token before you pass it to the query. Then you can use the token as is, without having to change it in the query.

Your query examples don't seem to be valid queries though, so not totally clear on how you are getting your value. Can you provide more info.

 

 

0 Karma

ortalis
New Member

I have created a dashboard that I'm getting the value from the user.
I need to use this query also in a code I wrote so I need to find a way to replace these values so my query would work.
The query isn't valid right now since I don't know how to pre-evaluate the temp param before doing the search ("ERROR" "Exception in script execution" "at scripts.$temp$."), and then injecting the value to the rex command.
@bowesmana 

0 Karma

bowesmana
SplunkTrust
SplunkTrust

Can you post the dashboard snippets of your inputs and searches, it's not clear to me what is needed

0 Karma

ormal
New Member

Here is our Query now:

index=myindex script=$script$ customer_name=* run_number=*
| table customer_name  run_number
| join run_number
[search index=myindex
[search index=myindex "ERROR" "at scripts.$temp$."
[search index=myindex script=$script$ customer_name=$customer_name$  run_number=*
| head 1 | return run_number]
| rex "at\sscripts.$temp$.(?<stack_trace>[^\t\n\s]+)"
| head 1 | table stack_trace
| return $stack_trace]
|table run_number]

We dont want to get the "temp" value from the user.
We want to create it from the script name.
For example if the script name is: "or_m.pdf"
we want the remove the "_" and the suffix ".pdf" so it will be: "orm"



0 Karma

bowesmana
SplunkTrust
SplunkTrust

The important part here is your dashboard token handling, not the query. In order to generate a temp token from the script, this would be done in the drilldown logic of your dashboard, bnot the query. You cannot do this in the query itself. Please post the dashboard logic you are using to set the relevant tokens.

Also, I don't know what your data is like, but I would suggest finding a better way of doing your search. It is rarely necessary to use join - and the fact that you are using 3 subsearches is most likely a very bad idea and most likely not necessary.

Generally you only have to do a single search and use aggregation and evaluations to get the correct data filtered. Your 4 searches will all have to be done separately - and will each have to run independently, so is likely to be very slow in comparison to a more optimal search.

 

0 Karma
Get Updates on the Splunk Community!

Observe and Secure All Apps with Splunk

  Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

Splunk Decoded: Business Transactions vs Business IQ

It’s the morning of Black Friday, and your e-commerce site is handling 10x normal traffic. Orders are flowing, ...

Fastest way to demo Observability

I’ve been having a lot of fun learning about Kubernetes and Observability. I set myself an interesting ...